@extends('layouts.user')

@section('title', 'Dashboard')

@section('content')

<!-- ================= HERO ================= -->

<div class="card-hero mb-4">

    <h2>
        Selamat Datang,
        {{ auth()->user()->name }}
    </h2>

    <p>

        Pantau riwayat deteksi dini hipertensi dan
        lakukan pemeriksaan sesuai rekomendasi yang
        diberikan oleh sistem.

    </p>

    <a href="{{ url('/user/diagnosa') }}"
        class="btn btn-light mt-2">

        Mulai Deteksi Dini

    </a>

</div>


<!-- ================= STATISTIK ================= -->

<div class="row mb-4">

    <!-- Total -->

    <div class="col-md-4">

        <div class="card shadow-sm p-3 h-100">

            <h6 class="text-muted">

                Total Deteksi Dini

            </h6>

            <h3>

                {{ $totalDiagnosa }}

            </h3>

        </div>

    </div>


    <!-- Rekomendasi -->

    <div class="col-md-4">

        <div class="card shadow-sm p-3 h-100">

            <h6 class="text-muted">

                Rekomendasi Terakhir

            </h6>

            <h6>

                {{ $lastDiagnosa->rekomendasi ?? '-' }}

            </h6>

        </div>

    </div>


    <!-- Hasil -->

    <div class="col-md-4">

        <div class="card shadow-sm p-3 h-100">

            <h6 class="text-muted">

                Hasil Deteksi Dini

            </h6>

            <h6>

                {{ $lastDiagnosa->penyakit->nama ?? '-' }}

            </h6>

        </div>

    </div>

</div>


<!-- ================= RIWAYAT ================= -->

<div class="d-flex justify-content-between align-items-center mb-3">

    <h5 class="mb-0">

        Riwayat Deteksi Dini

    </h5>

    <form method="GET">

        <select
            name="perPage"
            onchange="this.form.submit()"
            class="form-select form-select-sm">

            <option value="5"
                {{ $perPage == 5 ? 'selected' : '' }}>
                5
            </option>

            <option value="10"
                {{ $perPage == 10 ? 'selected' : '' }}>
                10
            </option>

            <option value="25"
                {{ $perPage == 25 ? 'selected' : '' }}>
                25
            </option>

            <option value="50"
                {{ $perPage == 50 ? 'selected' : '' }}>
                50
            </option>

        </select>

    </form>

</div>
<!-- ================= TABEL RIWAYAT ================= -->

<div class="card shadow-sm p-3">

    <div class="table-responsive">

        <table class="table table-hover align-middle">

            <thead class="table-light">

                <tr>

                    <th width="8%">No</th>

                    <th width="18%">Tanggal</th>

                    <th>Rekomendasi Pemeriksaan</th>

                    <th>Hasil Deteksi Dini</th>

                    <th width="15%">Keyakinan</th>

                </tr>

            </thead>

            <tbody>

            @forelse($riwayat as $r)

                @php

                    switch ($r->rekomendasi) {

                        case 'Lakukan Pemantauan Mandiri':
                            $badge = 'success';
                            break;

                        case 'Lakukan Pemeriksaan Tekanan Darah':
                            $badge = 'warning';
                            break;

                        case 'Konsultasikan dengan Tenaga Kesehatan':
                            $badge = 'danger';
                            break;

                        case 'Segera ke Fasilitas Pelayanan Kesehatan':
                            $badge = 'dark';
                            break;

                        default:
                            $badge = 'secondary';
                    }

                @endphp

                <tr>

                    <td>

                        {{ $loop->iteration + ($riwayat->currentPage()-1) * $riwayat->perPage() }}

                    </td>

                    <td>

                        {{ $r->created_at->format('d-m-Y') }}

                    </td>

                    <td>

                        <span class="badge bg-{{ $badge }}">

                            {{ $r->rekomendasi }}

                        </span>

                    </td>

                    <td>

                        {{ $r->penyakit->nama }}

                    </td>

                    <td>

                        {{ number_format($r->cf_hasil*100,2) }}%

                    </td>

                </tr>

            @empty

                <tr>

                    <td colspan="5"
                        class="text-center text-muted">

                        Belum ada riwayat deteksi dini.

                    </td>

                </tr>

            @endforelse

            </tbody>

        </table>

    </div>

    <!-- ================= PAGINATION ================= -->

    <div class="mt-3">

        {{ $riwayat->links() }}

    </div>

</div>

<div class="mt-3">

    <a href="{{ url('/user/riwayat') }}"
        class="btn btn-primary">

        Lihat Seluruh Riwayat

    </a>

</div>

@endsection