<h6>Nama Pasien: <?= esc($pembayaran['nama_lengkap'] ?? '-') ?></h6>
<h6>Tanggal Pembayaran: <?= date('d-m-Y', strtotime($pembayaran['tanggal_pembayaran'])) ?></h6>
<h6>Total: Rp <?= number_format($pembayaran['total_biaya'], 0, ',', '.') ?></h6>
<h6>Metode: <?= esc($pembayaran['metode_pembayaran']) ?></h6>
<h6>Keterangan: <?= esc($pembayaran['keterangan']) ?></h6>

<hr>

<h6>Detail Item</h6>
<div class="table-responsive">
    <table class="table table-bordered">
        <thead class="table-light">
            <tr>
                <th>Jenis</th>
                <th>Nama Item</th>
                <th>Jumlah</th>
                <th>Harga</th>
                <th>Subtotal</th>
            </tr>
        </thead>
        <tbody>
            <?php foreach ($detail as $item): ?>
                <tr>
                    <td><?= ucfirst($item['jenis_item']) ?></td>
                    <td><?= esc($item['nama_item']) ?></td>
                    <td><?= $item['jumlah'] ?></td>
                    <td>Rp <?= number_format($item['harga'], 0, ',', '.') ?></td>
                    <td>Rp <?= number_format($item['subtotal'], 0, ',', '.') ?></td>
                </tr>
            <?php endforeach; ?>
        </tbody>
    </table>
</div>

<button onclick="printThermal()" class="btn btn-sm btn-dark mb-3">
    <i class="bi bi-printer"></i> Print Termal
</button>

<!-- STRUK CETAK TERMAL -->
<div id="thermal-print" style="display:none; font-family: monospace; font-size:12px; max-width: 300px; padding: 10px;">
    <div style="text-align:center;">
        <strong>KLINIK GIGI SEHAT</strong><br>
        Jl. Sehat No. 123<br>
        0812-3456-7890<br>
        ------------------------------
    </div>

    <div>
        Pasien : <?= esc($pembayaran['nama_lengkap'] ?? '-') ?><br>
        Tanggal: <?= date('d-m-Y H:i', strtotime($pembayaran['tanggal_pembayaran'])) ?><br>
        Metode : <?= esc($pembayaran['metode_pembayaran']) ?><br>
        ------------------------------
    </div>

    <div>
        <?php foreach ($detail as $item): ?>
            <?= esc($item['nama_item']) ?><br>
            <?= $item['jumlah'] ?> x Rp <?= number_format($item['harga'], 0, ',', '.') ?>
            <span style="float:right;">Rp <?= number_format($item['subtotal'], 0, ',', '.') ?></span><br>
        <?php endforeach; ?>
    </div>

    <div style="border-top:1px dashed #000; margin-top:5px;"></div>
    <div>
        <strong>Total:</strong>
        <span style="float:right;">Rp <?= number_format($pembayaran['total_biaya'], 0, ',', '.') ?></span><br>
    </div>
    <div style="text-align:center; margin-top:10px;">
        --- Terima Kasih ---
    </div>
</div>


<script>
    function printThermal() {
        let printContents = document.getElementById('thermal-print').innerHTML;
        let newWindow = window.open('', '', 'width=300,height=600');
        newWindow.document.write('<html><head><title>Print Struk</title>');
        newWindow.document.write('<style>body{font-family: monospace; font-size:12px;}</style>');
        newWindow.document.write('</head><body>');
        newWindow.document.write(printContents);
        newWindow.document.write('</body></html>');
        newWindow.document.close();
        newWindow.focus();
        newWindow.print();
        newWindow.close();
    }
</script>