<div class="preview-container bg-white text-gray-800 font-sans text-xs">
    
    <div class="text-center mb-4 border-b border-gray-300 pb-2">
        <h1 class="text-sm font-bold uppercase"><?php echo e($angsuran->mahasiswa->kampus->nama ?? 'KAMPUS TIDAK ADA'); ?></h1>
        <h2 class="text-xs font-semibold mt-1">PROGRAM PERKULIAHAN</h2>
    </div>

    
    <div class="grid grid-cols-2 gap-3 mb-4">
        <div>
            <table class="w-full">
                <tr>
                    <td class="font-semibold w-20">Nama</td>
                    <td>: <?php echo e($angsuran->mahasiswa->nama); ?></td>
                </tr>
                <tr>
                    <td class="font-semibold">NIM</td>
                    <td>: <?php echo e($angsuran->mahasiswa->nim); ?></td>
                </tr>
                <tr>
                    <td class="font-semibold">Status</td>
                    <td>: Baru</td>
                </tr>
            </table>
        </div>
        <div>
            <table class="w-full">
                <tr>
                    <td class="font-semibold w-20">No Telp</td>
                    <td>: <?php echo e($angsuran->mahasiswa->no_wa ?? '-'); ?></td>
                </tr>
                <tr>
                    <td class="font-semibold">Kelompok</td>
                    <td>: <?php echo e($angsuran->mahasiswa->kelompok ?? 'SMA'); ?></td>
                </tr>
                <tr>
                    <td class="font-semibold">Angkatan</td>
                    <td>: (<?php echo e($angsuran->mahasiswa->angkatan); ?>)</td>
                </tr>
            </table>
        </div>
    </div>

    <div class="mb-3">
        <table class="w-full">
            <tr>
                <td class="font-semibold w-24">Program Studi</td>
                <td> :
                    <?php if($angsuran->mahasiswa->prodi && $angsuran->mahasiswa->prodi->jenjang): ?>
                        [<?php echo e($angsuran->mahasiswa->prodi->jenjang); ?>]
                    <?php endif; ?>
                    <?php echo e($angsuran->mahasiswa->prodi->nama ?? '-'); ?>

                </td>
            </tr>
        </table>
    </div>

    
    <?php
        $cutiSemester = $angsuran->mahasiswa->cuti_semester;
        $cutiList = [];

        if (!is_null($cutiSemester)) {
            if (is_string($cutiSemester) && str_starts_with($cutiSemester, '[')) {
                $cutiList = json_decode($cutiSemester, true);
            } elseif (is_array($cutiSemester)) {
                $cutiList = $cutiSemester;
            } elseif ($cutiSemester != '') {
                $cutiList = [$cutiSemester];
            }
        }

        $isItemOnCuti = function ($detail) use ($angsuran, $cutiList) {
            if (empty($cutiList)) {
                return false;
            }

            $kodeBiaya = $detail->kode_biaya;

            // Biaya RUTIN, BL, SP, BT tidak terpengaruh cuti
            if (
                str_starts_with($kodeBiaya, 'RUTIN-') ||
                str_starts_with($kodeBiaya, 'BL-') ||
                str_starts_with($kodeBiaya, 'SP-') ||
                str_starts_with($kodeBiaya, 'BT-')
            ) {
                return false;
            }

            // Hanya SPB, SPP, UKT yang bisa terkena cuti
            if (
                !str_starts_with($kodeBiaya, 'SPB') &&
                !str_starts_with($kodeBiaya, 'SPP') &&
                !str_starts_with($kodeBiaya, 'UKT')
            ) {
                return false;
            }

            return in_array($detail->semester, $cutiList);
        };

        $cutiText = !empty($cutiList) ? 'Semester ' . implode(', ', $cutiList) : '';
    ?>

    <?php if($cutiText): ?>
        <div class="mb-3 p-2 bg-yellow-100 border border-yellow-400 rounded text-xs">
            <strong>Informasi Cuti:</strong> <?php echo e($cutiText); ?> (Item dicoret karena cuti pada semester tersebut)
        </div>
    <?php endif; ?>

    
    <?php
        $biayaTambahan = $angsuran->details
            ->filter(function ($d) {
                $kode = $d->kode_biaya;
                return str_starts_with($kode, 'RUTIN-') ||
                    str_starts_with($kode, 'SP-') ||
                    str_starts_with($kode, 'BL-') ||
                    str_starts_with($kode, 'BT-');
            })
            ->sortBy(function ($detail) {
                preg_match('/S(\d+)-/', $detail->kode_biaya, $matches);
                $semester = (int) ($matches[1] ?? 0);
                $jenis = substr($detail->kode_biaya, 0, strpos($detail->kode_biaya, '-'));
                $prioritas = ['RUTIN' => 1, 'SP' => 2, 'BL' => 3, 'BT' => 4];
                return [$semester, $prioritas[$jenis] ?? 5];
            })
            ->values();

        // PERBAIKAN: Group biaya tambahan berdasarkan semester
        $groupedBiayaTambahan = $biayaTambahan->groupBy(function ($detail) {
            preg_match('/S(\d+)-/', $detail->kode_biaya, $matches);
            return 'Semester ' . ($matches[1] ?? '0');
        });
    ?>

    <?php if($biayaTambahan->count() > 0): ?>
        <div class="mb-4">
            <h3 class="font-bold text-xs mb-2 text-center">BIAYA LAINNYA</h3>
            <table class="w-full border border-gray-300">
                <thead>
                    <tr class="bg-orange-50">
                        <th class="border p-1 text-center w-8">No</th>
                        <th class="border p-1 text-center">Jenis Biaya</th>
                        <th class="border p-1 text-center">Komponen</th>
                        <th colspan="2" class="border p-1 text-center">Rencana</th>
                        <th colspan="2" class="border p-1 text-center">Realisasi</th>
                    </tr>
                    <tr class="bg-orange-100">
                        <th class="border p-1"></th>
                        <th class="border p-1"></th>
                        <th class="border p-1"></th>
                        <th class="border p-1 w-14">Tanggal</th>
                        <th class="border p-1 w-16">Rupiah</th>
                        <th class="border p-1 w-14">Tanggal</th>
                        <th class="border p-1 w-16">Rupiah</th>
                    </tr>
                </thead>
                <tbody>
                    <?php $__currentLoopData = $groupedBiayaTambahan; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $semester => $semesterDetails): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <tr>
                            <td colspan="7" class="bg-orange-200 font-semibold text-center border p-1">
                                <?php echo e($semester); ?>

                            </td>
                        </tr>
                        <?php $__currentLoopData = $semesterDetails; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $index => $detail): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <?php
                                $jenisBiaya = str_starts_with($detail->kode_biaya, 'RUTIN-')
                                    ? 'Biaya Rutin'
                                    : (str_starts_with($detail->kode_biaya, 'SP-')
                                        ? 'Semester Pendek'
                                        : (str_starts_with($detail->kode_biaya, 'BL-')
                                            ? 'Biaya Lain'
                                            : 'Biaya Tetap'));
                                $isCuti = $isItemOnCuti($detail);
                                // Tampilkan nilai asli jika potongan pending
                                $displayTotal = $detail->total;
                                $displaySisa = $detail->sisa;
                                if ($detail->total_asli && $detail->potongan_valid !== 'valid') {
                                    $displayTotal = $detail->total_asli;
                                    $displaySisa = $detail->total_asli - $detail->dibayar;
                                }
                            ?>
                            <tr class="<?php echo e($isCuti ? 'cuti-item' : ($index % 2 == 0 ? 'bg-white' : 'bg-orange-50')); ?>">
                                <td class="border p-1 text-center"><?php echo e($index + 1); ?></td>
                                <td class="border p-1"><?php echo e($jenisBiaya); ?></td>
                                <td class="border p-1">
                                    <?php if($isCuti): ?>
                                        <span class="line-through text-gray-400"><?php echo e($detail->komponen); ?></span>
                                        <span class="text-xs text-gray-500 ml-1">(Cuti Semester
                                            <?php echo e($detail->semester); ?>)</span>
                                    <?php else: ?>
                                        <?php echo e($detail->komponen); ?>

                                    <?php endif; ?>
                                </td>
                                <td class="border p-1 text-center">
                                    <?php if($isCuti): ?>
                                        <span
                                            class="line-through text-gray-400"><?php echo e(\Carbon\Carbon::parse($detail->tanggal_angsuran)->format('d-m-Y')); ?></span>
                                    <?php else: ?>
                                        <?php echo e(\Carbon\Carbon::parse($detail->tanggal_angsuran)->format('d-m-Y')); ?>

                                    <?php endif; ?>
                                </td>
                                <td class="border p-1 text-right">
                                    <?php if($isCuti): ?>
                                        <span class="line-through text-gray-400">Rp
                                            <?php echo e(number_format($displayTotal, 0, ',', '.')); ?></span>
                                    <?php else: ?>
                                        Rp <?php echo e(number_format($displayTotal, 0, ',', '.')); ?>

                                    <?php endif; ?>
                                </td>
                                <td class="border p-1 text-center">
                                    <?php if($isCuti): ?>
                                        <span class="line-through text-gray-400">-</span>
                                    <?php else: ?>
                                        <?php if($detail->tanggal_bayar): ?>
                                            <?php echo e(\Carbon\Carbon::parse($detail->tanggal_bayar)->format('d-m-Y')); ?>

                                        <?php else: ?>
                                            -
                                        <?php endif; ?>
                                    <?php endif; ?>
                                </td>
                                <td class="border p-1 text-right">
                                    <?php if($isCuti): ?>
                                        <span class="line-through text-gray-400">-</span>
                                    <?php else: ?>
                                        <?php if($detail->dibayar > 0): ?>
                                            Rp <?php echo e(number_format($detail->dibayar, 0, ',', '.')); ?>

                                        <?php else: ?>
                                            -
                                        <?php endif; ?>
                                    <?php endif; ?>
                                </td>
                            </tr>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        <tr class="bg-orange-100 font-semibold">
                            <td colspan="4" class="border p-1 text-right">Jumlah <?php echo e($semester); ?></td>
                            <td class="border p-1 text-right">Rp
                                <?php echo e(number_format($semesterDetails->sum('total'), 0, ',', '.')); ?></td>
                            <td class="border p-1 text-right">Jumlah</td>
                            <td class="border p-1 text-right">Rp
                                <?php echo e(number_format($semesterDetails->sum('dibayar'), 0, ',', '.')); ?></td>
                        </tr>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    <tr class="bg-orange-200 font-bold">
                        <td colspan="4" class="border p-1 text-right">TOTAL BIAYA LAINNYA</td>
                        <td class="border p-1 text-right">Rp
                            <?php echo e(number_format($biayaTambahan->sum('total'), 0, ',', '.')); ?></td>
                        <td class="border p-1 text-right">TOTAL</td>
                        <td class="border p-1 text-right">Rp
                            <?php echo e(number_format($biayaTambahan->sum('dibayar'), 0, ',', '.')); ?></td>
                    </tr>
                </tbody>
            </table>
        </div>
    <?php endif; ?>

    
    <?php
        $spbDetails = $angsuran->details
            ->filter(fn($d) => str_starts_with($d->kode_biaya, 'SPB'))
            ->sortBy(function ($d) {
                preg_match('/SPB_(\d+)/', $d->kode_biaya, $m);
                return (int) ($m[1] ?? 0);
            })
            ->values();

        $sppDetails = $angsuran->details
            ->filter(fn($d) => str_starts_with($d->kode_biaya, 'SPP'))
            ->sortBy(function ($d) {
                preg_match('/SPP(\d+)_(\d+)/', $d->kode_biaya, $m);
                return [(int) ($m[2] ?? 1), (int) ($m[1] ?? 0)];
            })
            ->values();

        $uktDetails = $angsuran->details
            ->filter(fn($d) => str_starts_with($d->kode_biaya, 'UKT'))
            ->sortBy(function ($d) {
                preg_match('/UKT(\d+)_(\d+)/', $d->kode_biaya, $m);
                return [(int) ($m[2] ?? 1), (int) ($m[1] ?? 0)];
            })
            ->values();

        $sppGrouped = $sppDetails->groupBy(function ($d) {
            preg_match('/SPP(\d+)_(\d+)/', $d->kode_biaya, $m);
            return 'Semester ' . ($m[2] ?? '1');
        });

        $uktGrouped = $uktDetails->groupBy(function ($d) {
            preg_match('/UKT(\d+)_(\d+)/', $d->kode_biaya, $m);
            return 'Semester ' . ($m[2] ?? '1');
        });
    ?>

    <div class="flex flex-row gap-4 mb-4">
        <?php if($spbDetails->count() > 0): ?>
            <div class="flex-1">
                <h3 class="font-bold text-xs mb-2 text-center">SUMBANGAN UANG GEDUNG (SPB)</h3>
                <table class="w-full border border-gray-300">
                    <thead>
                        <tr class="bg-blue-50">
                            <th class="border p-1 text-center w-8">No</th>
                            <th colspan="2" class="border p-1 text-center">Rencana</th>
                            <th colspan="2" class="border p-1 text-center">Realisasi</th>
                        </tr>
                        <tr class="bg-blue-100">
                            <th class="border p-1"></th>
                            <th class="border p-1 w-14">Tanggal</th>
                            <th class="border p-1 w-16">Rupiah</th>
                            <th class="border p-1 w-14">Tanggal</th>
                            <th class="border p-1 w-16">Rupiah</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php $__currentLoopData = $spbDetails; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $i => $d): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <?php
                                $isCuti = $isItemOnCuti($d);
                                $displayTotal = $d->total;
                                if ($d->total_asli && $d->potongan_valid !== 'valid') {
                                    $displayTotal = $d->total_asli;
                                }
                            ?>
                            <tr class="<?php echo e($isCuti ? 'cuti-item' : ($i % 2 == 0 ? 'bg-white' : 'bg-blue-50')); ?>">
                                <td class="border p-1 text-center"><?php echo e($i + 1); ?></td>
                                <td class="border p-1 text-center">
                                    <?php if($isCuti): ?>
                                        <span
                                            class="line-through text-gray-400"><?php echo e(\Carbon\Carbon::parse($d->tanggal_angsuran)->format('d-m-Y')); ?></span>
                                    <?php else: ?>
                                        <?php echo e(\Carbon\Carbon::parse($d->tanggal_angsuran)->format('d-m-Y')); ?>

                                    <?php endif; ?>
                                </td>
                                <td class="border p-1 text-right">
                                    <?php if($isCuti): ?>
                                        <span class="line-through text-gray-400">Rp
                                            <?php echo e(number_format($displayTotal, 0, ',', '.')); ?></span>
                                    <?php else: ?>
                                        Rp <?php echo e(number_format($displayTotal, 0, ',', '.')); ?>

                                    <?php endif; ?>
                                </td>
                                <td class="border p-1 text-center">
                                    <?php if($isCuti): ?>
                                        <span class="line-through text-gray-400">-</span>
                                    <?php else: ?>
                                        <?php if($d->tanggal_bayar): ?>
                                            <?php echo e(\Carbon\Carbon::parse($d->tanggal_bayar)->format('d-m-Y')); ?>

                                        <?php else: ?>
                                            -
                                        <?php endif; ?>
                                    <?php endif; ?>
                                </td>
                                <td class="border p-1 text-right">
                                    <?php if($isCuti): ?>
                                        <span class="line-through text-gray-400">-</span>
                                    <?php else: ?>
                                        <?php if($d->dibayar > 0): ?>
                                            Rp <?php echo e(number_format($d->dibayar, 0, ',', '.')); ?>

                                        <?php else: ?>
                                            -
                                        <?php endif; ?>
                                    <?php endif; ?>
                                </td>
                            </tr>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        <tr class="bg-blue-100 font-semibold">
                            <td colspan="2" class="border p-1 text-right">Jumlah SPB</td>
                            <td class="border p-1 text-right">Rp
                                <?php echo e(number_format($spbDetails->sum('total'), 0, ',', '.')); ?></td>
                            <td class="border p-1 text-right">Jumlah</td>
                            <td class="border p-1 text-right">Rp
                                <?php echo e(number_format($spbDetails->sum('dibayar'), 0, ',', '.')); ?></td>
                        </tr>
                    </tbody>
                </table>
            </div>
        <?php endif; ?>

        <?php if($sppDetails->count() > 0): ?>
            <div class="flex-1">
                <h3 class="font-bold text-xs mb-2 text-center">SUMBANGAN PENDIDIKAN PERSEMESTER (SPP)</h3>
                <?php $__currentLoopData = $sppGrouped; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $semester => $details): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <div class="border border-gray-300 mb-1">
                        <div class="bg-green-200 font-semibold text-center p-1 border-b"><?php echo e($semester); ?></div>
                        <table class="w-full">
                            <thead>
                                <tr class="bg-green-50">
                                    <th class="border p-1 text-center w-12">Angsuran Ke-</th>
                                    <th colspan="2" class="border p-1 text-center">Rencana</th>
                                    <th colspan="2" class="border p-1 text-center">Realisasi</th>
                                </tr>
                                <tr class="bg-green-100">
                                    <th class="border p-1"></th>
                                    <th class="border p-1 w-14">Tanggal</th>
                                    <th class="border p-1 w-16">Rupiah</th>
                                    <th class="border p-1 w-14">Tanggal</th>
                                    <th class="border p-1 w-16">Rupiah</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php $__currentLoopData = $details; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $idx => $d): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <?php
                                        preg_match('/SPP(\d+)_(\d+)/', $d->kode_biaya, $m);
                                        $angsuranKe = $m[1] ?? $idx + 1;
                                        $isCuti = $isItemOnCuti($d);
                                        $displayTotal = $d->total;
                                        if ($d->total_asli && $d->potongan_valid !== 'valid') {
                                            $displayTotal = $d->total_asli;
                                        }
                                    ?>
                                    <tr
                                        class="<?php echo e($isCuti ? 'cuti-item' : ($idx % 2 == 0 ? 'bg-white' : 'bg-green-50')); ?>">
                                        <td class="border p-1 text-center"><?php echo e($angsuranKe); ?></td>
                                        <td class="border p-1 text-center">
                                            <?php if($isCuti): ?>
                                                <span
                                                    class="line-through text-gray-400"><?php echo e(\Carbon\Carbon::parse($d->tanggal_angsuran)->format('d-m-Y')); ?></span>
                                            <?php else: ?>
                                                <?php echo e(\Carbon\Carbon::parse($d->tanggal_angsuran)->format('d-m-Y')); ?>

                                            <?php endif; ?>
                                        </td>
                                        <td class="border p-1 text-right">
                                            <?php if($isCuti): ?>
                                                <span class="line-through text-gray-400">Rp
                                                    <?php echo e(number_format($displayTotal, 0, ',', '.')); ?></span>
                                            <?php else: ?>
                                                Rp <?php echo e(number_format($displayTotal, 0, ',', '.')); ?>

                                            <?php endif; ?>
                                        </td>
                                        <td class="border p-1 text-center">
                                            <?php if($isCuti): ?>
                                                <span class="line-through text-gray-400">-</span>
                                            <?php else: ?>
                                                <?php if($d->tanggal_bayar): ?>
                                                    <?php echo e(\Carbon\Carbon::parse($d->tanggal_bayar)->format('d-m-Y')); ?>

                                                <?php else: ?>
                                                    -
                                                <?php endif; ?>
                                            <?php endif; ?>
                                        </td>
                                        <td class="border p-1 text-right">
                                            <?php if($isCuti): ?>
                                                <span class="line-through text-gray-400">-</span>
                                            <?php else: ?>
                                                <?php if($d->dibayar > 0): ?>
                                                    Rp <?php echo e(number_format($d->dibayar, 0, ',', '.')); ?>

                                                <?php else: ?>
                                                    -
                                                <?php endif; ?>
                                            <?php endif; ?>
                                        </td>
                                    </tr>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                <tr class="bg-green-100 font-semibold">
                                    <td colspan="2" class="border p-1 text-right">Jumlah <?php echo e($semester); ?></td>
                                    <td class="border p-1 text-right">Rp
                                        <?php echo e(number_format($details->sum('total'), 0, ',', '.')); ?></td>
                                    <td class="border p-1 text-right">Jumlah</td>
                                    <td class="border p-1 text-right">Rp
                                        <?php echo e(number_format($details->sum('dibayar'), 0, ',', '.')); ?></td>
                                </tr>
                            </tbody>
                        </table>
                    </div>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            </div>
        <?php endif; ?>

        <?php if($uktDetails->count() > 0): ?>
            <div class="flex-1">
                <h3 class="font-bold text-xs mb-2 text-center">UANG KULIAH TUNGGAL (UKT)</h3>
                <?php $__currentLoopData = $uktGrouped; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $semester => $details): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <div class="border border-gray-300 mb-1">
                        <div class="bg-purple-200 font-semibold text-center p-1 border-b"><?php echo e($semester); ?></div>
                        <table class="w-full">
                            <thead>
                                <tr class="bg-purple-50">
                                    <th class="border p-1 text-center w-12">Angsuran Ke-</th>
                                    <th colspan="2" class="border p-1 text-center">Rencana</th>
                                    <th colspan="2" class="border p-1 text-center">Realisasi</th>
                                </tr>
                                <tr class="bg-purple-100">
                                    <th class="border p-1"></th>
                                    <th class="border p-1 w-14">Tanggal</th>
                                    <th class="border p-1 w-16">Rupiah</th>
                                    <th class="border p-1 w-14">Tanggal</th>
                                    <th class="border p-1 w-16">Rupiah</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php $__currentLoopData = $details; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $idx => $d): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <?php
                                        preg_match('/UKT(\d+)_(\d+)/', $d->kode_biaya, $m);
                                        $angsuranKe = $m[1] ?? $idx + 1;
                                        $isCuti = $isItemOnCuti($d);
                                        $displayTotal = $d->total;
                                        if ($d->total_asli && $d->potongan_valid !== 'valid') {
                                            $displayTotal = $d->total_asli;
                                        }
                                    ?>
                                    <tr
                                        class="<?php echo e($isCuti ? 'cuti-item' : ($idx % 2 == 0 ? 'bg-white' : 'bg-purple-50')); ?>">
                                        <td class="border p-1 text-center"><?php echo e($angsuranKe); ?></td>
                                        <td class="border p-1 text-center">
                                            <?php if($isCuti): ?>
                                                <span
                                                    class="line-through text-gray-400"><?php echo e(\Carbon\Carbon::parse($d->tanggal_angsuran)->format('d-m-Y')); ?></span>
                                            <?php else: ?>
                                                <?php echo e(\Carbon\Carbon::parse($d->tanggal_angsuran)->format('d-m-Y')); ?>

                                            <?php endif; ?>
                                        </td>
                                        <td class="border p-1 text-right">
                                            <?php if($isCuti): ?>
                                                <span class="line-through text-gray-400">Rp
                                                    <?php echo e(number_format($displayTotal, 0, ',', '.')); ?></span>
                                            <?php else: ?>
                                                Rp <?php echo e(number_format($displayTotal, 0, ',', '.')); ?>

                                            <?php endif; ?>
                                        </td>
                                        <td class="border p-1 text-center">
                                            <?php if($isCuti): ?>
                                                <span class="line-through text-gray-400">-</span>
                                            <?php else: ?>
                                                <?php if($d->tanggal_bayar): ?>
                                                    <?php echo e(\Carbon\Carbon::parse($d->tanggal_bayar)->format('d-m-Y')); ?>

                                                <?php else: ?>
                                                    -
                                                <?php endif; ?>
                                            <?php endif; ?>
                                        </td>
                                        <td class="border p-1 text-right">
                                            <?php if($isCuti): ?>
                                                <span class="line-through text-gray-400">-</span>
                                            <?php else: ?>
                                                <?php if($d->dibayar > 0): ?>
                                                    Rp <?php echo e(number_format($d->dibayar, 0, ',', '.')); ?>

                                                <?php else: ?>
                                                    -
                                                <?php endif; ?>
                                            <?php endif; ?>
                                        </td>
                                    </tr>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                <tr class="bg-purple-100 font-semibold">
                                    <td colspan="2" class="border p-1 text-right">Jumlah <?php echo e($semester); ?></td>
                                    <td class="border p-1 text-right">Rp
                                        <?php echo e(number_format($details->sum('total'), 0, ',', '.')); ?></td>
                                    <td class="border p-1 text-right">Jumlah</td>
                                    <td class="border p-1 text-right">Rp
                                        <?php echo e(number_format($details->sum('dibayar'), 0, ',', '.')); ?></td>
                                </tr>
                            </tbody>
                        </table>
                    </div>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            </div>
        <?php endif; ?>
    </div>

    
    <div class="mt-4 p-3 border border-gray-300 rounded bg-yellow-50">
        <div class="grid grid-cols-2 gap-4">
            <div>
                <p class="text-xs"><strong>Total Tagihan:</strong> Rp
                    <?php echo e(number_format($angsuran->total, 0, ',', '.')); ?></p>
                <p class="text-xs"><strong>Total Dibayar:</strong> Rp
                    <?php echo e(number_format($angsuran->total - $angsuran->sisa, 0, ',', '.')); ?></p>
            </div>
            <div>
                <p class="text-xs"><strong>Sisa Tagihan:</strong> Rp <?php echo e(number_format($angsuran->sisa, 0, ',', '.')); ?>

                </p>
                <p class="text-xs"><strong>Status:</strong> <span
                        class="<?php echo e($angsuran->sisa <= 0 ? 'text-green-600 font-bold' : 'text-red-600 font-bold'); ?>"><?php echo e($angsuran->sisa <= 0 ? 'LUNAS' : 'BELUM LUNAS'); ?></span>
                </p>
            </div>
        </div>
        <?php if($cutiText): ?>
            <p class="text-xs mt-1 text-orange-600"><strong>Catatan:</strong> Item semester yang dicoret adalah history
                cuti (Semester <?php echo e(implode(', ', $cutiList)); ?>) dan tidak wajib dibayar.</p>
        <?php endif; ?>
    </div>
