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

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>Rekap Pelanggaran | Tatib 5</title>

    <link rel="icon" type="image/png" href="<?= base_url('logo.png') ?>">

    <!-- 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;
        }

        /* HEADER */

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

        .btn-back {
            color: white;
            text-decoration: none;
            font-weight: 600;
        }

        .btn-back:hover {
            color: #FFD54F;
        }

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

        .logo-header {
            width: 60px;
        }

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

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

        /* CARD */

        .login-card {
            max-width: 450px;
            margin: 70px auto;
            border: none;
            border-radius: 20px;
            overflow: hidden;
            box-shadow: 0 10px 25px rgba(0, 0, 0, .08);
        }

        .card-header {
            background: #2563EB;
            color: white;
            text-align: center;
            font-size: 22px;
            font-weight: 600;
            padding: 18px;
        }

        .card-body {
            padding: 35px;
        }

        label {
            font-weight: 600;
            margin-bottom: 8px;
        }

        .form-control {
            height: 48px;
            border-radius: 12px;
        }

        .btn-login {
            width: 100%;
            background: #2563EB;
            color: white;
            border: none;
            border-radius: 12px;
            padding: 12px;
            font-weight: 600;
            transition: .3s;
        }

        .btn-login:hover {
            background: #1E40AF;
        }

        .back-home {
            display: block;
            text-align: center;
            margin-top: 20px;
            text-decoration: none;
            color: #2563EB;
            font-weight: 600;
        }

        .back-home:hover {
            color: #1E3A8A;
        }

        footer {
            margin-top: 80px;
            background: #FFD54F;
            padding: 20px 30px;
            color: #1E3A8A;
        }

        footer h5 {
            color: #1E3A8A;
            font-weight: 700;
            margin-bottom: 5px;
        }

        footer small {
            color: #1E3A8A;
            font-weight: 600;
            line-height: 1.7;
        }

        .footer-link {
            color: #1E3A8A;
            text-decoration: none;
            font-weight: 700;
            margin-left: 25px;
        }

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

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

</head>

