<?php $__env->startSection('title', 'Laporan Kehadiran Karyawan'); ?>
<?php $__env->startSection('page-title', 'Laporan Presensi & Kehadiran'); ?>
<?php $__env->startSection('page-subtitle', 'Laporan log presensi komprehensif dengan filter kustom tanggal dan departemen.'); ?>

<?php $__env->startSection('page-actions'); ?>
<div class="d-flex justify-content-md-end gap-2 mt-2 mt-md-0">
    <button type="button" class="btn btn-outline-secondary" onclick="window.print()">
        <i class="bi bi-printer me-1"></i> Cetak Laporan
    </button>
    <a href="<?php echo e(route('admin.attendance.export', request()->query())); ?>" class="btn btn-success">
        <i class="bi bi-file-earmark-excel me-1"></i> Export Excel (.xls)
    </a>
</div>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('content'); ?>

<div class="card shadow-sm border-0 mb-4 d-print-none">
    <div class="card-body p-3">
        <form method="GET" action="<?php echo e(route('admin.reports.index')); ?>" class="row g-2 align-items-center">
            <div class="col-12 col-md-3">
                <label class="form-label text-xs text-muted mb-1">Periode Preset</label>
                <select name="preset" class="form-select bg-light border-0" onchange="this.form.submit()">
                    <option value="today" <?php echo e($preset == 'today' ? 'selected' : ''); ?>>Hari Ini</option>
                    <option value="this_week" <?php echo e($preset == 'this_week' ? 'selected' : ''); ?>>Minggu Ini</option>
                    <option value="this_month" <?php echo e($preset == 'this_month' ? 'selected' : ''); ?>>Bulan Ini</option>
                    <option value="custom" <?php echo e($preset == 'custom' ? 'selected' : ''); ?>>Kustom Rentang Tanggal</option>
                </select>
            </div>

            <?php if($preset == 'custom'): ?>
                <div class="col-6 col-md-2">
                    <label class="form-label text-xs text-muted mb-1">Dari Tanggal</label>
                    <input type="date" name="start_date" class="form-control bg-light border-0" value="<?php echo e($startDate); ?>">
                </div>
                <div class="col-6 col-md-2">
                    <label class="form-label text-xs text-muted mb-1">Sampai Tanggal</label>
                    <input type="date" name="end_date" class="form-control bg-light border-0" value="<?php echo e($endDate); ?>">
                </div>
            <?php endif; ?>

            <div class="col-6 col-md-3">
                <label class="form-label text-xs text-muted mb-1">Departemen</label>
                <select name="department_id" class="form-select bg-light border-0">
                    <option value="">Semua Departemen</option>
                    <?php $__currentLoopData = $departments; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $dept): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <option value="<?php echo e($dept->id); ?>" <?php echo e(request('department_id') == $dept->id ? 'selected' : ''); ?>><?php echo e($dept->name); ?></option>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </select>
            </div>
            <div class="col-6 col-md-2 d-flex align-items-end">
                <button type="submit" class="btn btn-primary w-100"><i class="bi bi-funnel me-1"></i> Terapkan</button>
            </div>
        </form>
    </div>
</div>


<div class="card shadow-sm border-0">
    <div class="card-header bg-white py-3 d-flex justify-content-between align-items-center">
        <h5 class="card-title mb-0 fw-bold">
            <i class="bi bi-file-earmark-text me-2 text-primary"></i> 
            Log Presensi (<?php echo e(\Carbon\Carbon::parse($startDate)->translatedFormat('d M Y')); ?> s/d <?php echo e(\Carbon\Carbon::parse($endDate)->translatedFormat('d M Y')); ?>)
        </h5>
        <span class="badge bg-light-primary text-primary">Total: <?php echo e($attendances->total()); ?> Record</span>
    </div>
    <div class="card-body p-0">
        <div class="table-responsive">
            <table class="table table-hover align-middle mb-0">
                <thead class="bg-light">
                    <tr>
                        <th class="ps-4">Tanggal</th>
                        <th>Karyawan</th>
                        <th>Departemen</th>
                        <th>Jam Masuk</th>
                        <th>Jam Pulang</th>
                        <th>Status</th>
                        <th>Terlambat</th>
                        <th class="pe-4">Jarak Geofence</th>
                    </tr>
                </thead>
                <tbody>
                    <?php $__empty_1 = true; $__currentLoopData = $attendances; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $att): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                        <tr>
                            <td class="ps-4">
                                <strong><?php echo e(\Carbon\Carbon::parse($att->attendance_date)->translatedFormat('d M Y')); ?></strong>
                            </td>
                            <td>
                                <div class="d-flex align-items-center">
                                    <div class="avatar avatar-sm bg-light-primary text-primary me-2 flex-shrink-0">
                                        <?php if($att->employee?->photo): ?>
                                            <img src="<?php echo e(asset($att->employee->photo)); ?>" alt="Avatar" style="width: 32px; height: 32px; object-fit: cover; border-radius: 50%;">
                                        <?php else: ?>
                                            <span class="avatar-content"><?php echo e(strtoupper(substr($att->employee?->name ?? 'K', 0, 2))); ?></span>
                                        <?php endif; ?>
                                    </div>
                                    <div>
                                        <h6 class="mb-0 fw-bold"><?php echo e($att->employee?->name ?? 'Karyawan'); ?></h6>
                                        <small class="text-muted"><?php echo e($att->employee?->nik); ?></small>
                                    </div>
                                </div>
                            </td>
                            <td><?php echo e($att->employee?->department?->name ?? '-'); ?></td>
                            <td>
                                <?php if($att->check_in): ?>
                                    <span class="fw-bold text-success"><?php echo e(\Carbon\Carbon::parse($att->check_in)->format('H:i')); ?></span>
                                <?php else: ?>
                                    <span class="text-muted">-</span>
                                <?php endif; ?>
                            </td>
                            <td>
                                <?php if($att->check_out): ?>
                                    <span class="fw-bold text-danger"><?php echo e(\Carbon\Carbon::parse($att->check_out)->format('H:i')); ?></span>
                                <?php else: ?>
                                    <span class="text-muted">-</span>
                                <?php endif; ?>
                            </td>
                            <td>
                                <span class="badge <?php echo e($att->status_badge); ?>"><?php echo e($att->status_label); ?></span>
                            </td>
                            <td>
                                <?php if($att->late_minutes > 0): ?>
                                    <span class="text-danger fw-bold">+<?php echo e($att->late_minutes); ?>m</span>
                                <?php else: ?>
                                    <span class="text-success">-</span>
                                <?php endif; ?>
                            </td>
                            <td class="pe-4">
                                <?php if($att->distance_in !== null): ?>
                                    <span class="badge bg-light-primary text-primary"><?php echo e(round($att->distance_in)); ?> Meter</span>
                                <?php else: ?>
                                    <span class="text-muted">-</span>
                                <?php endif; ?>
                            </td>
                        </tr>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                        <tr>
                            <td colspan="8" class="text-center py-5 text-muted">
                                Tidak ada log presensi pada periode yang dipilih.
                            </td>
                        </tr>
                    <?php endif; ?>
                </tbody>
            </table>
        </div>

        <?php if($attendances->hasPages()): ?>
            <div class="p-3 border-top d-flex justify-content-end">
                <?php echo e($attendances->links('pagination::bootstrap-5')); ?>

            </div>
        <?php endif; ?>
    </div>
</div>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\laragon\www\absensi\resources\views/admin/reports/index.blade.php ENDPATH**/ ?>