<page backtop="20mm" backbottom="20mm" backleft="20mm" backright="20mm">
    <style>
        body {
            font-family: helvetica;
            font-size: 11pt;
        }

        .judul {
            text-align: center;
            font-weight: bold;
            font-size: 14pt;
            text-decoration: underline;
        }

        .nomor {
            text-align: center;
            margin-top: 3px;
            margin-bottom: 15px;
        }

        table.identitas {
            width: 100%;
            border-collapse: collapse;
            margin-top: 5px;
            margin-bottom: 10px;
        }

        table.identitas td {
            padding: 2px 3px;
            vertical-align: top;
        }

        table.identitas td.label {
            width: 22%;
        }

        table.identitas td.titik {
            width: 2%;
        }

        table.identitas td.nilai {
            width: 76%;
        }

        table.pemeriksaan {
            width: 100%;
            border-collapse: collapse;
            margin-top: 10px;
            font-size: 10.5pt;
        }

        table.pemeriksaan th,
        table.pemeriksaan td {
            border: 1px solid #000;
            padding: 4px 6px;
        }

        table.pemeriksaan th {
            text-align: center;
            font-weight: bold;
        }

        .kesimpulan {
            margin-top: 15px;
            font-weight: bold;
        }

        .paragraf {
            margin-top: 5px;
            text-align: justify;
        }

        .ttd {
            width: 100%;
            margin-top: 5px;
        }

        .ttd td {
            vertical-align: top;
            text-align: center;
            font-size: 11pt;
        }
    </style>

<table style="width: 100%; font-size: 10pt; text-align: center;">
    <tr>
        <td style="width: 20%; text-align: center;">
            <img src="<?= base_url('images/logo2.png'); ?>" width="70" height="70" alt="Logo" />
        </td>
        <td style="width: 80%; text-align: center;">
            <h3 style="margin: 0; padding: 0;">
                <?= safe($utama['NamaPerusahaan']); ?>
            </h3>
            <p style="margin: 2px 0 0 0; padding: 0; line-height: 1.2;">
                <?= safe($utama['AlamatPerusahaan']); ?><br>
                Jakarta<br>
                <?= safe($utama['TeleponPerusahaan']); ?>, Fax : <?= safe($utama['FaxPerusahaan']); ?>
            </p>
        </td>
    </tr>
</table>

<hr style="border:1px solid #000; margin:10px auto; width:95%;">

    <div class="judul">SURAT KETERANGAN BEBAS NARKOBA</div>
    <div class="nomor">No : <?= htmlspecialchars($id['ID'] . '/' . date('m') . '/' . date('Y')); ?></div>

    <p>Dengan ini menerangkan bahwa:</p>

    <table class="identitas">
        <tr>
            <td class="label">Nama</td>
            <td class="titik">:</td>
            <td class="nilai"><?= safe($id['Nama']); ?></td>
        </tr>
        <tr>
            <td>Tanggal Lahir</td>
            <td>:</td>
            <td><?= !empty($id['TTL']) ? safe(date('d-m-Y', strtotime($id['TTL']))) : ''; ?></td>
        </tr>
        <tr>
            <td style="width:25%">Alamat</td>
            <td style="width:5%">:</td>
            <td style="width:70%"><?= $mcu['HomeAddress1']; ?></td>
        </tr>
        <tr>
            <td>Tanggal Kunjungan</td>
            <td>:</td>
            <td><?= safe(date('d-m-Y', strtotime($id['Kunjungan']))); ?></td>
        </tr>
        <tr>
            <td>Dokter</td>
            <td>:</td>
            <td><?= safe($id['Dokter']); ?></td>
        </tr>
        <tr>
            <td>Penjamin</td>
            <td>:</td>
            <td><?= safe($id['CompanyName'] ?? ''); ?></td>
        </tr>
    </table>

    <p class="paragraf">
        Telah dilakukan pemeriksaan Narkoba terhadap yang bersangkutan meliputi pemeriksaan
        laboratorium (urine) sebagai berikut:
    </p>

    <table class="lab-result">
        <thead>
            <tr>
                <th width="45%">PEMERIKSAAN</th>
                <th width="25%">HASIL</th>
                <th width="30%">NILAI NORMAL</th>
            </tr>
        </thead>
        <tbody>
            <?php if (!empty($groupnarkoba)) : ?>
                <?php foreach ($groupnarkoba as $g) : ?>
                    <tr>
                        <td class="group" colspan="3"><b><?= strtoupper(safe($g['BahasaLC'])); ?></b></td>
                    </tr>

                    <?php
                    $filtered = array_filter($viewlabnarkoba, function ($v) use ($g) {
                        return $v['CategoryID'] == $g['CategoryID'];
                    });
                    ?>

                    <?php if (!empty($filtered)) : ?>
                        <?php
                        $positif = false;

                        foreach ($filtered as $d) :
                            if (stripos($d['ResultValue'], 'posit') !== false) {
                                $positif = true;
                            }
                        ?>
                            <tr>
                                <td style="padding-left:20px;"><?= safe($d['Bahasa']); ?></td>
                                <td style="text-align:center;"><?= safe($d['ResultValue']); ?></td>
                                <td style="text-align:center;"><?= safe($d['Normalvalue']); ?></td>
                            </tr>
                        <?php endforeach; ?>


                    <?php else : ?>
                        <tr>
                            <td colspan="3" style="font-style:italic; text-align:center;">Tidak ada data</td>
                        </tr>
                    <?php endif; ?>
                <?php endforeach; ?>
            <?php else : ?>
                <tr>
                    <td colspan="3" style="text-align:center;">Tidak ada hasil laboratorium</td>
                </tr>
            <?php endif; ?>
        </tbody>
    </table>
    <?php
    $kesimpulan = $positif ? "POSITIF NARKOBA" : "BEBAS NARKOBA";
    ?>
    <p class="kesimpulan">Kesimpulan : <b><?= $kesimpulan; ?></b></p>

    <p class="paragraf">
        Demikian surat keterangan ini dibuat untuk dipergunakan seperlunya.
    </p>
<br><br>
   <table style="width:100%;">
    <tr>
        <td style="width:60%;"></td>
        <td style="width:40%; text-align:right; padding-right:60px;">
            Jakarta, <?= date('d-M-Y'); ?><br>
            Pemeriksa, <br><br><br><br><br>

            ( ........................... )
        </td>
    </tr>
</table>
</page>