{{-- resources/views/admin/kegiatan/riwayat/_card.blade.php --}}
{{-- Diinclude dari index.blade.php --}}
@php
    $totalSantri = $kegiatan->total_absensi;
    $hdr  = $kegiatan->hadir     ?? 0;
    $tlb  = $kegiatan->terlambat ?? 0;
    $izn  = $kegiatan->izin      ?? 0;
    $skt  = $kegiatan->sakit     ?? 0;
    $alp  = $kegiatan->alpa      ?? 0;
    $plg  = $kegiatan->pulang    ?? 0;
    $tot  = $kegiatan->total_absensi ?? 0;

    $pct  = fn($n) => $tot > 0 ? round($n / $tot * 100) : 0;

    $isUmum = $kegiatan->kelasKegiatan->isEmpty();
@endphp

<div class="rw-card">

    {{-- Header --}}
    <div class="rw-card-head">
        <div style="flex: 1; min-width: 0;">
            <div class="rw-card-title">
                <i class="fas fa-clipboard-list"></i>
                {{ $kegiatan->nama_kegiatan }}
            </div>
            <div class="rw-card-meta">
                <span><i class="fas fa-clock"></i>
                    {{ date('H:i', strtotime($kegiatan->waktu_mulai)) }}–{{ date('H:i', strtotime($kegiatan->waktu_selesai)) }}
                </span>
                <span class="rw-kat-tag"><i class="fas fa-tag"></i> {{ $kegiatan->kategori->nama_kategori }}</span>
                @if($isUmum)
                    <span class="rw-umum-tag"><i class="fas fa-globe"></i> Umum</span>
                @else
                    @foreach($kegiatan->kelasKegiatan->take(3) as $kls)
                        <span class="rw-kelas-tag">{{ $kls->nama_kelas }}</span>
                    @endforeach
                    @if($kegiatan->kelasKegiatan->count() > 3)
                        <span class="rw-umum-tag">+{{ $kegiatan->kelasKegiatan->count() - 3 }} kelas</span>
                    @endif
                @endif
            </div>
        </div>

        {{-- Hari badge (jika mode hari ini) --}}
        @if(isset($passParams) && $passParams['mode'] === 'hari_ini')
        <div style="font-size: 0.75rem; color: var(--primary-color); font-weight: 700;
                    background: #f0fdf4; padding: 4px 10px; border-radius: 20px; border: 1px solid #bbf7d0;
                    white-space: nowrap; flex-shrink: 0;">
            <i class="fas fa-calendar-day"></i> {{ $kegiatan->hari }}
        </div>
        @endif
    </div>

    {{-- Body: stats --}}
    <div class="rw-card-body">
        @if($tot > 0)
            {{-- Chips --}}
            <div class="rw-stats-row">
                @if($hdr > 0) <span class="rw-chip hadir"><i class="fas fa-check"></i> {{ $hdr }} Hadir</span> @endif
                @if($tlb > 0) <span class="rw-chip terlambat"><i class="fas fa-clock"></i> {{ $tlb }} Terlambat</span> @endif
                @if($izn > 0) <span class="rw-chip izin"><i class="fas fa-envelope"></i> {{ $izn }} Izin</span> @endif
                @if($skt > 0) <span class="rw-chip sakit"><i class="fas fa-heartbeat"></i> {{ $skt }} Sakit</span> @endif
                @if($alp > 0) <span class="rw-chip alpa"><i class="fas fa-times"></i> {{ $alp }} Alpa</span> @endif
                @if($plg > 0) <span class="rw-chip pulang"><i class="fas fa-home"></i> {{ $plg }} Pulang</span> @endif
            </div>

            {{-- Progress bar --}}
            <div class="rw-progress-wrap">
                @if($hdr > 0)  <div class="rw-prog-hadir"     style="width:{{ $pct($hdr) }}%;" title="Hadir {{ $hdr }}"></div> @endif
                @if($tlb > 0)  <div class="rw-prog-terlambat" style="width:{{ $pct($tlb) }}%;" title="Terlambat {{ $tlb }}"></div> @endif
                @if($izn > 0)  <div class="rw-prog-izin"      style="width:{{ $pct($izn) }}%;" title="Izin {{ $izn }}"></div> @endif
                @if($skt > 0)  <div class="rw-prog-sakit"     style="width:{{ $pct($skt) }}%;" title="Sakit {{ $skt }}"></div> @endif
                @if($alp > 0)  <div class="rw-prog-alpa"      style="width:{{ $pct($alp) }}%;" title="Alpa {{ $alp }}"></div> @endif
                @if($plg > 0)  <div class="rw-prog-pulang"    style="width:{{ $pct($plg) }}%;" title="Pulang {{ $plg }}"></div> @endif
            </div>
            <div style="font-size: 0.74rem; color: #94a3b8;">
                Total tercatat: <strong style="color:#374151;">{{ $tot }}</strong> santri
            </div>
        @else
            <span class="rw-chip none"><i class="fas fa-inbox"></i> Belum ada data absensi</span>
        @endif
    </div>

    {{-- Footer --}}
    <div class="rw-card-foot">
        <div class="rw-total-txt">
            @if($tot > 0)
                <i class="fas fa-users" style="color:var(--primary-color);"></i>
                <strong>{{ $hdr + $tlb }}</strong> hadir dari <strong>{{ $tot }}</strong> tercatat
            @else
                <span style="color:#cbd5e1;"><i class="fas fa-info-circle"></i> Belum ada absensi diinput</span>
            @endif
        </div>

        @php
            $detailParams = array_merge($passParams ?? [], ['kategori_id' => request('kategori_id')]);
        @endphp
        <a href="{{ route('admin.riwayat-kegiatan.show', $kegiatan->id) }}?{{ http_build_query($detailParams) }}"
           class="btn-rw-detail">
            <i class="fas fa-users"></i> Lihat Santri
        </a>
    </div>
</div>