@extends('base.layout')

@section('content')
<div class="wrapper">
    <div class="container-fluid">
        <div class="row">
            <div class="col-sm-12">
                <div class="card-box ribbon-box">
                    <div class="ribbon ribbon-danger">Rekapitulasi Data Bulan {{$bulan}} Tahun {{$tahun}}</div>
                    <p></p>
                    <div class="mt-3 mb-3">
                         <a href="{{ route('exportGlassReport', ['bulan' => $bulan, 'tahun' => $tahun]) }}" class="btn btn-success">
                            <i class="fa fa-file-excel-o"></i> Download Full Excel (CSV)
                        </a>
                    </div>

                    <div class="table-responsive">
                        <table class="table table-bordered" id="datatable">
                            <thead>
                                <tr>
                                    <th>Nama Pasien</th>
                                    <th>No RM</th>
                                    <th>Bakteri</th>
                                    @foreach($jsonantibiotik as $antibiotic)
                                        <th title="{{ $antibiotic }}">{{ $antibiotic }}</th>
                                    @endforeach
                                </tr>
                            </thead>
                            <tbody>
                                @forelse($orderbydate as $data)
                                    <tr>
                                        <td>{{ $data->nmpasien }}</td>
                                        <td>{{ $data->noregister }}</td>
                                        <td>{{ $data->nm_spesimen }}</td> @foreach($jsonantibiotik as $headerAntibiotik)
                                            @php
                                                // LOGIC UTAMA:
                                                // Cek di array lookup: [id_pasien][nama_antibiotik]
                                                // Jika ada, ambil nilainya. Jika tidak, kosong.
                                                $interpretasi = $antibiotikLookup[$data->id][$headerAntibiotik] ?? '';
                                            @endphp
                                            <td class="text-center" style="{{ $interpretasi == 'R' ? 'background-color:#ffcccc' : '' }}">
                                                {{ $interpretasi }}
                                            </td>
                                        @endforeach
                                    </tr>
                                @empty
                                    <tr>
                                        <td colspan="{{ count($jsonantibiotik) + 3 }}">Data tidak ditemukan</td>
                                    </tr>
                                @endforelse
                            </tbody>
                        </table>
                    </div>

                </div>
            </div>
        </div>
    </div>
</div>
@endsection