<?php $__env->startSection('title', 'Data Kunjungan'); ?>
<?php $__env->startSection('page-title', 'Data Kunjungan'); ?>

<?php $__env->startSection('content'); ?>
    <!-- =========================
    FILTER & SEARCH
========================= -->
    <div class="card shadow-sm mb-4 border-0">
        <div class="card-body py-3">
            <form
                method="GET"
                action="<?php echo e(route('admin.kunjungan.index')); ?>"
                class="row g-3 align-items-end"
            >
                <!-- SEARCH -->
                <div class="col-md-4">
                    <label
                        class="form-label small fw-semibold mb-1"
                        style="color: var(--navy-primary)"
                    >
                        Cari Data
                    </label>

                    <div class="input-group">
                        <span class="input-group-text bg-white border-end-0">
                            <i class="bi bi-search text-muted"></i>
                        </span>

                        <input
                            type="text"
                            name="search"
                            class="form-control border-start-0"
                            placeholder="Nama, instansi, bidang, atau no. antrian..."
                            value="<?php echo e(request('search')); ?>"
                        />
                    </div>
                </div>

                <!-- STATUS -->
                <div class="col-md-3">
                    <label
                        class="form-label small fw-semibold mb-1"
                        style="color: var(--navy-primary)"
                    >
                        Filter Status
                    </label>

                    <select name="status" class="form-select">
                        <option value="">Semua Status</option>

                        <option
                            value="pending"
                            <?php echo e(request('status') === 'pending' ? 'selected' : ''); ?>

                        >
                            🕒 Pending
                        </option>

                        <option
                            value="diterima"
                            <?php echo e(request('status') === 'diterima' ? 'selected' : ''); ?>

                        >
                            ✅ Diterima
                        </option>

                        <option
                            value="ditolak"
                            <?php echo e(request('status') === 'ditolak' ? 'selected' : ''); ?>

                        >
                            ❌ Ditolak
                        </option>
                    </select>
                </div>

                <!-- FILTER BIDANG -->
                <div class="col-md-3">
                    <label
                        class="form-label small fw-semibold mb-1"
                        style="color: var(--navy-primary)"
                    >
                        Filter Bidang
                    </label>

                    <select name="bidang" class="form-select">
                        <option value="">Semua Bidang</option>

                        <?php $__currentLoopData = $bidangs; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $b): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <option
                                value="<?php echo e($b->id_bidang); ?>"
                                <?php echo e(request('bidang') == $b->id_bidang ? 'selected' : ''); ?>

                            >
                                <?php echo e($b->nama_bidang); ?>

                            </option>

                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </select>
                </div>

                <!-- BUTTON -->
                <div class="col-auto">
                    <button type="submit" class="btn btn-navy px-4">
                        <i class="bi bi-filter me-1"></i>
                        Terapkan
                    </button>
                </div>

                <div class="col-auto">
                    <a
                        href="<?php echo e(route('admin.kunjungan.index')); ?>"
                        class="btn btn-light border text-secondary"
                    >
                        <i class="bi bi-arrow-clockwise"></i>
                        Reset
                    </a>
                </div>
            </form>
        </div>
    </div>
    <!-- =========================
    TABLE
