@extends('layouts.app')

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

@section('content')
<!-- Main 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 Dinas</h3>
            <p class="text-muted mb-0">Selamat datang, <strong>{{ $user->name }}</strong></p>
            <small class="text-muted"><i class="bi bi-shield-check"></i> Administrator Dinas</small>
        </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>
    @else
    <div class="alert alert-warning border-0 shadow-sm mb-4" role="alert">
        <div class="d-flex align-items-center">
            <i class="bi bi-exclamation-triangle-fill me-2"></i>
            <div>
                <strong>Perhatian:</strong> Belum ada tahun ajaran yang aktif. Hubungi SuperAdmin.
            </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 KCD</h6>
                                    <h3 class="mb-0 text-primary">{{ $data['total_kcd'] }}</h3>
                                    <small class="text-muted">Kawasan</small>
                                </div>
                                <div class="d-none d-sm-block">
                                    <i class="bi bi-geo-alt 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">Total Pengawas</h6>
                                    <h3 class="mb-0 text-success">{{ $data['total_pengawas'] }}</h3>
                                    <small class="text-muted">Aktif</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">Total Sekolah</h6>
                                    <h3 class="mb-0 text-info">{{ $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-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-dinas.pengawas') }}" class="btn btn-primary btn-sm">
                                    <i class="bi bi-person-plus"></i> Tambah Pengawas
                                </a>
                                <a href="{{ route('admin-dinas.sekolah.index') }}" class="btn btn-outline-primary btn-sm">
                                    <i class="bi bi-building"></i> Kelola Sekolah
                                </a>
                                <a href="{{ route('admin-dinas.mapping-kcd') }}" class="btn btn-outline-info btn-sm">
                                    <i class="bi bi-geo"></i> Mapping KCD
                                </a>
                                <a href="#" class="btn btn-outline-secondary btn-sm">
                                    <i class="bi bi-download"></i> Export Data
                                </a>
                            </div>
                        </div>
                    </div>

                    <!-- Summary Card -->
                    <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-bar-chart text-success"></i> Ringkasan
                            </h6>
                        </div>
                        <div class="card-body">
                            <div class="mb-3">
                                <div class="d-flex justify-content-between mb-1">
                                    <small class="text-muted">Sekolah Aktif</small>
                                    <small class="text-muted">{{ $data['total_schools'] > 0 ? round(($data['active_schools'] / $data['total_schools']) * 100) : 0 }}%</small>
                                </div>
                                <div class="progress" style="height: 6px;">
                                    <div class="progress-bar bg-success" role="progressbar" style="width: {{ $data['total_schools'] > 0 ? ($data['active_schools'] / $data['total_schools']) * 100 : 0 }}%"></div>
                                </div>
                            </div>
                            <div class="mb-3">
                                <div class="d-flex justify-content-between mb-1">
                                    <small class="text-muted">Form Aktif</small>
                                    <small class="text-muted">{{ $data['total_forms'] > 0 ? round(($data['active_forms'] / $data['total_forms']) * 100) : 0 }}%</small>
                                </div>
                                <div class="progress" style="height: 6px;">
                                    <div class="progress-bar bg-warning" role="progressbar" style="width: {{ $data['total_forms'] > 0 ? ($data['active_forms'] / $data['total_forms']) * 100 : 0 }}%"></div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <!-- Info Cards -->
            <div class="row">
                <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>Informasi Sistem:</strong> AppSuper PKLK dirancang untuk mengelola 
                                penugasan pengawas dengan model Hybrid (Macro + Micro Mapping), validasi SPTJM, dan pemetaan kompetensi dinamis.
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
@endsection