@extends('layouts.admin')

@section('title', 'Edit Data Siswa')
@section('subtitle', 'Perbarui data: ' . $student->name)

@section('content')

<div class="row g-3 justify-content-center">
    <div class="col-12 col-lg-6">
        <div class="panel">
            <div class="panel-head">
                <h3>Edit Data Siswa</h3>
                <a href="{{ route('admin.students.index') }}" class="btn-soft-secondary" style="width:auto;padding:0 12px;font-size:.8rem;">
                    <i class="fa-solid fa-arrow-left me-1"></i> Kembali
                </a>
            </div>
            <div class="panel-body">
                <form action="{{ route('admin.students.update', $student->id) }}" method="POST">
                    @csrf @method('PUT')
                    <div class="mb-3">
                        <label class="form-label">NIS</label>
                        <input type="text" name="nis" class="form-control" value="{{ old('nis', $student->nis) }}" required>
                    </div>
                    <div class="mb-3">
                        <label class="form-label">Nama Lengkap</label>
                        <input type="text" name="name" class="form-control" value="{{ old('name', $student->name) }}" required>
                    </div>
                    <div class="mb-3">
                        <label class="form-label">Jenis Kelamin</label>
                        <select name="gender" class="form-select" required>
                            <option value="L" {{ $student->gender === 'L' ? 'selected' : '' }}>Laki-laki</option>
                            <option value="P" {{ $student->gender === 'P' ? 'selected' : '' }}>Perempuan</option>
                        </select>
                    </div>
                    <div class="mb-3">
                        <label class="form-label">Kelas</label>
                        <select name="class" class="form-select" required>
                            @foreach($classes as $kelas)
                                <option value="{{ $kelas->name }}" {{ $student->class === $kelas->name ? 'selected' : '' }}>
                                    Kelas {{ $kelas->name }}
                                </option>
                            @endforeach
                        </select>
                    </div>
                    <div class="mb-3">
                        <label class="form-label">Alamat <span class="text-muted">(opsional)</span></label>
                        <textarea name="address" class="form-control" rows="2">{{ old('address', $student->address) }}</textarea>
                    </div>
                    <div class="d-flex gap-2">
                        <button type="submit" class="btn btn-brand">
                            <i class="fa-solid fa-floppy-disk me-1"></i> Simpan Perubahan
                        </button>
                        <a href="{{ route('admin.students.index') }}" class="btn btn-secondary">Batal</a>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

@endsection
