@extends('layouts.app')

@section('title', 'Edit Tahun Ajaran')

@section('content')
<div class="container-fluid">
    <!-- Page Header -->
    <div class="mb-4">
        <div class="d-flex align-items-center mb-2">
            <a href="{{ route('superadmin.academic-years.index') }}" class="btn btn-outline-secondary btn-sm me-3">
                <i class="bi bi-arrow-left"></i>
            </a>
            <div>
                <h4 class="mb-0">
                    <i class="bi bi-pencil text-primary me-2"></i>
                    Edit Tahun Ajaran
                </h4>
                <p class="text-muted mb-0 small">Perbarui informasi tahun ajaran {{ $academicYear->name }}</p>
            </div>
        </div>
    </div>

    @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

    <div class="row">
        <div class="col-lg-8">
            <div class="card border-0 shadow-sm">
                <div class="card-header bg-primary text-white py-3">
                    <h5 class="mb-0">
                        <i class="bi bi-calendar-range me-2"></i>
                        Informasi Tahun Ajaran
                    </h5>
                </div>
                <div class="card-body p-4">
                    <form action="{{ route('superadmin.academic-years.update', $academicYear->id) }}" method="POST">
                        @csrf
                        @method('PUT')

                        @if($academicYear->is_active)
                        <div class="alert alert-success" role="alert">
                            <i class="bi bi-check-circle-fill me-2"></i>
                            Tahun ajaran ini sedang <strong>aktif</strong>
                        </div>
                        @endif

                        <div class="mb-4">
                            <label class="form-label fw-bold">
                                <i class="bi bi-calendar-event text-muted me-1"></i>
                                Nama Tahun Ajaran <span class="text-danger">*</span>
                            </label>
                            <input type="text" name="name" class="form-control @error('name') is-invalid @enderror" 
                                value="{{ old('name', $academicYear->name) }}" placeholder="Contoh: 2025/2026" required>
                            @error('name')
                            <div class="invalid-feedback">{{ $message }}</div>
                            @enderror
                            <small class="text-muted">Format: YYYY/YYYY</small>
                        </div>

                        <div class="row mb-4">
                            <div class="col-md-6">
                                <label class="form-label fw-bold">
                                    <i class="bi bi-calendar-check text-muted me-1"></i>
                                    Tanggal Mulai <span class="text-danger">*</span>
                                </label>
                                <input type="date" name="start_date" class="form-control @error('start_date') is-invalid @enderror" 
                                    value="{{ old('start_date', $academicYear->start_date->format('Y-m-d')) }}" required>
                                @error('start_date')
                                <div class="invalid-feedback">{{ $message }}</div>
                                @enderror
                            </div>
                            <div class="col-md-6">
                                <label class="form-label fw-bold">
                                    <i class="bi bi-calendar-x text-muted me-1"></i>
                                    Tanggal Selesai <span class="text-danger">*</span>
                                </label>
                                <input type="date" name="end_date" class="form-control @error('end_date') is-invalid @enderror" 
                                    value="{{ old('end_date', $academicYear->end_date->format('Y-m-d')) }}" required>
                                @error('end_date')
                                <div class="invalid-feedback">{{ $message }}</div>
                                @enderror
                            </div>
                        </div>

                        <div class="mb-4">
                            <label class="form-label fw-bold">
                                <i class="bi bi-journal-text text-muted me-1"></i>
                                Keterangan
                            </label>
                            <textarea name="description" class="form-control @error('description') is-invalid @enderror" 
                                rows="3" placeholder="Keterangan tambahan (opsional)">{{ old('description', $academicYear->description) }}</textarea>
                            @error('description')
                            <div class="invalid-feedback">{{ $message }}</div>
                            @enderror
                        </div>

                        <div class="border-top pt-4 mt-4">
                            <div class="d-flex justify-content-between">
                                <a href="{{ route('superadmin.academic-years.index') }}" class="btn btn-secondary">
                                    <i class="bi bi-x-circle me-1"></i>
                                    Batal
                                </a>
                                <button type="submit" class="btn btn-primary">
                                    <i class="bi bi-save me-1"></i>
                                    Simpan Perubahan
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>

        <div class="col-lg-4">
            <div class="card border-0 border-start border-warning border-4 bg-light">
                <div class="card-body">
                    <h6 class="text-warning mb-3">
                        <i class="bi bi-exclamation-triangle-fill me-1"></i>Perhatian
                    </h6>
                    <ul class="small text-muted mb-0">
                        <li class="mb-2">Perubahan nama tahun ajaran akan mempengaruhi tampilan di seluruh sistem</li>
                        <li class="mb-2">Pastikan periode tanggal sudah sesuai</li>
                        <li class="mb-2">Status keaktifan tidak dapat diubah dari halaman ini</li>
                        <li class="mb-2">Gunakan tombol "Aktifkan" di halaman daftar untuk mengaktifkan tahun ajaran</li>
                    </ul>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection
