@extends('layouts.app')

@section('title', 'Daftar Sekolah - Admin KCD')

@section('content')
<div class="container-fluid">
    <!-- Page Header -->
    <div class="d-flex justify-content-between align-items-center mb-4">
        <div>
            <h1 class="h3 mb-0">Daftar Sekolah</h1>
            <p class="text-muted small mt-1">Data sekolah di wilayah KCD Anda</p>
        </div>
    </div>

    <!-- Statistics Cards -->
    <div class="row mb-4">
        <div class="col-md-3 col-sm-6 mb-3">
            <div class="card stat-card border-0 shadow-sm">
                <div class="card-body">
                    <div class="d-flex align-items-center">
                        <div class="flex-grow-1">
                            <h6 class="card-title text-muted mb-1">Total Sekolah</h6>
                            <h3 class="mb-0">{{ $stats['total'] }}</h3>
                            <small class="text-muted"><i class="bi bi-building"></i> Institusi</small>
                        </div>
                        <div class="text-primary opacity-50" style="font-size: 2rem;">
                            <i class="bi bi-building"></i>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-md-3 col-sm-6 mb-3">
            <div class="card stat-card success border-0 shadow-sm">
                <div class="card-body">
                    <div class="d-flex align-items-center">
                        <div class="flex-grow-1">
                            <h6 class="card-title text-muted mb-1">Sekolah Aktif</h6>
                            <h3 class="mb-0">{{ $stats['active'] }}</h3>
                            <small class="text-success"><i class="bi bi-check-circle"></i> Beroperasi</small>
                        </div>
                        <div class="text-success opacity-50" style="font-size: 2rem;">
                            <i class="bi bi-check-circle"></i>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-md-3 col-sm-6 mb-3">
            <div class="card stat-card info border-0 shadow-sm">
                <div class="card-body">
                    <div class="d-flex align-items-center">
                        <div class="flex-grow-1">
                            <h6 class="card-title text-muted mb-1">Sekolah Negeri</h6>
                            <h3 class="mb-0">{{ $schools->where('status', 'Negeri')->count() }}</h3>
                            <small class="text-info"><i class="bi bi-bank"></i> Pemerintah</small>
                        </div>
                        <div class="text-info opacity-50" style="font-size: 2rem;">
                            <i class="bi bi-bank"></i>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-md-3 col-sm-6 mb-3">
            <div class="card stat-card warning border-0 shadow-sm">
                <div class="card-body">
                    <div class="d-flex align-items-center">
                        <div class="flex-grow-1">
                            <h6 class="card-title text-muted mb-1">Sekolah Swasta</h6>
                            <h3 class="mb-0">{{ $schools->where('status', 'Swasta')->count() }}</h3>
                            <small class="text-warning"><i class="bi bi-briefcase"></i> Privat</small>
                        </div>
                        <div class="text-warning opacity-50" style="font-size: 2rem;">
                            <i class="bi bi-briefcase"></i>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- Data Table -->
    <div class="card border-0 shadow-sm">
        <div class="card-header bg-white border-bottom d-flex justify-content-between align-items-center">
            <h5 class="mb-0"><i class="bi bi-list-ul"></i> Daftar Sekolah</h5>
            <small class="text-muted">Total: {{ $schools->count() }} sekolah</small>
        </div>
        <div class="card-body p-0">
            @if($schools->isEmpty())
                <div class="text-center py-5 text-muted">
                    <i class="bi bi-inbox" style="font-size: 3rem;"></i>
                    <p class="mt-3">Belum ada sekolah di wilayah KCD ini</p>
                </div>
            @else
                <div class="table-responsive">
                    <table class="table table-hover mb-0">
                        <thead class="table-light">
                            <tr>
                                <th style="width: 5%">No</th>
                                <th style="width: 10%">NPSN</th>
                                <th style="width: 20%">Nama Sekolah</th>
                                <th style="width: 8%">Jenjang</th>
                                <th style="width: 8%">Status</th>
                                <th style="width: 10%">KCD</th>
                                <th style="width: 12%">Kepala Sekolah</th>
                                <th style="width: 7%">Active</th>
                            </tr>
                        </thead>
                        <tbody>
                            @foreach($schools as $index => $school)
                                <tr>
                                    <td>{{ $index + 1 }}</td>
                                    <td><code>{{ $school->npsn }}</code></td>
                                    <td>
                                        <strong>{{ $school->name }}</strong>
                                        @if($school->email)
                                            <br><small class="text-muted"><i class="bi bi-envelope"></i> {{ $school->email }}</small>
                                        @endif
                                    </td>
                                    <td>
                                        <span class="badge bg-{{ 
                                            $school->level == 'PAUD' ? 'info' : 
                                            ($school->level == 'SD' ? 'primary' : 
                                            ($school->level == 'SMP' ? 'success' : 
                                            ($school->level == 'SMA' ? 'warning' : 
                                            ($school->level == 'SMK' ? 'danger' : 'secondary')))) 
                                        }}">
                                            {{ $school->level }}
                                        </span>
                                    </td>
                                    <td>
                                        <span class="badge bg-{{ $school->status == 'Negeri' ? 'success' : 'warning' }}">
                                            {{ $school->status }}
                                        </span>
                                    </td>
                                    <td>
                                        <small>{{ $school->kcd->name ?? ($school->kabKota->kcd->name ?? '-') }}</small>
                                    </td>
                                    <td>
                                        <small>{{ $school->principal_name ?? '-' }}</small>
                                        @if($school->principal_nip)
                                            <br><small class="text-muted">NIP: {{ $school->principal_nip }}</small>
                                        @endif
                                    </td>
                                    <td>
                                        @if($school->is_active)
                                            <span class="badge bg-success"><i class="bi bi-check-circle"></i></span>
                                        @else
                                            <span class="badge bg-secondary"><i class="bi bi-x-circle"></i></span>
                                        @endif
                                    </td>
                                </tr>
                            @endforeach
                        </tbody>
                    </table>
                </div>
            @endif
        </div>
    </div>
</div>
@endsection