========================= -->
    <div class="card shadow-sm border-0">
        <!-- HEADER -->
        <div
            class="card-header bg-white py-3 d-flex justify-content-between align-items-center"
        >
            <h5
                class="card-title mb-0 fw-bold"
                style="color: var(--navy-primary)"
            >
                Daftar Kunjungan
            </h5>

            <span class="badge badge-navy px-3 py-2">
                <?php echo e($kunjungans->count()); ?>


                Data Ditemukan
            </span>
        </div>

        <!-- BODY -->
        <div class="card-body p-0">
            <div class="table-responsive">
                <table class="table table-hover align-middle mb-0">
                    <thead class="bg-light text-muted small text-uppercase">
                        <tr>
                            <th class="px-4 py-3">No. Antrian</th>

                            <th class="py-3">Tamu & Instansi</th>

                            <th class="py-3">Waktu Kunjungan</th>

                            <th class="py-3">Bidang / Subbagian</th>

                            <th class="py-3">Status</th>

                            <th class="text-center px-4 py-3">Aksi</th>
                        </tr>
                    </thead>

                    <tbody>
                        <?php $__empty_1 = true; $__currentLoopData = $kunjungans; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $k): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                            <?php
                            $s = $k->status_kunjungan;
                        ?>
                            <tr>
                                <!-- NOMOR ANTRIAN -->
                                <td class="px-4">
                                    <span
                                        class="badge badge-navy px-3 py-2 fw-bold"
                                        style="letter-spacing: 1px"
                                    >
                                        <?php echo e($k->nomor_antrian); ?>

                                    </span>
                                </td>

                                <!-- TAMU -->
                                <td>
                                    <div class="fw-bold mb-0 text-dark">
                                        <?php echo e($k->tamu->nama ?? 'Tamu Umum'); ?>

                                    </div>

                                    <div class="text-muted small">
                                        <i class="bi bi-building me-1"></i>

                                        <?php echo e($k->tamu->instansi ?? '-'); ?>

                                    </div>
                                </td>

                                <!-- WAKTU -->
                                <td>
                                    <div class="small fw-medium">
                                        <?php echo e(\Carbon\Carbon::parse($k->tanggal_kunjungan)->format('d M Y')); ?>

                                    </div>

                                    <div class="text-muted extra-small">
                                        <i class="bi bi-clock me-1"></i>

                                        <?php echo e($k->jam_masuk); ?> WIB
                                    </div>
                                </td>

                                <!-- BIDANG -->
                                <td>
                                    <div class="d-flex flex-column gap-1">
                                        <span
                                            class="badge rounded-pill px-3 py-2"
                                            style="
                                                background: rgba(
                                                    37,
                                                    99,
                                                    235,
                                                    0.1
                                                );
                                                color: #2563eb;
                                                width: fit-content;
                                            "
                                        >
                                            <?php echo e($k->bidang->nama_bidang ?? '-'); ?>

                                        </span>

                                        <?php if($k->subbagian): ?>
                                            <small class="text-muted">
                                                <?php echo e($k->subbagian->nama_subbagian); ?>

                                            </small>

                                        <?php endif; ?>
                                    </div>
                                </td>

                                 <!-- STATUS -->
                                 <td>
                                     <?php if($s === 'diterima'): ?>
                                         <?php if($k->is_served): ?>
                                             <span
                                                 class="badge rounded-pill bg-success text-white border border-success px-3"
                                             >
                                                 ✅ Selesai Dilayani
                                             </span>
                                         <?php else: ?>
                                             <span
                                                 class="badge rounded-pill bg-success-subtle text-success border border-success px-3"
                                             >
                                                 ✅ Diterima
                                             </span>
                                         <?php endif; ?>

                                     <?php elseif($s === 'ditolak'): ?>
                                         <span
                                             class="badge rounded-pill bg-danger-subtle text-danger border border-danger px-3"
                                         >
                                             ❌ Ditolak
                                         </span>

                                     <?php else: ?>
                                         <span
                                             class="badge rounded-pill bg-warning-subtle text-warning border border-warning px-3"
                                         >
                                             🕒 Pending
                                         </span>

                                     <?php endif; ?>
                                 </td>

                                 <!-- AKSI -->
                                 <td class="text-center px-4">
                                     <div
                                         class="d-flex gap-2 justify-content-center align-items-center"
                                     >
                                         <!-- SELESAI -->
                                         <?php if($s === 'diterima' && !$k->is_served): ?>
                                             <form
                                                 action="<?php echo e(route('admin.kunjungan.selesai', $k->id_kunjungan)); ?>"
                                                 method="POST"
                                                 onsubmit="
                                                     return confirm(
                                                         'Apakah Anda yakin ingin menyelesaikan kunjungan ini?',
                                                     );
                                                 "
                                                 class="m-0"
                                             >
                                                 <?php echo csrf_field(); ?>
                                                 <button
                                                     class="btn btn-sm btn-success"
                                                     title="Selesai Dilayani"
                                                 >
                                                     <i class="bi bi-check-lg"></i> Selesai
                                                 </button>
                                             </form>
                                         <?php endif; ?>

                                         <!-- DETAIL -->
                                         <a
                                             href="<?php echo e(route('admin.kunjungan.detail', $k->id_kunjungan)); ?>"
                                             class="btn btn-sm btn-outline-primary"
                                             title="Detail"
                                         >
                                             <i class="bi bi-eye-fill"></i>
                                         </a>

                                         <!-- HAPUS -->
                                         <form
                                             action="<?php echo e(route('admin.kunjungan.hapus', $k->id_kunjungan)); ?>"
                                             method="POST"
                                             onsubmit="
                                                 return confirm(
                                                     'Apakah Anda yakin ingin menghapus data ini?',
                                                 );
                                             "
                                             class="m-0"
                                         >
                                             <?php echo csrf_field(); ?>
                                             <?php echo method_field('DELETE'); ?>

                                             <button
                                                 class="btn btn-sm btn-outline-danger"
                                                 title="Hapus"
                                             >
                                                 <i class="bi bi-trash-fill"></i>
                                             </button>
                                         </form>
                                     </div>
                                 </td>
                            </tr>

                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                            <tr>
                                <td colspan="6" class="text-center py-5">
                                    <div class="text-muted">
                                        <i
                                            class="bi bi-search fs-1 d-block mb-3 opacity-25"
                                        ></i>

                                        <p class="mb-0">Tidak ada data kunjungan yang sesuai dengan kriteria.</p>

                                        <a
                                            href="<?php echo e(route('admin.kunjungan.index')); ?>"
                                            class="btn btn-sm btn-link text-decoration-none"
                                        >
                                            Lihat Semua Data
                                        </a>
                                    </div>
                                </td>
                            </tr>

                        <?php endif; ?>
                    </tbody>
                </table>
            </div>
        </div>
    </div>

<?php $__env->stopSection(); ?>

<?php echo $__env->make('admin.layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH /home/evo/Downloads/buku-tamu-ksop/resources/views/admin/kunjungan/index.blade.php ENDPATH**/ ?>