@extends('adminlte.layouts.app')

@section('content')
<div class="content-wrapper">

    {{-- HEADER --}}
    <div class="content-header">
        <div class="container-fluid">
            <div class="row mb-3">
                <div class="col-sm-6">
                    <h1 class="m-0 fw-bold text-gradient-warning">
                        <i class="fas fa-user-edit me-2"></i>Edit Siswa
                    </h1>
                </div>
                <div class="col-sm-6">
                    <ol class="breadcrumb float-sm-right">
                        <li class="breadcrumb-item">
                            <a href="{{ route('siswa.index') }}">Siswa</a>
                        </li>
                        <li class="breadcrumb-item active">Edit</li>
                    </ol>
                </div>
            </div>
        </div>
    </div>

    {{-- CONTENT --}}
    <section class="content">
        <div class="container-fluid">

            <div class="card shadow-xl rounded-3 border-0">
                <div class="card-header bg-gradient-warning text-white py-3 px-4">
                    <h3 class="card-title m-0 fw-semibold">
                        <i class="fas fa-user-graduate me-1"></i> Form Edit Data Siswa
                    </h3>
                </div>

                <div class="card-body px-4 py-4">

                    {{-- ERROR VALIDASI --}}
                    @if ($errors->any())
                        <div class="alert alert-danger shadow-sm">
                            <ul class="mb-0">
                                @foreach ($errors->all() as $error)
                                    <li>{{ $error }}</li>
                                @endforeach
                            </ul>
                        </div>
                    @endif

                    <form id="formEditSiswa"
                          action="{{ route('siswa.update', $siswa->id) }}"
                          method="POST">
                        @csrf
                        @method('PUT')

                        <div class="row">
                            <div class="col-md-6 mb-3">
                                <label class="form-label fw-semibold">NIS</label>
                                <input type="text" name="nis"
                                    class="form-control shadow-sm @error('nis') is-invalid @enderror"
                                    value="{{ old('nis', $siswa->nis) }}">
                                @error('nis')
                                    <div class="invalid-feedback">{{ $message }}</div>
                                @enderror
                            </div>

                            <div class="col-md-6 mb-3">
                                <label class="form-label fw-semibold">Nama Siswa</label>
                                <input type="text" name="nama"
                                    class="form-control shadow-sm @error('nama') is-invalid @enderror"
                                    value="{{ old('nama', $siswa->nama) }}">
                                @error('nama')
                                    <div class="invalid-feedback">{{ $message }}</div>
                                @enderror
                            </div>

                            <div class="col-md-6 mb-3">
                                <label class="form-label fw-semibold">Kelas</label>
                                <input type="text" name="kelas"
                                    class="form-control shadow-sm @error('kelas') is-invalid @enderror"
                                    value="{{ old('kelas', $siswa->kelas) }}">
                                @error('kelas')
                                    <div class="invalid-feedback">{{ $message }}</div>
                                @enderror
                            </div>

                            <div class="col-md-6 mb-3">
                                <label class="form-label fw-semibold">No HP</label>
                                <input type="text" name="no_hp"
                                    class="form-control shadow-sm @error('no_hp') is-invalid @enderror"
                                    value="{{ old('no_hp', $siswa->no_hp) }}">
                                @error('no_hp')
                                    <div class="invalid-feedback">{{ $message }}</div>
                                @enderror
                            </div>

                            <div class="col-md-12 mb-3">
                                <label class="form-label fw-semibold">Alamat</label>
                                <textarea name="alamat" rows="3"
                                    class="form-control shadow-sm @error('alamat') is-invalid @enderror">{{ old('alamat', $siswa->alamat) }}</textarea>
                                @error('alamat')
                                    <div class="invalid-feedback">{{ $message }}</div>
                                @enderror
                            </div>
                        </div>

                        <div class="d-flex justify-content-between mt-4">
                            <a href="{{ route('siswa.index') }}"
                                class="btn btn-secondary shadow-sm hover-scale">
                                <i class="fas fa-arrow-left me-1"></i> Kembali
                            </a>

                            <button type="submit"
                                class="btn btn-warning shadow-sm hover-scale">
                                <i class="fas fa-sync-alt me-1"></i> Update
                            </button>
                        </div>
                    </form>

                </div>
            </div>

        </div>
    </section>
</div>

{{-- SWEETALERT --}}
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>

<script>
document.getElementById('formEditSiswa').addEventListener('submit', function (e) {
    e.preventDefault();

    Swal.fire({
        title: 'Update Data Siswa?',
        text: 'Perubahan data akan disimpan',
        icon: 'warning',
        showCancelButton: true,
        confirmButtonText: 'Update',
        cancelButtonText: 'Batal'
    }).then((result) => {
        if (result.isConfirmed) {
            this.submit();
        }
    });
});
</script>

<style>
.text-gradient-warning {
    background: linear-gradient(90deg, #f7971e, #ffd200);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}
.hover-scale {
    transition: 0.2s;
}
.hover-scale:hover {
    transform: translateY(-2px) scale(1.02);
    box-shadow: 0 8px 20px rgba(0,0,0,0.15);
}
</style>
@endsection
