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

<head>
    <meta charset="UTF-8">
    <title>SKL_<?= $siswa->nama ?></title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 0px;
            padding: 0;
            font-size: 12px;
        }

        .container {
            width: 90%;
            margin: 0 auto;
            padding: 10px;
            /* Padding untuk konten */
        }

        .border-text-box {
            border: 1px solid #000;
            padding: 10px;
            display: inline-block;
            font-size: 16px;
            font-weight: bold;
            letter-spacing: 5px;
        }

        .nama-surat {
            font-size: 16px;
            font-weight: bold;
        }

        .header {
            text-align: center;
            margin-bottom: 30px;
        }

        .kop-surat {
            /* Styling untuk kop surat */
            /* ... */
            text-align: center;
            margin-bottom: 30px;
            margin-top: 0;
        }

        .img-container {
            position: relative;
            float: right;

        }

        .img-ttd {
            position: absolute;

            left: 80;
            z-index: 1;
            width: 150px;
        }

        .ttd-kepala-sekolah {
            position: relative;
            z-index: 0;

            float: right;
            /* Sesuaikan jarak antara gambar tanda tangan dan teks kepala sekolah */
        }

        table {
            font-size: 12px;
            width: 100%;
        }

        th {
            text-align: center;
        }

        hr {
            border: 0;
            /* Hapus border default */
            height: 1px;
            /* Set tinggi garis */
            background-color: #ccc;
            margin-bottom: 0;
        }

        .table-bordered {
            width: 100%;
            border-collapse: collapse;
            margin-bottom: 20px;
        }

        .table-bordered th,
        .table-bordered td {
            border: 1px solid #dddddd;
            padding: 8px;
        }
    </style>
</head>

<body>
    <?php if ($settingskl->kop_img == 'N') { ?>
        <table class="table">
            <tbody>
                <tr>
                    <td style="width: 100px;text-align:center"><img src="data:image/png;base64,<?= $setting->logo64 ?>" width="80" alt="TTD"></td>
                    <td style="text-align:center;line-height:5px"><?= $settingskl->header_surat ?></td>
                    <td style="width: 100px;text-align:center"></td>
                </tr>
            </tbody>
        </table>
    <?php } else { ?>
        <img src="data:image/png;base64,<?= $setting->kop64 ?>" style="max-width: 20cm;" class="img-responsive" alt="KOP SURAT" />
    <?php } ?>
    <hr>
    <div class="container">
        <div class="header">
            <span class="nama-surat"><u><?= $settingskl->nama_surat ?></u></span><br>
            No. Surat: <strong><?= $settingskl->no_surat ?></strong>
        </div>

        <div class="content">
            <?= $settingskl->dasar_surat ?>
            <table style="margin-left:70px">
                <tr>
                    <td style="width: 150px;">Nama Siswa</td>
                    <td>: <b><?= $siswa->nama ?></b></td>
                </tr>
                <tr>
                    <td>Tempat, Tanggal Lahir</td>
                    <td>: <?= $siswa->tempat ?>, <?= $siswa->tgl_lahir ?></td>
                </tr>
                <tr>
                    <td>NIS / NISN</td>
                    <td>: <?= $siswa->nis ?> / <?= $siswa->nisn ?></td>
                </tr>
                <?php if ($settingskl->jurusan == 'Y') { ?>
                    <tr>
                        <td>Kompetensi Keahlian</td>
                        <td>: <?= $siswa->jurusan ?></td>
                    </tr>
                <?php } ?>
                <tr>
                    <td>Orang Tua / Wali</td>
                    <td>: <?= $siswa->nama_wali ?></td>
                </tr>

            </table>
            <?= $settingskl->isi_surat ?>
            <center>
                <span class="border-text-box"><?= $siswa->keterangan ?></span>
            </center>
            <?php if ($settingskl->nilai == 'Y') { ?>
                <p>dengan hasil sebagai berikut :</p>
                <table class="table table-bordered">
                    <thead>
                        <tr>
                            <th width="10">No</th>
                            <th>Mata Pelajaran</th>
                            <th width="50">Nilai</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php $no = 1; ?>
                        <?php $totalNilai = 0; ?>
                        <?php $jumlahData = 0; ?>
                        <?php foreach ($penilaian as $kelompok => $penilaians) : ?>
                            <tr>
                                <td colspan="3"><strong><?php echo $kelompok; ?></strong></td>
                            </tr>
                            <?php foreach ($penilaians as $penilaian) : ?>
                                <?php if ($penilaian->jurusan == 'semua' || $penilaian->jurusan == $siswa->jurusan) : ?>
                                    <tr>
                                        <td><?= $no++; ?></td>
                                        <td><?= $penilaian->nama_matapelajaran; ?></td>
                                        <td style="text-align: center;"><?= $penilaian->nilai; ?></td>
                                    </tr>

                                    <?php
                                    $totalNilai += $penilaian->nilai;
                                    $jumlahData++;
                                    ?>
                                <?php endif; ?>
                            <?php endforeach; ?>
                        <?php endforeach; ?>
                        <?php if ($jumlahData > 0) : ?>
                            <tr>
                                <td colspan="2">RATA RATA</td>
                                <td style="text-align: center;"><?= number_format($totalNilai / $jumlahData, 2); ?></td>
                            </tr>
                        <?php endif; ?>
                    </tbody>
                </table>

            <?php } ?>

            <?= $settingskl->penutup_surat ?>
        </div>
        <div class="ttd-kepala-sekolah">
            <?= $setting->kabupaten_kota ?>, <?= $settingskl->tgl_surat ?>
            <p>Kepala <?= $setting->nama_sekolah ?></p>
            <br><br><br><br>
            <u><?= $setting->nama_kepsek ?></u><br>
            NIP. <?= $setting->nip_kepsek ?>
        </div>
        <div class="img-container">
            <img src="data:image/png;base64,<?= $settingskl->ttd64 ?>" class="img-ttd" alt="TTD">
        </div>



    </div>

</body>

</html>