@extends('layouts.app')

@section('title', 'Daftar Murid Baru')

@section('content')
<div class="container-fluid">
    <!-- Page Header -->
    <div class="d-flex justify-content-between align-items-center mb-4">
        <div>
            <h2 class="mb-1">
                <i class="bi bi-people-fill text-primary"></i>
                Daftar Murid Baru
            </h2>
            <p class="text-muted mb-0">Daftar siswa baru yang telah diinput</p>
        </div>
        <a href="{{ route('admin-sekolah.murid-baru.input') }}" class="btn btn-primary">
            <i class="bi bi-plus-circle me-1"></i> Tambah Murid Baru
        </a>
    </div>

    @if(session('success'))
    <div class="alert alert-success alert-dismissible fade show" role="alert">
        <i class="bi bi-check-circle me-2"></i>{{ session('success') }}
        <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
    </div>
    @endif

    @if(session('error'))
    <div class="alert alert-danger alert-dismissible fade show" role="alert">
        <i class="bi bi-exclamation-circle me-2"></i>{{ session('error') }}
        <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
    </div>
    @endif

    <!-- Filter Card -->
    <div class="card border-0 shadow-sm mb-4">
        <div class="card-body">
            <form method="GET" action="{{ route('admin-sekolah.murid-baru.daftar') }}" class="row g-3">
                <div class="col-md-4">
                    <label class="form-label">Cari</label>
                    <input type="text" name="search" class="form-control" placeholder="Nama, NIK, atau NIS" value="{{ request('search') }}">
                </div>
                <div class="col-md-3">
                    <label class="form-label">Jenis Ketunaan</label>
                    <select name="ketunaan" class="form-select">
                        <option value="">Semua Ketunaan</option>
                        @foreach($disabilityTypes as $type)
                            <option value="{{ $type->id }}" {{ request('ketunaan') == $type->id ? 'selected' : '' }}>
                                {{ $type->name }}
                            </option>
                        @endforeach
                    </select>
                </div>
                <div class="col-md-2">
                    <label class="form-label">Jenis Kelamin</label>
                    <select name="jk" class="form-select">
                        <option value="">Semua</option>
                        <option value="L" {{ request('jk') == 'L' ? 'selected' : '' }}>Laki-laki</option>
                        <option value="P" {{ request('jk') == 'P' ? 'selected' : '' }}>Perempuan</option>
                    </select>
                </div>
                <div class="col-md-3 d-flex align-items-end gap-2">
                    <button type="submit" class="btn btn-primary">
                        <i class="bi bi-search me-1"></i> Filter
                    </button>
                    <a href="{{ route('admin-sekolah.murid-baru.daftar') }}" class="btn btn-secondary">
                        <i class="bi bi-arrow-counterclockwise me-1"></i> Reset
                    </a>
                </div>
            </form>
        </div>
    </div>

    <!-- Students Table -->
    <div class="card border-0 shadow-sm">
        <div class="card-header bg-white py-3">
            <h5 class="mb-0">
                <i class="bi bi-table me-2"></i>
                Total: {{ $students->total() }} Siswa
            </h5>
        </div>
        <div class="card-body p-0">
            @if($students->count() > 0)
            <div class="table-responsive">
                <table class="table table-hover mb-0">
                    <thead class="table-light">
                        <tr>
                            <th width="50">No</th>
                            <th>NIK / NIS</th>
                            <th>Nama Siswa</th>
                            <th>JK</th>
                            <th>TTL</th>
                            <th>Jenis Ketunaan</th>
                            <th>Orang Tua</th>
                            <th>Tanggal Input</th>
                            <th width="150" class="text-center">Aksi</th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach($students as $index => $student)
                        <tr>
                            <td>{{ $students->firstItem() + $index }}</td>
                            <td>
                                <small class="d-block text-muted">{{ $student->nik }}</small>
                                <strong>{{ $student->nis }}</strong>
                            </td>
                            <td>
                                <strong>{{ $student->nama }}</strong>
                                <br>
                                <small class="text-muted">Kelas {{ $student->kelas }}</small>
                            </td>
                            <td>
                                @if($student->jenis_kelamin == 'L')
                                    <span class="badge bg-info">L</span>
                                @else
                                    <span class="badge bg-pink">P</span>
                                @endif
                            </td>
                            <td>
                                <small>{{ $student->tempat_lahir }},<br>{{ $student->tanggal_lahir->format('d/m/Y') }}</small>
                            </td>
                            <td>
                                <span class="badge bg-warning text-dark">
                                    {{ $student->disabilityType->code ?? '-' }}
                                </span>
                                <small class="d-block mt-1">{{ $student->disabilityType->name ?? '-' }}</small>
                            </td>
                            <td>
                                <small>
                                    <strong>Ayah:</strong> {{ $student->nama_ayah }}<br>
                                    <strong>Ibu:</strong> {{ $student->nama_ibu }}
                                </small>
                            </td>
                            <td>
                                <small>{{ $student->created_at->format('d/m/Y H:i') }}</small>
                            </td>
                            <td class="text-center">
                                <a href="{{ route('admin-sekolah.murid-baru.detail', $student->id) }}" 
                                   class="btn btn-sm btn-info" title="Detail">
                                    <i class="bi bi-eye"></i>
                                </a>
                                <form action="{{ route('admin-sekolah.murid-baru.delete', $student->id) }}" 
                                      method="POST" class="d-inline" 
                                      onsubmit="return confirm('Yakin ingin menghapus data {{ $student->nama }}?')">
                                    @csrf
                                    @method('DELETE')
                                    <button type="submit" class="btn btn-sm btn-danger" title="Hapus">
                                        <i class="bi bi-trash"></i>
                                    </button>
                                </form>
                            </td>
                        </tr>
                        @endforeach
                    </tbody>
                </table>
            </div>
            
            <!-- Pagination -->
            <div class="p-3">
                {{ $students->links() }}
            </div>
            @else
            <div class="text-center py-5">
                <i class="bi bi-inbox display-1 text-muted"></i>
                <p class="text-muted mt-3">Belum ada data siswa</p>
                <a href="{{ route('admin-sekolah.murid-baru.input') }}" class="btn btn-primary">
                    <i class="bi bi-plus-circle me-1"></i> Tambah Murid Baru
                </a>
            </div>
            @endif
        </div>
    </div>
</div>

<style>
    .bg-pink {
        background-color: #ff69b4 !important;
        color: white !important;
    }
    
    .table > tbody > tr:hover {
        background-color: #f8f9fa;
    }
</style>
@endsection
