<?= $this->extend('layouts/main') ?>

<?= $this->section('title') ?>Laporan<?= $this->endSection() ?>

<?= $this->section('content') ?>
<div class="space-y-6">
    <div>
        <h1 class="text-2xl font-semibold tracking-tight text-gray-900">Ringkasan laporan</h1>
        <p class="mt-1 max-w-2xl text-sm text-gray-500">Ringkasan angka untuk rentang tanggal yang dipilih. Untuk daftar cuti per periode, buka <strong>Laporan → Cuti pegawai</strong>.</p>
    </div>

    <?= view('layouts/partials/admin_alert', ['errors' => $errors ?? []]) ?>

    <form method="get" action="<?= site_url('admin/laporan') ?>" class="rounded-2xl border border-gray-200 bg-white p-5 shadow-sm">
        <div class="flex flex-col gap-4 lg:flex-row lg:items-end lg:justify-between">
            <div class="flex flex-wrap items-end gap-3">
                <div>
                    <label class="block text-xs font-medium text-gray-600">Dari</label>
                    <input type="date" name="dari" value="<?= esc($dari) ?>" class="mt-1 rounded-lg border border-gray-300 px-3 py-2 text-sm shadow-sm focus:border-blue-500 focus:outline-none focus:ring-1 focus:ring-blue-500">
                </div>
                <div>
                    <label class="block text-xs font-medium text-gray-600">Sampai</label>
                    <input type="date" name="sampai" value="<?= esc($sampai) ?>" class="mt-1 rounded-lg border border-gray-300 px-3 py-2 text-sm shadow-sm focus:border-blue-500 focus:outline-none focus:ring-1 focus:ring-blue-500">
                </div>
            </div>
            <div class="flex flex-wrap items-center gap-2">
                <button type="submit" class="inline-flex items-center justify-center rounded-lg bg-blue-600 px-4 py-2 text-sm font-semibold text-white shadow-sm hover:bg-blue-700">Tampilkan</button>
                <a href="<?= site_url('admin/laporan/cuti') ?>?dari=<?= esc(urlencode($dari)) ?>&sampai=<?= esc(urlencode($sampai)) ?>" class="inline-flex items-center justify-center rounded-lg border border-gray-200 bg-white px-4 py-2 text-sm font-medium text-gray-800 shadow-sm hover:bg-gray-50">Laporan cuti</a>
            </div>
        </div>
    </form>

    <?php if (is_array($summary)) : ?>
        <div class="grid gap-4 sm:grid-cols-2 lg:grid-cols-3">
            <div class="rounded-2xl border border-gray-200 bg-white p-5 shadow-sm">
                <p class="text-xs font-semibold uppercase tracking-wide text-gray-500">Total pegawai</p>
                <p class="mt-2 text-3xl font-bold text-gray-900"><?= number_format((int) ($summary['total_pegawai'] ?? 0), 0, ',', '.') ?></p>
            </div>
            <div class="rounded-2xl border border-gray-200 bg-white p-5 shadow-sm">
                <p class="text-xs font-semibold uppercase tracking-wide text-gray-500">Presensi (rekam) rentang</p>
                <p class="mt-2 text-3xl font-bold text-emerald-700"><?= number_format((int) ($summary['presensi_rekam'] ?? 0), 0, ',', '.') ?></p>
            </div>
            <div class="rounded-2xl border border-gray-200 bg-white p-5 shadow-sm">
                <p class="text-xs font-semibold uppercase tracking-wide text-gray-500">Cuti disetujui rentang</p>
                <p class="mt-2 text-3xl font-bold text-sky-700"><?= number_format((int) ($summary['cuti_approve'] ?? 0), 0, ',', '.') ?></p>
            </div>
            <div class="rounded-2xl border border-gray-200 bg-white p-5 shadow-sm">
                <p class="text-xs font-semibold uppercase tracking-wide text-gray-500">Presensi hari ini</p>
                <p class="mt-2 text-2xl font-bold text-gray-900"><?= number_format((int) ($summary['presensi_hari_ini'] ?? 0), 0, ',', '.') ?></p>
                <p class="text-xs text-gray-500"><?= esc((string) ($summary['hari_ini'] ?? '')) ?></p>
            </div>
            <div class="rounded-2xl border border-gray-200 bg-white p-5 shadow-sm">
                <p class="text-xs font-semibold uppercase tracking-wide text-gray-500">Cuti (Approve) hari ini</p>
                <p class="mt-2 text-2xl font-bold text-gray-900"><?= number_format((int) ($summary['cuti_hari_ini'] ?? 0), 0, ',', '.') ?></p>
            </div>
            <div class="rounded-2xl border border-gray-200 bg-white p-5 shadow-sm">
                <p class="text-xs font-semibold uppercase tracking-wide text-gray-500">Belum rekam (estimasi)</p>
                <p class="mt-2 text-2xl font-bold text-amber-700"><?= number_format((int) ($summary['belum_rekam_hari_ini'] ?? 0), 0, ',', '.') ?></p>
                <p class="text-xs text-gray-500">Total − presensi hari ini − cuti approve hari ini</p>
            </div>
        </div>

        <section class="rounded-2xl border border-gray-200 bg-white p-6 shadow-sm">
            <div class="flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between">
                <div>
                    <p class="text-xs font-semibold uppercase tracking-wide text-gray-500">Laporan terkait</p>
                    <p class="mt-1 text-sm font-semibold text-gray-900">Cuti pegawai (rentang tanggal)</p>
                    <p class="mt-1 text-xs text-gray-500">Tabel detail per pegawai; cetak dari browser (Ctrl+P) di halaman laporan cuti.</p>
                </div>
                <a href="<?= site_url('admin/laporan/cuti') ?>?dari=<?= esc(urlencode($dari)) ?>&sampai=<?= esc(urlencode($sampai)) ?>" class="inline-flex shrink-0 items-center justify-center rounded-lg bg-blue-600 px-4 py-2.5 text-sm font-semibold text-white shadow-sm hover:bg-blue-700">
                    Buka laporan cuti
                </a>
            </div>
            <p class="mt-5 border-t border-gray-100 pt-4 text-xs text-gray-500">Integrasi: <code class="rounded bg-gray-100 px-1">GET /api/admin/laporan</code> · <code class="rounded bg-gray-100 px-1">GET /api/admin/laporan/cuti</code></p>
        </section>
    <?php elseif (empty($errors)) : ?>
        <div class="rounded-2xl border border-gray-200 bg-white p-6 shadow-sm">
            <?= view('layouts/partials/empty_state', [
                'icon'  => 'fa-chart-simple',
                'title' => 'Belum ada ringkasan',
                'hint'  => 'Pilih tanggal lalu klik Tampilkan untuk memuat angka agregat.',
            ]) ?>
        </div>
    <?php endif ?>
</div>
<?= $this->endSection() ?>