</div>

<style>
    .preview-container {
        font-family: 'Arial', sans-serif;
        line-height: 1.2;
        font-size: 10px;
    }

    .preview-container table {
        border-collapse: collapse;
        width: 100%;
    }

    .preview-container th,
    .preview-container td {
        border: 1px solid #ddd;
        padding: 2px 4px;
        font-size: 9px;
    }

    .preview-container .bg-blue-50 {
        background-color: #eff6ff;
    }

    .preview-container .bg-blue-100 {
        background-color: #dbeafe;
    }

    .preview-container .bg-green-50 {
        background-color: #f0fdf4;
    }

    .preview-container .bg-green-100 {
        background-color: #dcfce7;
    }

    .preview-container .bg-green-200 {
        background-color: #bbf7d0;
    }

    .preview-container .bg-purple-50 {
        background-color: #f3e8ff;
    }

    .preview-container .bg-purple-100 {
        background-color: #e9d5ff;
    }

    .preview-container .bg-purple-200 {
        background-color: #d8b4fe;
    }

    .preview-container .bg-yellow-50 {
        background-color: #fefce8;
    }

    .preview-container .bg-orange-50 {
        background-color: #fff7ed;
    }

    .preview-container .bg-orange-100 {
        background-color: #ffedd5;
    }

    .preview-container .bg-orange-200 {
        background-color: #fed7aa;
    }

    .preview-container .flex {
        display: flex;
    }

    .preview-container .flex-row {
        flex-direction: row;
    }

    .preview-container .flex-1 {
        flex: 1;
    }

    .preview-container .gap-4 {
        gap: 1rem;
    }

    .preview-container .cuti-item {
        background-color: #f3f4f6 !important;
        opacity: 0.7;
    }

    .preview-container .line-through {
        text-decoration: line-through;
    }

    .preview-container .cuti-item:hover {
        opacity: 0.9;
    }
</style>
<?php /**PATH C:\Users\User\Documents\K2-PROJECTS\k2-sipema\resources\views/angsuran/preview.blade.php ENDPATH**/ ?>