<div class="table-responsive">
    <table class="table table-sm table-bordered">
        <thead>
            <tr>
                <th>Nama Item</th>
                <th>Qty</th>
                <th>Harga</th>
                <th>Subtotal</th>
            </tr>
        </thead>
        <tbody>
            <?php if (!empty($items)): ?>
                <?php foreach ($items as $item): ?>
                    <tr>
                        <td><?= esc($item['nama_item'] ?? '-') ?></td>
                        <td><?= esc($item['qty']) ?></td>
                        <td class="text-end">Rp <?= number_format($item['harga'] ?? 0, 0, ',', '.') ?></td>
                        <td class="text-end">Rp <?= number_format($item['subtotal'] ?? 0, 0, ',', '.') ?></td>
                    </tr>
                <?php endforeach ?>
            <?php else: ?>
                <tr>
                    <td colspan="4" class="text-center">Tidak ada item.</td>
                </tr>
            <?php endif ?>
        </tbody>
    </table>

    <hr>

    <div class="row">
        <div class="col-md-6">
            <p><strong>Tanggal:</strong> <?= date('d-m-Y H:i:s', strtotime($sale['tanggal'] ?? date('Y-m-d H:i:s'))) ?></p>
            <p><strong>Pelanggan:</strong> <?= esc($sale['customer_name'] ?? '-') ?></p>
            <p><strong>Kasir:</strong> <?= esc($sale['user_name'] ?? '-') ?></p>
            <p><strong>Kode Transaksi:</strong> <?= esc($sale['kode'] ?? '-') ?></p>

            <?php if (!empty($sale['jenis_pesan'])): ?>
                <p><strong>Jenis Pesan:</strong> <?= esc(ucwords(str_replace('_', ' ', $sale['jenis_pesan']))) ?></p>
            <?php endif; ?>

            <?php if (($sale['jenis_pesan'] ?? '') === 'dine_in' && !empty($sale['no_meja'])): ?>
                <p><strong>No. Meja:</strong> <?= esc($sale['no_meja']) ?></p>
            <?php endif; ?>
        </div>

        <div class="col-md-6 text-end">
            <p><strong>Total:</strong> Rp <?= number_format($sale['total'], 0, ',', '.') ?></p>

            <?php if (!empty($sale['diskon_nominal']) && $sale['diskon_nominal'] > 0): ?>
                <p><strong>Diskon (<?= $sale['diskon_persen'] ?>%):</strong> Rp <?= number_format($sale['diskon_nominal'], 0, ',', '.') ?></p>
            <?php endif; ?>

            <?php if (($sale['pajak_nominal'] ?? 0) > 0): ?>
                <p><strong>Pajak (<?= $sale['pajak_persen'] ?>%):</strong> Rp <?= number_format($sale['pajak_nominal'], 0, ',', '.') ?></p>
            <?php endif; ?>

            <p><strong>Grand Total:</strong> <strong>Rp <?= number_format(($sale['total'] + $sale['pajak_nominal'] - $sale['diskon_nominal']), 0, ',', '.') ?></strong></p>

            <p><strong>Bayar:</strong> Rp <?= number_format($sale['dibayar'] ?? 0, 0, ',', '.') ?></p>
            <p><strong>Kembali:</strong> Rp <?= number_format($sale['kembalian'] ?? 0, 0, ',', '.') ?></p>
        </div>
    </div>
</div>