<body>

    <!-- HEADER -->

    <div class="top-header">

        <a href="<?= base_url('PilihKelas') ?>" 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 my-4">

        <div class="card shadow border-0 rounded-4">

            <div class="card-header bg-primary text-white text-center py-3">

                <h3 class="mb-0">
                    <i class="fa-solid fa-chart-column me-2"></i>
                    Halaman Rekap Pelanggaran dan Penghargaan
                </h3>

            </div>

            <div class="card-body">

                <!-- Informasi Kelas -->

                <div class="row mb-4">

                    <div class="col-md-6">

                        <table class="table table-borderless">

                            <tr>
                                <td width="180"><b>Kelas</b></td>
                                <td>: <?= $kelas['nama_kelas']; ?></td>
                            </tr>

                            <tr>
                                <td><b>Wali Kelas</b></td>
                                <td>: <?= $walikelas['nama']; ?></td>
                            </tr>
                            <tr>
                                <td><b>Tahun Ajaran</b></td>
                                <td>: <?= $tahunajaran; ?></td>
                            </tr>

                        </table>

                    </div>

                    <div class="col-md-6">

                        <table class="table table-borderless">

                            <tr>
                                <td width="180"><b>Guru BK</b></td>
                                <td>:
                                    <?php
                                    $bk = [];
                                    foreach ($gurubk as $g) {
                                        $bk[] = $g['nama'];
                                    }
                                    echo implode(', <br> ', $bk);
                                    ?>
                                </td>
                            </tr>



                        </table>

                    </div>

                </div>

                <!-- Button -->

                <div class="mb-4 text-center">

                    <a href="<?= base_url('RekapPelanggaran/exportSkorPdf/' . $kelas['id_kelas']) ?>"
                        class="btn btn-success me-2">
                        <i class="fa-solid fa-file-pdf"></i>
                        Unduh Rekap Skor Seluruh Murid
                    </a>

                    <a href="<?= base_url('RekapPelanggaran/exportPelanggaranPdf/' . $kelas['id_kelas']) ?>"
                        class="btn btn-danger">
                        <i class="fa-solid fa-file-pdf"></i>
                        Unduh Rekap Pelanggaran Tercatat
                    </a>
                    <a href="<?= base_url('RekapPelanggaran/exportPenghargaanPdf/' . $kelas['id_kelas']) ?>"
                        class="btn btn-info">
                        <i class="fa-solid fa-file-pdf"></i>
                        Unduh Rekap Penghargaan Tercatat
                    </a>
                </div>

                <!-- Rekap Murid -->

                <div class="card mb-4">

                    <div class="card-header bg-warning">

                        <b>
                            <i class="fa-solid fa-users"></i>
                            Rekap Skor Murid
                        </b>

                    </div>

                    <div class="card-body p-0">

                        <table class="table table-hover table-bordered mb-0">

                            <thead class="table-light">

                                <tr>

                                    <th width="60" style="text-align: center;">No</th>
                                    <th width="150" style="text-align: center;">NIS</th>
                                    <th style="text-align: center;">Nama Murid</th>
                                    <th width="100" style="text-align: center;">Skor Pelanggaran</th>
                                    <th width="100" style="text-align: center;">Skor Penghargaan</th>
                                    <th width="90" style="text-align: center;">Detail</th>

                                </tr>

                            </thead>

                            <tbody>

                                <?php
                                $no = 1;
                                foreach ($siswa as $row):
                                ?>

                                    <tr>

                                        <td><?= $no++; ?></td>
                                        <td><?= $row['nis']; ?></td>
                                        <td><?= $row['nama']; ?></td>
                                        <td class="text-center">

                                            <?php

                                            if ($row['skor'] >= 50) {

                                                $warna = 'danger';
                                            } elseif ($row['skor'] >= 25) {

                                                $warna = 'warning text-dark';
                                            } else {

                                                $warna = 'success';
                                            }

                                            ?>

                                            <span class="badge bg-<?= $warna; ?>">

                                                <?= $row['skor']; ?>

                                            </span>

                                        </td>
                                        <td class="text-center">
                                            <?php
                                            if ($row['poin_penghargaan'] >= 50) {
                                                $warnaPrestasi = 'primary';
                                            } elseif ($row['poin_penghargaan'] >= 25) {
                                                $warnaPrestasi = 'info';
                                            } elseif ($row['poin_penghargaan'] > 0) {
                                                $warnaPrestasi = 'success';
                                            } else {
                                                $warnaPrestasi = 'secondary';
                                            }
                                            ?>
                                            <span class="badge bg-<?= $warnaPrestasi ?>">
                                                <?= $row['poin_penghargaan']; ?>
                                            </span>
                                        </td>
                                        <td class="text-center">
                                            <a href="<?= base_url('RekapPelanggaranPermurid/' . $row['id_siswa']); ?>"
                                                class="btn btn-primary btn-sm">
                                                <i class="fa-solid fa-eye"></i>
                                            </a>
                                        </td>
                                    </tr>
                                <?php endforeach; ?>
                            </tbody>
                        </table>
                    </div>
                </div>

                <!-- Pelanggaran -->

                <div class="card">

                    <div class="card-header bg-info text-white">

                        <b>

                            <i class="fa-solid fa-triangle-exclamation"></i>

                            Pelanggaran Tercatat

                        </b>

                    </div>

                    <div class="card-body p-0">

                        <table class="table table-striped table-bordered mb-0">

                            <thead class="table-light">
                                <tr>
                                    <th width="60">No</th>
                                    <th>Tanggal</th>
                                    <th>Nama Murid</th>
                                    <th>Jenis Pelanggaran</th>
                                    <th width="200">Keterangan</th>
                                    <th>Guru Pencatat</th>
                                    <th width="50">Skor</th>
                                </tr>
                            </thead>

                            <tbody>

                                <?php
                                $no = 1;
                                foreach ($pelanggaran as $row):
                                ?>

                                    <tr>

                                        <td><?= $no++; ?></td>
                                        <td><?= $row['tanggal']; ?></td>
                                        <td><?= $row['nama_siswa']; ?></td>
                                        <td><?= $row['nama_pelanggaran']; ?></td>
                                        <td><?= $row['keterangan_tambahan']; ?></td>
                                        <td><?= $row['nama_guru']; ?></td>
                                        <td class="text-center">

                                            <span class="badge bg-danger">

                                                <?= $row['skor']; ?>

                                            </span>

                                        </td>

                                    </tr>

                                <?php endforeach; ?>

                            </tbody>

                        </table>

                    </div>

                </div>

                <div class="card mt-4 shadow">

                    <div class="card-header bg-success text-white">

                        <i class="fa-solid fa-award"></i>

                        Penghargaan Tercatat

                    </div>

                    <div class="card-body p-0">

                        <table class="table table-bordered table-hover mb-0">

                            <thead class="table-light">

                                <tr>

                                    <th width="60" class="text-center">No</th>
                                    <th width="140">Tanggal</th>
                                    <th>Nama Murid</th>
                                    <th>Penghargaan</th>
                                    <th>Keterangan</th>
                                    <th width="180">Guru Pencatat</th>
                                    <th width="120" class="text-center">Skor</th>
                                </tr>

                            </thead>

                            <tbody>

                                <?php $no = 1; ?>

                                <?php foreach ($penghargaan as $row): ?>

                                    <tr>

                                        <td class="text-center">
                                            <?= $no++ ?>
                                        </td>
                                        <td>

                                            <?= date('d-m-Y', strtotime($row['tanggal'])) ?>

                                        </td>
                                        <td>
                                            <?= $row['nama_siswa'] ?>
                                        </td>

                                        <td>
                                            <?= $row['nama_penghargaan'] ?>
                                        </td>
                                        <td>
                                            <?= $row['keterangan_tambahan'] ?>
                                        </td>
                                        <td>
                                            <?= $row['nama_guru'] ?>
                                        </td>
                                        <td class="text-center">

                                            <span class="badge bg-success fs-6">

                                                +<?= $row['poin'] ?>

                                            </span>

                                        </td>
                                    </tr>

                                <?php endforeach; ?>

                            </tbody>

                        </table>

                    </div>

                </div>
            </div>
        </div>
    </div>
    <footer>

        <div class="container">

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

                <div class="col-md-6">

                    <h5>SMP Negeri 5 Bandung</h5>

                    <small>

                        Jl. Sumatra No.40 Bandung<br>

                        Sistem Informasi Tata Tertib © 2026

                    </small>

                </div>

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

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

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

                        @bdg.smpn5

                    </a>

                    <a href="#" class="footer-link">

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

                        SMP Negeri 5 Bandung

                    </a>

                </div>

            </div>

        </div>

    </footer>
</body>

</html>