<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Models\Pasien;
use App\Models\Diagnosa;
use App\Models\Gejala;

class DashboardController extends Controller
{
    public function index()
    {
        // ==========================
        // STATISTIK
        // ==========================

        $totalPasien = Pasien::count();

        $totalDiagnosa = Diagnosa::count();

        $totalGejala = Gejala::count();

        // ==========================
        // DATA GRAFIK BERDASARKAN
        // REKOMENDASI PEMERIKSAAN
        // ==========================

        $chart = [

            [
                'label' => 'Lakukan Pemantauan Mandiri',
                'total' => Diagnosa::where('cf_hasil', '<=', 0.20)->count()
            ],

            [
                'label' => 'Lakukan Pemeriksaan Tekanan Darah',
                'total' => Diagnosa::where('cf_hasil', '>', 0.20)
                    ->where('cf_hasil', '<=', 0.40)
                    ->count()
            ],

            [
                'label' => 'Konsultasikan dengan Tenaga Kesehatan',
                'total' => Diagnosa::where('cf_hasil', '>', 0.40)
                    ->where('cf_hasil', '<=', 0.70)
                    ->count()
            ],

            [
                'label' => 'Segera Datangi Fasilitas Kesehatan',
                'total' => Diagnosa::where('cf_hasil', '>', 0.70)
                    ->count()
            ]

        ];

        return view(
            'admin.dashboard',
            compact(
                'totalPasien',
                'totalDiagnosa',
                'totalGejala',
                'chart'
            )
        );
    }
}