@extends('layouts.user')

@section('title', 'Riwayat')

@section('content')

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

    <form method="GET">
        <select name="perPage" onchange="this.form.submit()" class="form-select form-select-sm w-auto">
            <option value="5" {{ $perPage == 5 ? 'selected' : '' }}>5</option>
            <option value="10" {{ $perPage == 10 ? 'selected' : '' }}>10</option>
            <option value="25" {{ $perPage == 25 ? 'selected' : '' }}>25</option>
        </select>
    </form>
</div>

<table class="table table-bordered">
    <tr>
        <th>No</th>
        <th>Nama</th>
        <th>Penyakit</th>
        <th>CF (%)</th>
        <th>Tanggal</th>
        <th>Aksi</th>
    </tr>

    @forelse($data as $d)
    <tr>
            <td>{{ $loop->iteration + ($data->currentPage() - 1) * $data->perPage() }}</td>
            <td>{{ $d->pasien->nama ?? '-' }}</td>
            <td>{{ $d->penyakit->nama }}</td>
            <td>{{ number_format($d->cf_hasil * 100, 2) }}%</td>
            <td>{{ $d->created_at->format('d-m-Y') }}</td>
            
        <td>
            <a href="{{ route('diagnosa.hasil', $d->id) }}" 
                class="btn btn-info btn-sm">
                Preview
            </a>
            <a href="{{ route('diagnosa.pdf', $d->id) }}" 
               class="btn btn-success btn-sm">
               Download PDF
            </a>
        </td>
    </tr>
    @empty
    <tr>
        <td colspan="5">
            <div class="alert alert-info mb-0 text-center">
                Anda belum melakukan diagnosa, silakan lakukan diagnosa pada menu Diagnosis!
            </div>
        </td>
    </tr>
    @endforelse

</table>

<div class="mt-3">
    {{ $data->links('pagination::bootstrap-5') }}
</div>

@endsection