<x-app-layout>
@push('styles')
    <link rel="stylesheet" href="{{ asset('css/tugas.css') }}">
    <style>
        .pug-nav-tabs {
            display: flex; gap: 10px; margin-bottom: 24px; flex-wrap: wrap;
        }
        .pug-nav-item {
            padding: 12px 20px; border-radius: 12px; font-size: 13px; font-weight: 700;
            border: 1px solid var(--pug-border); color: var(--pug-t2);
            background: var(--pug-white); cursor: pointer; transition: all .2s; font-family: var(--pug-font);
            display: flex; align-items: center; gap: 8px; text-decoration: none;
            box-shadow: 0 1px 3px rgba(0,0,0,0.04);
        }
        .pug-nav-item i { font-size: 14px; opacity: 0.7; }
        .pug-nav-item:hover { border-color: var(--pug-green); color: var(--pug-green); background: var(--pug-green-l); transform: translateY(-2px); box-shadow: 0 4px 12px rgba(26,122,74,0.1); }
        .pug-nav-item.active { border-color: var(--pug-green); color: var(--pug-green); background: var(--pug-green-l); box-shadow: 0 4px 12px rgba(26,122,74,0.15); }
        .pug-nav-item.active i { opacity: 1; }
    </style>
@endpush

<div class="pug-wrap">
    <div class="pug-inner">
        
        {{-- ── PAGE HEADER ── --}}
        <div style="display:flex; align-items:center; justify-content:space-between; margin-bottom:24px;">
            <div style="display:flex; align-items:center; gap:15px;">
                <div class="pug-icon-wrap" style="width: 54px; height: 54px; font-size: 22px;">
                    <i class="fas fa-calendar-check"></i>
                </div>
                <div>
                    <h1 class="pug-page-title" style="font-size: 24px;">Laporan Kehadiran</h1>
                    <p class="pug-page-sub">Rekapitulasi kehadiran harian teknisi PDAM • {{ date('F Y') }}</p>
                </div>
            </div>
            <a href="{{ route('laporan.absensi.export', request()->query()) }}" target="_blank" class="pug-btn-primary" style="text-decoration: none; background: linear-gradient(135deg, var(--pug-t1), #334155);">
                <i class="fas fa-print"></i> Cetak Laporan
            </a>
        </div>

        {{-- ── TAB NAVIGATION ── --}}
        <div class="pug-nav-tabs">
            <a href="{{ route('laporan.index') }}" class="pug-nav-item">
                <i class="fas fa-th-large"></i> Ringkasan
            </a>
            <a href="{{ route('laporan.kasbon') }}" class="pug-nav-item">
                <i class="fas fa-hand-holding-usd"></i> Kasbon
            </a>
            <a href="{{ route('laporan.absensi') }}" class="pug-nav-item active">
                <i class="fas fa-calendar-check"></i> Kehadiran
            </a>
            <a href="{{ route('laporan.teknisi') }}" class="pug-nav-item">
                <i class="fas fa-users"></i> Performa Teknisi
            </a>
            <a href="{{ route('laporan.pekerjaan') }}" class="pug-nav-item">
                <i class="fas fa-tasks"></i> Pekerjaan
            </a>
            <a href="{{ route('laporan.penggajian') }}" class="pug-nav-item">
                <i class="fas fa-money-check-alt"></i> Penggajian
            </a>
            <a href="{{ route('laporan.data_teknisi') }}" class="pug-nav-item">
                <i class="fas fa-id-card"></i> Data Teknisi
            </a>
        </div>

        {{-- ── STATS ── --}}
        <div class="pug-stats" style="grid-template-columns: repeat(4, 1fr);">
            <div class="pug-stat pug-stat-selesai">
                <div class="pug-stat-icon"><i class="fas fa-user-check"></i></div>
                <div class="pug-stat-label">HADIR BULAN INI</div>
                <div class="pug-stat-val">{{ $statsAbsensi['hadir'] ?? 0 }}</div>
                <div class="pug-page-sub">Kehadiran tercatat</div>
            </div>
            <div class="pug-stat pug-stat-proses">
                <div class="pug-stat-icon" style="background: var(--pug-violet-l); color: var(--pug-violet);"><i class="fas fa-info-circle"></i></div>
                <div class="pug-stat-label">IZIN</div>
                <div class="pug-stat-val" style="color: var(--pug-violet);">{{ $statsAbsensi['izin'] ?? 0 }}</div>
                <div class="pug-page-sub">Permohonan izin</div>
            </div>
            <div class="pug-stat pug-stat-belum">
                <div class="pug-stat-icon" style="background: var(--pug-amber-l); color: var(--pug-amber);"><i class="fas fa-briefcase-medical"></i></div>
                <div class="pug-stat-label">SAKIT</div>
                <div class="pug-stat-val" style="color: var(--pug-amber);">{{ $statsAbsensi['sakit'] ?? 0 }}</div>
                <div class="pug-page-sub">Keterangan sakit</div>
            </div>
            <div class="pug-stat pug-stat-batal">
                <div class="pug-stat-icon" style="background: var(--pug-rose-l); color: var(--pug-rose);"><i class="fas fa-user-times"></i></div>
                <div class="pug-stat-label">ALPHA</div>
                <div class="pug-stat-val" style="color: var(--pug-rose);">{{ $statsAbsensi['alpha'] ?? 0 }}</div>
                <div class="pug-page-sub">Tanpa keterangan</div>
            </div>
        </div>

        {{-- ── TOOLBAR FILTER ── --}}
        <div class="pug-toolbar" style="margin-bottom: 24px;">
            <form method="GET" action="{{ route('laporan.absensi') }}" class="pug-toolbar-form">
                
                <div class="pug-toolbar-item" style="flex: 1; min-width: 250px;">
                    <label class="pug-field-label">Tanggal</label>
                    <div class="pug-input-icon">
                        <i class="fas fa-calendar-alt"></i>
                        <input type="date" name="tanggal" class="pug-input" value="{{ request('tanggal') }}">
                    </div>
                </div>

                <div class="pug-toolbar-item item-btn d-flex align-items-end gap-2" style="flex: 0 0 auto;">
                    <button type="submit" class="pug-btn-primary" style="height: 44px; margin-bottom: 0;">
                        <i class="fas fa-filter"></i> Filter
                    </button>
                    @if(request()->hasAny(['tanggal']))
                    <a href="{{ route('laporan.absensi') }}" class="pug-reset-btn" style="height: 44px; text-decoration: none;">
                        <i class="fas fa-redo"></i> Reset
                    </a>
                    @endif
                </div>
            </form>
        </div>

        {{-- ── TABLE PANEL ── --}}
        <div class="pug-panel">
            <div class="pug-panel-head">
                <div class="pug-panel-head-left">
                    <i class="fas fa-list-ul" style="color:var(--pug-green);margin-right:8px;"></i>
                    Data Laporan Kehadiran
                </div>
                <div class="pug-panel-head-right">
                    {{ $data->total() }} data ditemukan
                </div>
            </div>

            <div style="overflow-x:auto;">
                <table class="pug-table">
                    <thead>
                        <tr>
                            <th>Teknisi</th>
                            <th>Tanggal</th>
                            <th>Status Kehadiran</th>
                            <th>Keterangan</th>
                        </tr>
                    </thead>
                    <tbody>
                        @forelse($data as $item)
                        <tr>
                            <td>
                                <div style="display:flex; align-items:center; gap:12px;">
                                    <div class="pug-av">{{ strtoupper(substr($item->nama_teknisi ?? '?', 0, 2)) }}</div>
                                    <div class="pug-av-name">{{ $item->nama_teknisi ?? '-' }}</div>
                                </div>
                            </td>
                            <td><div class="pug-date">{{ \Carbon\Carbon::parse($item->tanggal)->format('d M Y') }}</div></td>
                            <td>
                                @php
                                    $st = strtolower($item->status);
                                    $bc = 'pug-badge-amber'; $ic = 'fa-clock';
                                    if($st == 'hadir') { $bc = 'pug-badge-green'; $ic = 'fa-check-circle'; }
                                    if(in_array($st, ['alpha','sakit'])) { $bc = 'pug-badge-rose'; $ic = 'fa-times-circle'; }
                                    if($st == 'izin') { $bc = 'pug-badge-violet'; $ic = 'fa-info-circle'; }
                                @endphp
                                <span class="pug-badge {{ $bc }}">
                                    <i class="fas {{ $ic }}"></i> {{ strtoupper($item->status) }}
                                </span>
                            </td>
                            <td>
                                <span style="font-size: 12px; color: var(--pug-t2); display: block; margin-bottom: 4px;">{{ $item->keterangan ?? '-' }}</span>
                                @if(!empty($item->latitude) && !empty($item->longitude))
                                <a href="https://maps.google.com/?q={{ $item->latitude }},{{ $item->longitude }}" target="_blank" class="pug-badge" style="background-color: var(--pug-blue-l); color: var(--pug-blue); text-decoration: none; padding: 4px 8px; font-size: 10px; display: inline-flex; align-items: center; gap: 4px;">
                                    <i class="fas fa-map-marker-alt"></i> Cek Lokasi
                                </a>
                                @endif
                            </td>
                        </tr>
                        @empty
                        <tr>
                            <td colspan="4">
                                <div class="pug-empty">
                                    <div class="pug-empty-icon"><i class="fas fa-inbox"></i></div>
                                    <div class="pug-empty-title">Tidak ada data kehadiran</div>
                                    <div class="pug-empty-sub">Ubah filter pencarian untuk melihat data lain.</div>
                                </div>
                            </td>
                        </tr>
                        @endforelse
                    </tbody>
                </table>
            </div>

            @if($data->hasPages())
            <div class="pug-pag">
                {{ $data->links() }}
            </div>
            @endif
        </div>

    </div>
</div>
</x-app-layout>
