<!DOCTYPE html>
<html lang="id">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>Invoice - <?php echo e($pesanan->kode_pesanan); ?></title>
    <style>
        * { margin: 0; padding: 0; box-sizing: border-box; }
        body { font-family: Arial, sans-serif; font-size: 9pt; color: #1a1a1a; background: white; }

        @media print {
            @page { size: A4 portrait; margin: 8mm; }
            body { margin: 0; }
        }
        .no-print { display: block; }
        @media print { .no-print { display: none !important; } }

        .invoice { width: 190mm; margin: 0 auto; }

        /* ── HEADER ── */
        .header { display: table; width: 100%; border-bottom: 3px solid #ea580c; padding-bottom: 10px; margin-bottom: 10px; }
        .header-left  { display: table-cell; vertical-align: top; width: 60%; }
        .header-right { display: table-cell; vertical-align: top; text-align: right; width: 40%; }
        .toko-nama { font-size: 15pt; font-weight: bold; color: #ea580c; }
        .toko-sub  { font-size: 7.5pt; color: #666; margin-top: 3px; line-height: 1.5; }
        .invoice-title { font-size: 20pt; font-weight: bold; text-transform: uppercase; letter-spacing: 3px; color: #1f2937; }
        .invoice-no { font-size: 8.5pt; color: #555; margin-top: 4px; line-height: 1.6; }

        /* ── STAMP ── */
        .paid-stamp {
            display: inline-block; border: 3px solid #16a34a; color: #16a34a;
            font-size: 15pt; font-weight: bold; padding: 4px 14px;
            transform: rotate(-12deg); letter-spacing: 3px;
            opacity: 0.88; margin-top: 6px;
        }
        .unpaid-stamp {
            display: inline-block; border: 3px solid #dc2626; color: #dc2626;
            font-size: 15pt; font-weight: bold; padding: 4px 14px;
            transform: rotate(-12deg); letter-spacing: 3px;
            opacity: 0.88; margin-top: 6px;
        }

        /* ── INFO BOX ── */
        .info-section { display: table; width: 100%; margin-bottom: 10px; }
        .info-box { display: table-cell; vertical-align: top; width: 50%; padding: 8px 10px; border: 1px solid #e2e8f0; background: #f8fafc; }
        .info-box:first-child { border-right: none; }
        .box-title  { font-size: 6.5pt; text-transform: uppercase; letter-spacing: 1.5px; color: #ea580c; font-weight: bold; margin-bottom: 5px; }
        .box-name   { font-size: 10pt; font-weight: bold; color: #1f2937; margin-bottom: 3px; }
        .box-detail { font-size: 7.5pt; color: #555; line-height: 1.7; }

        /* ── STATUS STRIP ── */
        .status-strip {
            background: #fff7ed; border: 1px solid #fed7aa;
            border-left: 4px solid #ea580c;
            padding: 6px 10px; margin-bottom: 10px; display: table; width: 100%;
        }
        .status-strip-left  { display: table-cell; font-size: 8pt; vertical-align: middle; color: #374151; }
        .status-strip-right { display: table-cell; text-align: right; font-size: 8pt; vertical-align: middle; padding-left: 8px; }
        .status-badge {
            display: inline-block; background: #1f2937; color: white;
            padding: 3px 10px; font-weight: bold; font-size: 7.5pt;
            text-transform: uppercase; letter-spacing: 0.5px;
        }

        /* ── TABEL PRODUK ── */
        .produk-tbl { width: 100%; border-collapse: collapse; margin-bottom: 8px; }
        .produk-tbl thead tr { background: #1f2937; color: white; }
        .produk-tbl th { padding: 7px 8px; text-align: left; font-size: 7.5pt; font-weight: bold; text-transform: uppercase; letter-spacing: 0.5px; }
        .produk-tbl th.r { text-align: right; }
        .produk-tbl th.c { text-align: center; }
        .produk-tbl td { padding: 6px 8px; border-bottom: 1px solid #f1f5f9; font-size: 8.5pt; vertical-align: top; }
        .produk-tbl td.r { text-align: right; }
        .produk-tbl td.c { text-align: center; }
        .produk-tbl tbody tr:nth-child(even) { background: #f8fafc; }
        .pnama   { font-weight: bold; color: #1f2937; }
        .pvarian { font-size: 7pt; color: #888; margin-top: 2px; }

        /* ── SUMMARY ── */
        .summary-wrap  { display: table; width: 100%; margin-bottom: 8px; }
        .summary-left  { display: table-cell; width: 55%; vertical-align: top; padding-right: 10px; }
        .summary-right { display: table-cell; width: 45%; vertical-align: top; }

        .catatan-box {
            border: 1px solid #e2e8f0; border-left: 4px solid #f59e0b;
            padding: 7px 10px; font-size: 7.5pt; color: #555;
            line-height: 1.7; background: #fffbeb;
        }
        .catatan-title { font-weight: bold; font-size: 7.5pt; margin-bottom: 3px; color: #92400e; text-transform: uppercase; }

        .sum-tbl { width: 100%; border-collapse: collapse; border: 1px solid #e2e8f0; }
        .sum-tbl td { padding: 5px 8px; font-size: 8.5pt; color: #374151; border-bottom: 1px solid #f1f5f9; }
        .sum-tbl td.r { text-align: right; }
        .sum-tbl tr.subtotal td { border-top: 1px solid #e2e8f0; }
        .sum-tbl tr.diskon td { color: #16a34a; }
        .sum-tbl tr.total { background: #1f2937; }
        .sum-tbl tr.total td { font-weight: bold; font-size: 10pt; color: white; border-bottom: none; padding: 7px 8px; }
        .sum-tbl tr.total td.r { font-size: 11pt; color: #fb923c; }

        /* ── TTD ── */
        .ttd-section { display: table; width: 100%; margin-top: 15px; }
        .ttd-box { display: table-cell; width: 33.33%; text-align: center; font-size: 8pt; padding: 5px; }
        .ttd-title { font-weight: bold; color: #374151; margin-bottom: 40px; }
        .ttd-line  { border-top: 1px solid #9ca3af; margin-top: 5px; }
        .ttd-name  { font-size: 7.5pt; color: #6b7280; margin-top: 3px; }

        /* ── FOOTER ── */
        .footer-strip { border-top: 2px solid #ea580c; margin-top: 10px; padding-top: 6px; display: table; width: 100%; }
        .footer-left  { display: table-cell; font-size: 7pt; color: #9ca3af; }
        .footer-right { display: table-cell; text-align: right; font-size: 7pt; color: #6b7280; }
    </style>
</head>
<body>
<div class="invoice">

    
    <div class="header">
        <div class="header-left">
            <?php
                $namaToko = $toko->nama_toko ?? 'Raja Futsal';
                $namaToko = trim(preg_replace('/[^\x{0000}-\x{007F}]/u', '', $namaToko)) ?: 'Raja Futsal';
            ?>
            <div class="toko-nama"><?php echo e($namaToko); ?></div>
            <div class="toko-sub">
                <?php if($toko && $toko->alamat): ?> <?php echo e($toko->alamat); ?><br> <?php endif; ?>
                <?php if($toko && ($toko->no_hp ?? $toko->telepon ?? null)): ?>
                    Telp: <?php echo e($toko->no_hp ?? $toko->telepon); ?>

                <?php endif; ?>
            </div>
        </div>
        <div class="header-right">
            <div class="invoice-title">INVOICE</div>
            <div class="invoice-no">
                No: <b><?php echo e($pesanan->kode_pesanan); ?></b><br>
                Tanggal: <?php echo e($pesanan->created_at->format('d M Y')); ?><br>
                Pukul: <?php echo e($pesanan->created_at->format('H:i')); ?> WIB
            </div>
            <div style="margin-top:8px;">
                <?php if($pesanan->pembayaran): ?>
                    <span class="paid-stamp">LUNAS</span>
                <?php else: ?>
                    <span class="unpaid-stamp">BELUM BAYAR</span>
                <?php endif; ?>
            </div>
        </div>
    </div>

    
    <div class="info-section">
        <div class="info-box">
            <div class="box-title">Dari (Penjual)</div>
            <div class="box-name"><?php echo e($namaToko); ?></div>
            <div class="box-detail">
                <?php if($toko && $toko->alamat): ?> <?php echo e($toko->alamat); ?><br> <?php endif; ?>
                <?php if($toko && ($toko->no_hp ?? $toko->telepon ?? null)): ?>
                    Telp: <?php echo e($toko->no_hp ?? $toko->telepon); ?>

                <?php endif; ?>
                <?php if($pesanan->kurir): ?>
                    <br><br>
                    <b>Kurir:</b> <?php echo e($pesanan->kurir->name); ?><br>
                    Telp Kurir: <?php echo e($pesanan->kurir->no_hp ?? '-'); ?>

                <?php endif; ?>
            </div>
        </div>
        <div class="info-box">
            <div class="box-title">Kepada (Pembeli)</div>
            <?php if($pesanan->alamat): ?>
                <div class="box-name"><?php echo e($pesanan->alamat->nama_penerima); ?></div>
                <div class="box-detail">
                    Telp: <?php echo e($pesanan->alamat->no_hp); ?><br>
                    <?php echo e($pesanan->alamat->alamat_lengkap); ?><br>
                    <?php if(optional($pesanan->alamat->village)->name): ?>
                        <?php echo e(strtoupper(optional($pesanan->alamat->village)->name)); ?>,
                    <?php endif; ?>
                    <?php echo e(strtoupper(optional($pesanan->alamat->district)->name ?? '')); ?><br>
                    <?php echo e(strtoupper(optional($pesanan->alamat->city)->name ?? '')); ?>,
                    <?php echo e(strtoupper(optional($pesanan->alamat->province)->name ?? '')); ?>

                    <?php if($pesanan->alamat->kode_pos): ?> <?php echo e($pesanan->alamat->kode_pos); ?> <?php endif; ?>
                </div>
            <?php else: ?>
                <div class="box-detail">Alamat tidak tersedia</div>
            <?php endif; ?>
        </div>
    </div>

    
    <div class="status-strip">
        <div class="status-strip-left">
            <b>No. Pesanan:</b> <?php echo e($pesanan->kode_pesanan); ?>

            <?php if($pesanan->no_resi): ?>
                &nbsp;&nbsp; <b>No. Resi:</b> <?php echo e($pesanan->no_resi); ?>

            <?php endif; ?>
            &nbsp;&nbsp; <b>Metode Bayar:</b>
            <?php if($pesanan->pembayaran): ?>
                <?php echo e(strtoupper(str_replace('_', ' ', $pesanan->pembayaran->metode))); ?>

            <?php else: ?> — <?php endif; ?>
        </div>
        <div class="status-strip-right">
            <?php
                $statusLabels = [
                    'pending'    => 'MENUNGGU PEMBAYARAN',
                    'dibayar'    => 'DIBAYAR',
                    'diproses'   => 'SEDANG DIPROSES',
                    'dikirim'    => 'DIKIRIM',
                    'selesai'    => 'SELESAI',
                    'dibatalkan' => 'DIBATALKAN',
                ];
            ?>
            <span class="status-badge">
                <?php echo e($statusLabels[$pesanan->status] ?? strtoupper($pesanan->status)); ?>

            </span>
        </div>
    </div>

    
    <table class="produk-tbl">
        <thead>
            <tr>
                <th style="width:4%">#</th>
                <th style="width:42%">Nama Produk</th>
                <th style="width:18%">Variasi</th>
                <th class="c" style="width:8%">Qty</th>
                <th class="r" style="width:14%">Harga Satuan</th>
                <th class="r" style="width:14%">Subtotal</th>
            </tr>
        </thead>
        <tbody>
            <?php $__currentLoopData = $pesanan->detail; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $i => $detail): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
            <tr>
                <td style="color:#9ca3af;"><?php echo e($i + 1); ?></td>
                <td>
                    <div class="pnama"><?php echo e($detail->nama_produk); ?></div>
                    <?php if($detail->warna || $detail->ukuran): ?>
                    <div class="pvarian">
                        <?php echo e(implode(' · ', array_filter([$detail->warna, $detail->ukuran ? 'Uk. '.$detail->ukuran : null]))); ?>

                    </div>
                    <?php endif; ?>
                </td>
                <td style="font-size:8pt;color:#6b7280;">
                    <?php if($detail->warna): ?> <?php echo e($detail->warna); ?> <?php endif; ?>
                    <?php if($detail->ukuran): ?> / <?php echo e($detail->ukuran); ?> <?php endif; ?>
                    <?php if(!$detail->warna && !$detail->ukuran): ?> — <?php endif; ?>
                </td>
                <td class="c" style="font-weight:bold;"><?php echo e($detail->qty); ?></td>
                <td class="r">Rp <?php echo e(number_format($detail->harga, 0, ',', '.')); ?></td>
                <td class="r" style="font-weight:bold;">Rp <?php echo e(number_format($detail->subtotal, 0, ',', '.')); ?></td>
            </tr>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
        </tbody>
    </table>

    
    <div class="summary-wrap">
        <div class="summary-left">
            <div class="catatan-box">
                <div class="catatan-title">&#9888; Catatan</div>
                Mohon periksa kondisi barang sebelum menerima. Invoice ini merupakan
                bukti transaksi yang sah. Simpan invoice ini sebagai bukti pembelian Anda.
                <?php if($pesanan->catatan): ?>
                    <?php
                        $catatanJson = json_decode($pesanan->catatan, true);
                        $catatanTampil = null;
                        if (json_last_error() === JSON_ERROR_NONE && is_array($catatanJson)) {
                            $catatanTampil = $catatanJson['keterangan'] ?? $catatanJson['keterangan_diskon'] ?? null;
                        } else {
                            $catatanTampil = $pesanan->catatan;
                        }
                    ?>
                    <?php if($catatanTampil): ?>
                        <br><br><b>Catatan Pesanan:</b> <?php echo e($catatanTampil); ?>

                    <?php endif; ?>
                <?php endif; ?>
            </div>
        </div>
        <div class="summary-right">
            <table class="sum-tbl">
                <tr>
                    <td>Subtotal (<?php echo e($pesanan->detail->sum('qty')); ?> item)</td>
                    <td class="r">Rp <?php echo e(number_format($subtotalProduk, 0, ',', '.')); ?></td>
                </tr>
                <?php if(isset($diskon) && $diskon > 0): ?>
                <tr class="diskon">
                    <td>Diskon</td>
                    <td class="r">− Rp <?php echo e(number_format($diskon, 0, ',', '.')); ?></td>
                </tr>
                <?php endif; ?>
                <tr>
                    <td>Ongkos Kirim</td>
                    <td class="r">
                        <?php if($ongkir <= 0): ?> GRATIS
                        <?php else: ?> Rp <?php echo e(number_format($ongkir, 0, ',', '.')); ?> <?php endif; ?>
                    </td>
                </tr>
                <?php if($pesanan->pembayaran): ?>
                <tr class="subtotal">
                    <td style="color:#6b7280;">Metode Pembayaran</td>
                    <td class="r"><?php echo e(strtoupper(str_replace('_',' ',$pesanan->pembayaran->metode))); ?></td>
                </tr>
                <tr>
                    <td style="color:#6b7280;">Tanggal Bayar</td>
                    <td class="r"><?php echo e($pesanan->pembayaran->created_at->format('d M Y')); ?></td>
                </tr>
                <?php endif; ?>
                <tr class="total">
                    <td>TOTAL</td>
                    <td class="r">Rp <?php echo e(number_format($pesanan->total_harga, 0, ',', '.')); ?></td>
                </tr>
            </table>
        </div>
    </div>

    
    <div class="ttd-section">
        <div class="ttd-box">
            <div class="ttd-title">Dipesan Oleh</div>
            <div class="ttd-line"></div>
            <div class="ttd-name"><?php echo e(optional($pesanan->user)->name ?? '-'); ?></div>
        </div>
        <div class="ttd-box">
            <div class="ttd-title">Dikirim Oleh</div>
            <div class="ttd-line"></div>
            <div class="ttd-name"><?php echo e($pesanan->kurir->name ?? '-'); ?></div>
        </div>
        <div class="ttd-box">
            <div class="ttd-title">Diterima Oleh</div>
            <div class="ttd-line"></div>
            <div class="ttd-name"><?php echo e($pesanan->alamat->nama_penerima ?? '-'); ?></div>
        </div>
    </div>

    
    <div class="footer-strip">
        <div class="footer-left">Dicetak: <?php echo e(now()->format('d M Y, H:i')); ?> WIB</div>
        <div class="footer-right">
            <b>Raja Futsal</b> — Perlengkapan Futsal Terpercaya &nbsp;|&nbsp; Terima kasih telah berbelanja!
        </div>
    </div>

</div>
</body>
</html><?php /**PATH C:\laragon\www\ecommerce\resources\views/pesanan/invoice.blade.php ENDPATH**/ ?>