<x-app-layout>
    @section('page-title', $pageTitle)
    <div class="d-flex align-items-center mb-4">
        <a href="{{ route('admin.pengumuman.index') }}" class="btn btn-outline-secondary me-3">
            <i class="bi bi-arrow-left"></i>
        </a>
        <h3 class="my-0 fw-bold">Formulir Tambah Pengumuman</h3>
    </div>

    <div class="row justify-content-center">
        <div class="col-md-10">
            <div class="card border-0 shadow-sm">
                <div class="card-body p-4">
                    <div class="card-body">
                        <form action="#" method="POST" id="formTambahPengumuman">
                            <div class="mb-3">
                                <label for="judul" class="form-label">Judul Pengumuman</label>
                                <input type="text" class="form-control" id="judul"
                                    placeholder="Masukkan judul pengumuman" required>
                            </div>
                            <div class="mb-3">
                                <label for="tipe" class="form-label">Tipe Pengumuman</label>
                                <select class="form-select" id="tipe" required>
                                    <option value="" selected disabled>Pilih tipe...</option>
                                    <option value="info">Info</option>
                                    <option value="success">Success</option>
                                    <option value="warning">Warning</option>
                                    <option value="danger">Danger</option>
                                    <option value="secondary">Secondary</option>
                                </select>
                            </div>
                            <div class="mb-3">
                                <label for="content" class="form-label">Isi Pengumuman</label>
                                <textarea class="form-control" id="content" rows="5" placeholder="Tulis isi pengumuman di sini..." required></textarea>
                            </div>
                            <hr>
                            <div class="d-flex justify-content-end">
                                <button type="submit" class="btn btn-primary">Simpan Pengumuman</button>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>

    @push('scripts')
    <script>
        document.getElementById('formTambahPengumuman').addEventListener('submit', function(e) {
            e.preventDefault(); 
            
            modernSwal.fire({
                title: 'Menyimpan...',
                timer: 800,
                didOpen: () => Swal.showLoading()
            }).then(() => {
                Toast.fire({
                    icon: 'success',
                    title: 'Berhasil',
                    text: 'Pengumuman baru berhasil ditambahkan.'
                });
                
                setTimeout(() => {
                    window.location.href = "{{ route('admin.pengumuman.index') }}";
                }, 1500);
            });
        });
    </script>
    @endpush
</x-app-layout>