<!DOCTYPE html>
<html lang="id">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="icon" type="image/png" href="<?= base_url('logo.png') ?>">
    <title>Input Pelanggaran | Tatib 5</title>

    <!-- Bootstrap -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">

    <!-- Font Awesome -->
    <link rel="stylesheet"
        href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.7.2/css/all.min.css">

    <!-- Google Font -->
    <link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap"
        rel="stylesheet">

    <style>
        body {
            font-family: 'Poppins', sans-serif;
            background: #f5f7fb;
        }

        .top-header {
            background: linear-gradient(135deg, #1d4ed8, rgb(47, 161, 210));
            color: #fff;
            padding: 15px 25px;
            margin-bottom: 25px;
            display: flex;
            justify-content: space-between;
            align-items: center;
            box-shadow: 0 10px 25px rgba(37, 99, 235, .25);
        }

        .btn-back {
            color: #fff;
            text-decoration: none;
            font-weight: 600;
            padding: 10px 18px;
            border-radius: 12px;
            transition: .3s;
        }

        .btn-back:hover {
            background: rgba(255, 255, 255, .15);
            color: #FFD54F;
        }

        .header-title {
            display: flex;
            align-items: center;
            gap: 12px;
        }

        .logo-header {
            width: 60px;
            height: 60px;
        }

        .header-title h4 {
            margin: 0;
            font-size: 22px;
            font-weight: 700;
        }

        .header-title small {
            opacity: .9;
        }

        .card {
            border: none;
            border-radius: 20px;
            box-shadow: 0 8px 20px rgba(0, 0, 0, .08);
            margin-bottom: 50px;
        }

        .card-header {
            background: #1d4ed8;
            color: white;
            border-radius: 20px 20px 0 0 !important;
            font-size: 20px;
            font-weight: 600;
        }

        .form-control,
        .form-select {
            border-radius: 12px;
        }

        .btn {
            border-radius: 12px;
        }

        .btn-primary {
            background: #2563EB;
        }

        .btn-warning {
            color: white;
        }

        .profile-card {
            background: white;
            border-radius: 20px;
            padding: 20px;
            text-align: center;
            box-shadow: 0 8px 20px rgba(0, 0, 0, .08);
        }

        .profile-card i {
            font-size: 80px;
            color: #2563EB;
        }

        .badge {
            font-size: 14px;
        }

        .footer {
            background: #FFD54F;
            padding: 20px 30px;
            margin-top: 60px;
            color: #1E3A8A;
            font-size: 15px;
            font-weight: 500;
        }

        .footer h5 {
            font-weight: 700;
            margin-bottom: 5px;
        }

        .footer-link {
            color: #1E3A8A;
            text-decoration: none;
            font-weight: 600;
            transition: .3s;
        }

        .footer-link i {
            margin-right: 6px;
            font-size: 18px;
        }

        .footer-link:hover {
            color: #0f172a;
        }
    </style>

</head>

<body>
    <div class="top-header">

        <a href="<?= base_url('token/logout') ?>" class="btn-back">
            <i class="fa-solid fa-arrow-left"></i>
            Kembali
        </a>

        <div class="header-title">

            <img src="<?= base_url('logo.png') ?>" class="logo-header">

            <div>
                <h4>TIM TATIB 5</h4>
                <small>SMP Negeri 5 Bandung</small>
            </div>

        </div>

    </div>

    <div class="container mt-5">
        <div class="row justify-content-center">
            <div class="col-lg-12">
                <div class="card">
                    <div class="card-header text-center">
                        <i class="fa-solid fa-clipboard-list me-2"></i>
                        Input Pelanggaran Murid
                    </div>
                    <div class="card-body">
                        <form action="<?= base_url('InputPelanggaran/simpan') ?>" method="post">

                            <!-- Kelas -->
                            <label class="fw-semibold">Pilih Kelas</label>
                            <select
                                name="id_kelas"
                                id="id_kelas"
                                class="form-select">
                                <option value="">Pilih Kelas</option>
                                <?php foreach ($kelas as $k): ?>
                                    <option value="<?= $k['id_kelas'] ?>">
                                        <?= $k['nama_kelas'] ?>
                                    </option>
                                <?php endforeach; ?>
                            </select>
                            <br>
                            <!-- Nama Murid -->
                            <label class="fw-semibold">Pilih Murid</label>
                            <select
                                name="id_siswa"
                                id="id_siswa"
                                class="form-select">
                                <option value="">Pilih Murid</option>
                            </select><br>

                            <!-- Tanggal & Guru -->
                            <label class="fw-semibold">Pilih Tanggal</label>
                            <input
                                type="date"
                                name="tanggal"
                                class="form-control"
                                value="<?= date('Y-m-d') ?>"
                                required><br>


                            <!-- Jenis Pelanggaran -->
                            <label class="fw-semibold">Pilih Pelanggaran</label>
                            <select
                                name="id_pelanggaran"
                                class="form-select"
                                required>

                                <option value="">-- Pilih Pelanggaran --</option>

                                <?php foreach ($pelanggaran as $p): ?>

                                    <option
                                        value="<?= $p['id_pelanggaran'] ?>">
                                        <?= $p['nama_pelanggaran'] ?>
                                        (<?= $p['skor'] ?> poin)
                                    </option>
                                <?php endforeach; ?>
                            </select>
                            <br>
                            <div class="mb-3">
                                <label class="fw-semibold">Guru Penginput</label>
                                <select name="id_guru" class="form-select" required>
                                    <option value="">-- Pilih Guru --</option>
                                    <?php foreach ($guru as $g): ?>
                                        <option value="<?= $g['id_guru']; ?>">
                                            <?= $g['nama']; ?>
                                        </option>
                                    <?php endforeach; ?>
                                </select>
                            </div>
                            <!-- Keterangan -->

                            <label class="fw-semibold">Keterangan Tambahan</label>
                            <textarea
                                name="keterangan_tambahan"
                                class="form-control"
                                rows="3"></textarea>
                            <br>
                            <!-- Tombol -->
                            <div class="text-end">
                                <button type="reset" class="btn btn-secondary">
                                    <i class="fa-solid fa-rotate-left"></i> Reset
                                </button>
                                <button type="submit" class="btn btn-primary">
                                    <i class="fa-solid fa-floppy-disk"></i> Simpan
                                </button>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <footer class="footer mt-5">

        <div class="container">

            <div class="row align-items-center">

                <!-- Kiri -->
                <div class="col-md-6 text-md-start text-center mb-3 mb-md-0">

                    <h5 class="mb-1">
                        SMP Negeri 5 Bandung
                    </h5>

                    <small>
                        Jl. Sumatra No. 40, Bandung <br>
                        Sistem Informasi Tata Tertib © 2026
                    </small>

                </div>

                <!-- Kanan -->
                <div class="col-md-6 text-md-end text-center">

                    <a href="https://instagram.com/bdg.smpn5" class="footer-link me-4" target="_blank">

                        <i class="fab fa-instagram"></i>

                        @bdg.smpn5

                    </a>

                    <a href="https://youtube.com/" class="footer-link" target="_blank">

                        <i class="fab fa-youtube"></i>

                        SMP Negeri 5 Bandung

                    </a>

                </div>

            </div>

        </div>

    </footer>

    <script>
        document.getElementById('id_kelas').addEventListener('change', function() {

            let id = this.value;

            fetch("<?= base_url('InputPelanggaran/getSiswa/') ?>" + id)

                .then(response => response.json())

                .then(data => {

                    let siswa = document.getElementById('id_siswa');

                    siswa.innerHTML = '<option value="">-- Pilih Murid --</option>';

                    data.forEach(function(item) {

                        siswa.innerHTML +=
                            `<option value="${item.id_siswa}">
                ${item.nama}
            </option>`;

                    });

                });

        });
    </script>
    <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
    <?php if (session()->getFlashdata('success')) : ?>

        <script>
            Swal.fire({
                icon: 'success',
                title: 'Berhasil!',
                text: '<?= session()->getFlashdata('success'); ?>',
                confirmButtonColor: '#16a34a',
                confirmButtonText: 'OK'
            });
        </script>

    <?php endif; ?>
</body>

</html>