@extends('layouts.app')

@section('title', 'Dashboard Admin KCD')

@section('content')
            <!-- Header -->
            <div class="d-flex justify-content-between align-items-center mb-4 flex-wrap">
                <div class="mb-2 mb-md-0">
                    <h3 class="mb-1">Dashboard Admin KCD</h3>
                    <p class="text-muted mb-0">Selamat datang, <strong>{{ $user->name }}</strong></p>
                    @if($data['kcd'])
                    <small class="text-muted"><i class="bi bi-geo-alt"></i> {{ $data['kcd']->name }}</small>
                    @endif
                </div>
                <div class="text-end">
                    <small class="text-muted d-none d-md-block">{{ now()->isoFormat('dddd, D MMMM Y') }}</small>
                    <small class="text-muted d-md-none">{{ now()->isoFormat('D MMM Y') }}</small>
                </div>
            </div>

            <!-- Academic Year Info -->
            @if($activeAcademicYear)
            <div class="alert alert-info border-0 shadow-sm mb-4" role="alert">
                <div class="d-flex align-items-center">
                    <div class="flex-shrink-0">
                        <i class="bi bi-calendar-check-fill fs-3"></i>
                    </div>
                    <div class="flex-grow-1 ms-3">
                        <h6 class="alert-heading mb-1">
                            <i class="bi bi-star-fill text-warning me-1"></i>
                            Tahun Ajaran Aktif: <strong>{{ $activeAcademicYear->name }}</strong>
                        </h6>
                        <p class="mb-0 small">
                            <i class="bi bi-calendar-event me-1"></i>
                            Periode: {{ $activeAcademicYear->start_date->format('d M Y') }} - {{ $activeAcademicYear->end_date->format('d M Y') }}
                        </p>
                    </div>
                </div>
            </div>
            @endif

            <!-- Statistics Cards -->
            <div class="row mb-4">
                <div class="col-6 col-md-3 mb-3">
                    <div class="card border-0 shadow-sm h-100">
                        <div class="card-body">
                            <div class="d-flex justify-content-between align-items-center">
                                <div>
                                    <h6 class="text-muted fw-normal mb-1 small">Total Sekolah</h6>
                                    <h3 class="mb-0 text-primary">{{ $data['total_schools'] }}</h3>
                                    <small class="text-success">
                                        <i class="bi bi-check-circle"></i> {{ $data['active_schools'] }} Aktif
                                    </small>
                                </div>
                                <div class="d-none d-sm-block">
                                    <i class="bi bi-building text-primary opacity-50" style="font-size: 2.5rem;"></i>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="col-6 col-md-3 mb-3">
                    <div class="card border-0 shadow-sm h-100">
                        <div class="card-body">
                            <div class="d-flex justify-content-between align-items-center">
                                <div>
                                    <h6 class="text-muted fw-normal mb-1 small">Pengawas Aktif</h6>
                                    <h3 class="mb-0 text-success">{{ $data['total_pengawas'] }}</h3>
                                    <small class="text-muted">Supervisi KCD</small>
                                </div>
                                <div class="d-none d-sm-block">
                                    <i class="bi bi-people text-success opacity-50" style="font-size: 2.5rem;"></i>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="col-6 col-md-3 mb-3">
                    <div class="card border-0 shadow-sm h-100">
                        <div class="card-body">
                            <div class="d-flex justify-content-between align-items-center">
                                <div>
                                    <h6 class="text-muted fw-normal mb-1 small">Sekolah Aktif</h6>
                                    <h3 class="mb-0 text-info">{{ $data['active_schools'] }}</h3>
                                    <small class="text-muted">Operasional</small>
                                </div>
                                <div class="d-none d-sm-block">
                                    <i class="bi bi-check-circle text-info opacity-50" style="font-size: 2.5rem;"></i>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="col-6 col-md-3 mb-3">
                    <div class="card border-0 shadow-sm h-100">
                        <div class="card-body">
                            <div class="d-flex justify-content-between align-items-center">
                                <div>
                                    <h6 class="text-muted fw-normal mb-1 small">Form Evaluasi</h6>
                                    <h3 class="mb-0 text-warning">{{ $data['active_forms'] }}</h3>
                                    <small class="text-muted">Aktif</small>
                                </div>
                                <div class="d-none d-sm-block">
                                    <i class="bi bi-file-text text-warning opacity-50" style="font-size: 2.5rem;"></i>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <!-- Recent Activities & Quick Actions -->
            <div class="row">
                <div class="col-lg-8 mb-4">
                    <div class="card border-0 shadow-sm">
                        <div class="card-header bg-white border-bottom">
                            <h5 class="card-title mb-0">
                                <i class="bi bi-clock-history text-info"></i> Aktivitas Terbaru
                            </h5>
                        </div>
                        <div class="card-body">
                            @if($data['recent_activities']->count() > 0)
                                <div class="list-group list-group-flush">
                                    @foreach($data['recent_activities'] as $activity)
                                    <div class="list-group-item px-0 py-3">
                                        <div class="d-flex align-items-start">
                                            <div class="flex-shrink-0">
                                                <span class="badge bg-{{ $activity['color'] }} rounded-circle p-2">
                                                    <i class="bi bi-{{ $activity['icon'] }}"></i>
                                                </span>
                                            </div>
                                            <div class="flex-grow-1 ms-3">
                                                <div class="d-flex w-100 justify-content-between flex-wrap">
                                                    <h6 class="mb-1">{{ $activity['message'] }}</h6>
                                                    <small class="text-muted">{{ $activity['time'] }}</small>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    @endforeach
                                </div>
                            @else
                                <div class="text-center py-4">
                                    <i class="bi bi-inbox text-muted" style="font-size: 3rem;"></i>
                                    <p class="text-muted mt-2 mb-0">Belum ada aktivitas terbaru</p>
                                </div>
                            @endif
                        </div>
                    </div>
                </div>

                <div class="col-lg-4 mb-4">
                    <div class="card border-0 shadow-sm">
                        <div class="card-header bg-white border-bottom">
                            <h5 class="card-title mb-0">
                                <i class="bi bi-lightning-fill text-warning"></i> Aksi Cepat
                            </h5>
                        </div>
                        <div class="card-body">
                            <div class="d-grid gap-2">
                                <a href="{{ route('admin-kcd.sekolah') }}" class="btn btn-primary btn-sm">
                                    <i class="bi bi-building"></i> Kelola Sekolah
                                </a>
                                <a href="{{ route('admin-kcd.pengawas') }}" class="btn btn-outline-success btn-sm">
                                    <i class="bi bi-people"></i> Kelola Pengawas
                                </a>
                                <a href="{{ route('admin-kcd.mapping-sekolah') }}" class="btn btn-outline-info btn-sm">
                                    <i class="bi bi-geo-alt"></i> Mapping Sekolah
                                </a>
                                <a href="#" class="btn btn-outline-secondary btn-sm">
                                    <i class="bi bi-download"></i> Export Data
                                </a>
                            </div>
                        </div>
                    </div>

                    <!-- KCD Info Card -->
                    @if($data['kcd'])
                    <div class="card border-0 shadow-sm mt-3">
                        <div class="card-header bg-white border-bottom">
                            <h6 class="card-title mb-0">
                                <i class="bi bi-info-circle text-info"></i> Informasi KCD
                            </h6>
                        </div>
                        <div class="card-body">
                            <table class="table table-sm table-borderless mb-0">
                                <tr>
                                    <td class="text-muted"><small><strong>Nama KCD</strong></small></td>
                                    <td><small>{{ $data['kcd']->name }}</small></td>
                                </tr>
                                <tr>
                                    <td class="text-muted"><small><strong>Kode</strong></small></td>
                                    <td><small>{{ $data['kcd']->code }}</small></td>
                                </tr>
                                <tr>
                                    <td class="text-muted"><small><strong>Total Sekolah</strong></small></td>
                                    <td><small>{{ $data['total_schools'] }} sekolah</small></td>
                                </tr>
                                <tr>
                                    <td class="text-muted"><small><strong>Pengawas</strong></small></td>
                                    <td><small>{{ $data['total_pengawas'] }} orang</small></td>
                                </tr>
                            </table>
                        </div>
                    </div>
                    @endif
                </div>
            </div>

            <!-- Recent Schools Table -->
            @if($data['recent_schools']->count() > 0)
            <div class="row">
                <div class="col-12">
                    <div class="card border-0 shadow-sm">
                        <div class="card-header bg-white border-bottom">
                            <div class="d-flex justify-content-between align-items-center">
                                <h5 class="card-title mb-0">
                                    <i class="bi bi-building text-primary"></i> Sekolah Terdaftar
                                </h5>
                                <a href="{{ route('admin-kcd.sekolah') }}" class="btn btn-sm btn-outline-primary">
                                    Lihat Semua <i class="bi bi-arrow-right"></i>
                                </a>
                            </div>
                        </div>
                        <div class="card-body">
                            <div class="table-responsive">
                                <table class="table table-hover align-middle mb-0">
                                    <thead class="table-light">
                                        <tr>
                                            <th>Nama Sekolah</th>
                                            <th>NPSN</th>
                                            <th>Kab/Kota</th>
                                            <th class="text-center">Status</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        @foreach($data['recent_schools'] as $school)
                                        <tr>
                                            <td>
                                                <strong>{{ $school->name }}</strong>
                                            </td>
                                            <td>{{ $school->npsn }}</td>
                                            <td>{{ $school->kabKota->name ?? '-' }}</td>
                                            <td class="text-center">
                                                @if($school->is_active)
                                                    <span class="badge bg-success">Aktif</span>
                                                @else
                                                    <span class="badge bg-secondary">Nonaktif</span>
                                                @endif
                                            </td>
                                        </tr>
                                        @endforeach
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            @endif

            <!-- Info Alert -->
            <div class="row mt-4">
                <div class="col-12">
                    <div class="alert alert-info border-0 shadow-sm" role="alert">
                        <div class="d-flex align-items-center">
                            <i class="bi bi-lightbulb me-2" style="font-size: 1.5rem;"></i>
                            <div>
                                <strong>Tips:</strong> Anda dapat mengelola sekolah dan pengawas di wilayah KCD Anda melalui menu di sidebar. 
                                Gunakan fitur mapping untuk menugaskan pengawas ke sekolah binaan.
                            </div>
                        </div>
                    </div>
                </div>
            </div>
@endsection