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

<head>
    <meta charset="UTF-8">
    <title>Formulir Permintaan dan Pemberian Cuti</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            font-size: 11pt;
        }

        table {
            width: 100%;
            border-collapse: collapse;
        }

        td,
        th {
            border: 1px solid black;
            padding: 5px;
            vertical-align: top;
        }

        .no-border {
            border: none;
        }
    </style>
</head>

<body>
    <?php
    $mulai = new DateTime($data['tanggal_mulai']);
    $selesai = new DateTime($data['tanggal_selesai']);
    $lamaCuti = $mulai->diff($selesai)->days + 1; // +1 supaya termasuk hari pertama
    ?>

    <!-- Tambahkan sebelum heading formulir -->
    <table style="width: 100%;border: none; border-collapse: collapse;margin-bottom: 5px;">
        <tr style="border: none;">
            <td style="width: 60%;border: none;"></td>
            <td style="width: 40%; text-align: right;border: none;">
                <p style="margin: 0;">............................, ............................</p>
                <p style="margin: 0;text-align: left;padding-left: 30px;">Yth.</p>
                <p style="margin: 0;">......................................................</p>
                <p style="margin: 0; text-align: left;padding-left: 30px;">di</p>
                <p style="margin: 0;">......................................................</p>
            </td>
        </tr>
    </table>

    <h3 style="text-align: center; text-transform: uppercase;">
        Formulir Permintaan dan Pemberian Cuti
    </h3>
    <p>Nomor: ...........................................................</p>

    <table>
        <tr>
            <td colspan="4"><strong>I. DATA PEGAWAI</strong></td>
        </tr>
        <tr>
            <td>Nama</td>
            <td><?= $data['nama'] ?></td>
            <td>NIP</td>
            <td><?= $data['nip'] ?></td>
        </tr>
        <tr>
            <td>Jabatan</td>
            <td><?= $data['nama_jabatan'] ?? '-' ?></td>
            <td>Gol. Ruang</td>
            <td><?= $data['golongan_ruang'] ?? '-' ?></td>
        </tr>
        <tr>
            <td>Unit Kerja</td>
            <td><?= $data['nama_unit'] ?? '-' ?></td>
            <td>Masa Kerja</td>
            <td><?= $data['masa_kerja'] ?? '-' ?></td>
        </tr>

        <tr>
            <td colspan="4"><strong>II. JENIS CUTI YANG DIAMBIL</strong></td>
        </tr>
        <tr>
            <td colspan="4"> <?= $data['nama_jenis'] ?></td>
        </tr>

        <tr>
            <td colspan="4"><strong>III. ALASAN CUTI</strong><br><?= $data['keterangan'] ?></td>
        </tr>

        <tr>
            <td colspan="4"><strong>IV. LAMANYA CUTI</strong><br>
                Selama: <?= $lamaCuti ?> hari<br>
                Mulai Tanggal: <?= date('d-m-Y', strtotime($data['tanggal_mulai'])) ?><br>
                s/d: <?= date('d-m-Y', strtotime($data['tanggal_selesai'])) ?>
            </td>
        </tr>

        <tr>
            <td colspan="4"><strong>V. CATATAN CUTI : </strong></td>
        </tr>
        <tr>
            <td rowspan="2">Tahun</td>
            <td rowspan="2">Sisa</td>
            <td rowspan="2">Keterangan</td>
            <td>Paraf Petugas</td>
        </tr>
        <tr>
            <td style="height: 50px;"></td>
        </tr>
        <?php if (!empty($historiCuti)): ?>
            <?php foreach ($historiCuti as $cuti): ?>
                <tr>
                    <td><?= date('Y', strtotime($cuti['tanggal_mulai'])) ?></td>
                    <td><?= $cuti['sisa_cuti'] ?? '-' ?></td>
                    <td><?= esc($cuti['keterangan']) ?></td>
                    <td></td>
                </tr>
            <?php endforeach; ?>
        <?php else: ?>
            <tr>
                <td colspan="4" style="text-align:center;">Tidak ada histori cuti</td>
            </tr>
        <?php endif; ?>

        <tr>
            <!-- Kolom kiri: Alamat selama cuti -->
            <td colspan="2" style="vertical-align: top;">
                <strong>VI. ALAMAT SELAMA MENJALANKAN CUTI</strong><br><br>
                <?= $data['alamat_selama_menjalankan_cuti'] ?><br><br>
                <strong>Telp/HP:</strong> <?= $data['nohape'] ?>
            </td>

            <!-- Kolom kanan: TTD -->
            <td colspan="2" style="text-align: center;">
                <?= $data['tempat_pengajuan'] ?? '.....................' ?>, <?= date('d-m-Y') ?><br>
                Hormat Saya,<br><br>
                <?php if (!empty($data['ttd_user'])): ?>
                    <img src="<?= base_url('uploads/ttd/' . $data['ttd_user']) ?>" style="height:80px;"><br>
                <?php else: ?>
                    <div style="height: 80px;"></div>
                <?php endif; ?>
                (<strong><?= $data['nama'] ?></strong>)<br>
                NIP. <?= $data['nip'] ?>
            </td>
        </tr>

        <!-- VII. PERTIMBANGAN ATASAN LANGSUNG -->
        <tr>
            <td colspan="4"><strong>VII. PERTIMBANGAN ATASAN LANGSUNG</strong></td>
        </tr>
        <tr>
            <td colspan="4">
                <strong><?= strtoupper($data['status_supervisor'] ?? '-') ?></strong>
            </td>
        </tr>
        <tr>
            <td colspan="2"></td>
            <td colspan="2" style="text-align: center;">
                <!-- <?= $supervisor['nama_jabatan'] ?? 'Supervisor' ?><br> -->
                Atasan Langsung<br>
                <?php if (!empty($supervisor['ttd_user'])): ?>
                    <img src="<?= base_url('uploads/ttd/' . $supervisor['ttd_user']) ?>" style="height:80px;"><br>
                <?php else: ?>
                    <div style="height: 80px;"></div>
                <?php endif; ?>
                <strong>(<?= $supervisor['nama'] ?? '..................................' ?>)</strong><br>
                NIP. <?= $supervisor['nip'] ?? '..........................' ?>
            </td>
        </tr>
        <!-- VIII. KEPUTUSAN PEJABAT YANG BERWENANG MEMBERIKAN CUTI -->
        <tr>
            <td colspan="4"><strong>VIII. KEPUTUSAN PEJABAT YANG BERWENANG MEMBERIKAN CUTI</strong></td>
        </tr>
        <tr>
            <td colspan="4">
                <strong><?= strtoupper($data['status_manager'] ?? '-') ?></strong>
            </td>
        </tr>
        <tr>
            <td colspan="2"></td>
            <td colspan="2" style="text-align: center;">
                <!-- <?= $manager['nama_jabatan'] ?? 'Manager' ?><br> -->
                Ketua<br>
                <?php if (!empty($manager['ttd_user'])): ?>
                    <img src="<?= base_url('uploads/ttd/' . $manager['ttd_user']) ?>" style="height:80px;"><br>
                <?php else: ?>
                    <div style="height: 80px;"></div>
                <?php endif; ?>
                <strong>(<?= $manager['nama'] ?? '..................................' ?>)</strong><br>
                NIP. <?= $manager['nip'] ?? '..........................' ?>
            </td>
        </tr>
    </table>
</body>

</html>