@extends('layouts.app')

@section('title', 'Detail Peserta PSAJ')

@section('content')
<div class="container-fluid">
    <div class="mb-4">
        <h1 class="h3 mb-2">Detail Peserta PSAJ</h1>
        <p class="text-muted mb-0">{{ $participant->school->name }}</p>
    </div>

    @if (session('success'))
        <div class="alert alert-success alert-dismissible fade show" role="alert">
            {{ 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">
            {{ session('error') }}
            <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
        </div>
    @endif

    <div class="row">
        <div class="col-md-4">
            <div class="card">
                <div class="card-body text-center">
                    @if ($participant->photo)
                        <img src="{{ asset('storage/' . $participant->photo) }}" 
                             alt="Foto {{ $participant->nama }}" 
                             class="img-thumbnail mb-3" 
                             style="max-width: 200px;">
                    @else
                        <div class="bg-light p-5 mb-3 rounded">
                            <i class="bi bi-person fs-1 text-muted"></i>
                            <p class="text-muted mb-0 mt-2">Tidak ada foto</p>
                        </div>
                    @endif
                    
                    <h4>{{ $participant->nama }}</h4>
                    <p class="text-muted mb-2">{{ $participant->no_peserta }}</p>
                    
                    <div class="d-flex justify-content-center gap-2 mb-3">
                        <span class="badge bg-primary">{{ $participant->jenjang }}</span>
                        <span class="badge bg-info">Kelas {{ $participant->kelas }}</span>
                        <span class="badge bg-warning text-dark">{{ $participant->disabilityType->code }}</span>
                        @if ($participant->is_locked)
                            <span class="badge bg-success" title="Data final, terkunci pada {{ $participant->submitted_at?->format('d/m/Y H:i') }}">
                                <i class="bi bi-lock-fill me-1"></i>Final
                            </span>
                        @else
                            <span class="badge bg-secondary">
                                <i class="bi bi-pencil me-1"></i>Draft
                            </span>
                        @endif
                    </div>

                    <div class="d-grid gap-2">
                        @if ($participant->is_locked)
                            <form method="POST" action="{{ route('admin-dinas.psaj.unlock', $participant->id) }}" onsubmit="return confirm('Apakah Anda yakin ingin membuka kunci data peserta ini? Sekolah dapat mengedit kembali data ini.')">
                                @csrf
                                <button type="submit" class="btn btn-danger w-100">
                                    <i class="bi bi-unlock me-2"></i>Buka Kunci Data
                                </button>
                            </form>
                        @else
                            <button class="btn btn-secondary" disabled>
                                <i class="bi bi-pencil me-2"></i>Data Belum Terkunci
                            </button>
                        @endif
                    </div>
                </div>
            </div>
        </div>

        <div class="col-md-8">
            <div class="card">
                <div class="card-header">
                    <h5 class="mb-0">Informasi Peserta</h5>
                </div>
                <div class="card-body">
                    <table class="table table-borderless">
                        <tr>
                            <th width="30%">Nomor Peserta</th>
                            <td>{{ $participant->no_peserta }}</td>
                        </tr>
                        <tr>
                            <th>Nama Lengkap</th>
                            <td>{{ $participant->nama }}</td>
                        </tr>
                        <tr>
                            <th>NIK</th>
                            <td>{{ $participant->nik }}</td>
                        </tr>
                        <tr>
                            <th>NISN</th>
                            <td>{{ $participant->nisn }}</td>
                        </tr>
                        <tr>
                            <th>NIS</th>
                            <td>{{ $participant->nis ?? '-' }}</td>
                        </tr>
                        <tr>
                            <th>Jenjang</th>
                            <td>
                                <span class="badge bg-primary">{{ $participant->jenjang }}</span>
                            </td>
                        </tr>
                        <tr>
                            <th>Kelas</th>
                            <td>{{ $participant->kelas }}</td>
                        </tr>
                        <tr>
                            <th>Tempat Lahir</th>
                            <td>{{ $participant->tempat_lahir }}</td>
                        </tr>
                        <tr>
                            <th>Tanggal Lahir</th>
                            <td>{{ $participant->tanggal_lahir->format('d F Y') }} ({{ $participant->age }} tahun)</td>
                        </tr>
                        <tr>
                            <th>Nama Ibu</th>
                            <td>{{ $participant->nama_ibu }}</td>
                        </tr>
                        <tr>
                            <th>Jenis Ketunaan</th>
                            <td>
                                <strong>{{ $participant->disabilityType->name }}</strong> ({{ $participant->disabilityType->code }})
                                @if ($participant->disabilityType->description)
                                    <br>
                                    <small class="text-muted">{{ $participant->disabilityType->description }}</small>
                                @endif
                            </td>
                        </tr>
                        <tr>
                            <th>Sekolah</th>
                            <td>{{ $participant->school->name }}</td>
                        </tr>
                        <tr>
                            <th>Status Data</th>
                            <td>
                                @if ($participant->is_locked)
                                    <span class="badge bg-success">
                                        <i class="bi bi-lock-fill me-1"></i>Final (Terkunci)
                                    </span>
                                @else
                                    <span class="badge bg-warning">
                                        <i class="bi bi-pencil me-1"></i>Draft (Masih Bisa Diedit)
                                    </span>
                                @endif
                            </td>
                        </tr>
                        @if ($participant->is_locked && $participant->submitted_at)
                        <tr>
                            <th>Difinalisasi Pada</th>
                            <td>{{ $participant->submitted_at->format('d F Y H:i') }}</td>
                        </tr>
                        @endif
                        <tr>
                            <th>Didaftarkan</th>
                            <td>{{ $participant->created_at->format('d F Y H:i') }}</td>
                        </tr>
                        <tr>
                            <th>Terakhir Diupdate</th>
                            <td>{{ $participant->updated_at->format('d F Y H:i') }}</td>
                        </tr>
                    </table>
                </div>
            </div>
        </div>
    </div>

    <div class="mt-3">
        <a href="{{ route('admin-dinas.psaj.index') }}" class="btn btn-secondary">
            <i class="bi bi-arrow-left me-2"></i>Kembali ke Daftar
        </a>
    </div>
</div>
@endsection
