@extends('layouts.app')

@section('content')
<div class="page-header">
    <h4><i class="bi bi-pencil-square me-2" style="color:#ca8a04;"></i>Edit Data Siswa</h4>
    <p>Ubah informasi siswa pada formulir di bawah ini sesuai data terbaru.</p>
</div>

<div class="card card-table p-4" style="border-radius: 14px; border: none; box-shadow: 0 2px 12px rgba(0, 0, 0, 0.07);">

    {{-- Notifikasi Error Validasi --}}
    @if($errors->any())
    <div class="alert alert-danger py-2" style="border-radius: 8px; font-size: 0.875rem;">
        <ul class="mb-0 ps-3">
            @foreach($errors->all() as $error)
            <li>{{ $error }}</li>
            @endforeach
        </ul>
    </div>
    @endif

    {{-- Form Edit Data --}}
    <form action="{{ route('siswa.update', $siswa->id) }}" method="POST">
        @csrf
        @method('PUT') {{-- Wajib di Laravel untuk proses Update/PUT --}}

        <div class="row g-3">
            {{-- Input NISN --}}
            <div class="col-md-6">
                <label for="nisn" class="form-label small fw-semibold text-secondary">NISN</label>
                <input type="text" name="nisn" id="nisn" class="form-control" value="{{ old('nisn', $siswa->nisn) }}"
                    placeholder="Contoh: 0012345678" required>
            </div>

            {{-- Input Nama Lengkap --}}
            <div class="col-md-6">
                <label for="nama" class="form-label small fw-semibold text-secondary">Nama Lengkap</label>
                <input type="text" name="nama" id="nama" class="form-control" value="{{ old('nama', $siswa->nama) }}"
                    placeholder="Masukkan nama lengkap" required>
            </div>

            {{-- Input Kelas --}}
            <div class="col-md-6">
                <label for="kelas" class="form-label small fw-semibold text-secondary">Kelas</label>
                <input type="text" name="kelas" id="kelas" class="form-control"
                    value="{{ old('kelas', $siswa->kelas) }}" placeholder="Contoh: XII-RPL-1" required>
            </div>

            {{-- Input Jenis Kelamin --}}
            <div class="col-md-6">
                <label for="jenis_kelamin" class="form-label small fw-semibold text-secondary">Jenis Kelamin</label>
                <select name="jenis_kelamin" id="jenis_kelamin" class="form-select" required>
                    <option value="Laki-laki" {{ old('jenis_kelamin', $siswa->jenis_kelamin) == 'Laki-laki' ? 'selected'
                        : '' }}>Laki-laki</option>
                    <option value="Perempuan" {{ old('jenis_kelamin', $siswa->jenis_kelamin) == 'Perempuan' ? 'selected'
                        : '' }}>Perempuan</option>
                </select>
            </div>

            {{-- Input Alamat Rumah --}}
            <div class="col-12">
                <label for="alamat" class="form-label small fw-semibold text-secondary">Alamat Rumah Lengkap</label>
                <textarea name="alamat" id="alamat" class="form-control" rows="3"
                    placeholder="Masukkan alamat tempat tinggal..."
                    required>{{ old('alamat', $siswa->alamat) }}</textarea>
            </div>
        </div>

        {{-- Tombol Aksi --}}
        <div class="mt-4 pt-3 border-top d-flex gap-2">
            <button type="submit" class="btn btn-warning text-dark fw-bold d-flex align-items-center gap-2"
                style="border-radius: 8px;">
                <i class="bi bi-check-circle"></i> Perbarui Data
            </button>
            <a href="{{ route('siswa.index') }}" class="btn btn-light border" style="border-radius: 8px;">Batal</a>
        </div>
    </form>
</div>
@endsection