<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>Form Pengajuan Bonus RAP</title>

    <style>
        body {
            font-family: Arial, sans-serif;
            font-size: 9px;
            line-height: 1.2;
            margin: 10px;
            color: #000;
        }

        .title {
            text-align: center;
            margin-bottom: 6px;
            border-bottom: 2px solid #000;
            padding-bottom: 3px;
        }

        .title h1 {
            margin: 0;
            font-size: 13px;
        }

        .title p {
            margin: 0;
            font-size: 9px;
        }

        .rap-item {
            margin-bottom: 10px;
            padding-bottom: 6px;
            border-bottom: 1px dashed #999;
        }

        .info-rap table {
            width: 100%;
            border-collapse: collapse;
            margin-bottom: 4px;
        }

        .info-rap td {
            padding: 1px 3px;
            font-size: 9px;
        }

        .info-label {
            font-weight: bold;
            width: 70px;
        }

        h4 {
            margin: 4px 0 2px;
            font-size: 10px;
        }

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

        table.bonus th,
        table.bonus td {
            border: 1px solid #000;
            padding: 2px;
            font-size: 9px;
        }

        table.bonus th {
            text-align: center;
            background-color: #f0f0f0;
        }

        .total {
            margin-top: 3px;
            text-align: right;
            font-size: 10px;
            font-weight: bold;
        }

        .total span {
            font-size: 8px;
            font-weight: normal;
        }

        /* TTD DI AKHIR */
        .signature {
            margin-top: 20px;
        }

        .signature table {
            width: 100%;
            text-align: center;
        }

        .signature td {
            padding-top: 25px;
        }

        .signature-name {
            margin-top: 30px;
            font-weight: bold;
            text-decoration: underline;
        }

        .footer {
            position: fixed;
            bottom: 5px;
            right: 10px;
            font-size: 8px;
        }
    </style>
</head>

<body>

    <!-- JUDUL SEKALI SAJA -->
    <div class="title">
        <h1>FORM PENGAJUAN BONUS RAP</h1>
        <p>Recruitment Affiliate Program - Bonus Tambahan</p>
    </div>

    <!-- LOOP RAP -->
    @foreach ($data as $item)
        <div class="rap-item">

            <div class="info-rap">
                <table>
                    <tr>
                        <td class="info-label">Nama RAP</td>
                        <td>: {{ $item['rap']->nama }}</td>

                        <td class="info-label">No. HP</td>
                        <td>: {{ $item['rap']->no_hp }}</td>
                    </tr>
                    <tr>
                        <td class="info-label">Bank/E-Wallet</td>
                        <td>: {{ $item['rap']->bank_ewallet ?? '-' }}</td>

                        <td class="info-label">No. Rekening</td>
                        <td>: {{ $item['rap']->no_rekening ?? '-' }}</td>
                    </tr>
                    <tr>
                        <td class="info-label">Marketing</td>
                        <td>: {{ $item['rap']->marketing ?? '-' }}</td>

                        <td class="info-label">Tipe</td>
                        <td>: {{ $item['rap']->tipe == 'mahasiswa' ? 'Mahasiswa' : 'Non Mahasiswa' }}</td>
                    </tr>
                </table>
            </div>

            <h4>Detail Bonus yang Diajukan</h4>

            <table class="bonus">
                <thead>
                    <tr>
                        <th width="3%">No</th>
                        <th width="14%">Tahun Ajaran</th>
                        <th width="12%">Total Mahasiswa</th>
                        <th width="10%">Rule Bonus</th>
                        <th width="14%">Nominal Bonus</th>
                        <th width="12%">Tgl Validasi</th>
                        <th width="12%">Tgl Pengajuan</th>
                    </tr>
                </thead>
                <tbody>
                    @foreach ($item['bonus_list'] as $idx => $bonus)
                        <tr>
                            <td align="center">{{ $idx + 1 }}</td>
                            <td align="center">{{ $bonus->tahun_ajaran }}</td>
                            <td align="center">{{ $item['rap']->getMahasiswaByTahunAjaran($bonus->tahun_ajaran) }}
                                Mahasiswa</td>
                            <td align="center">
                                @php
                                    $bonusRule = $item['rap']->getBonusRuleByTahunAjaran($bonus->tahun_ajaran);
                                    echo $bonusRule ? $bonusRule->nama_rule : '-';
                                @endphp
                            </td>
                            <td align="right">Rp {{ number_format($bonus->nominal, 0, ',', '.') }}</td>
                            <td align="center">
                                {{ $bonus->tanggal_validasi
                                    ? (is_string($bonus->tanggal_validasi)
                                        ? \Carbon\Carbon::parse($bonus->tanggal_validasi)->format('d/m/Y')
                                        : $bonus->tanggal_validasi->format('d/m/Y'))
                                    : '-' }}
                            </td>
                            <td align="center">
                                {{ $bonus->tanggal_pengajuan
                                    ? (is_string($bonus->tanggal_pengajuan)
                                        ? \Carbon\Carbon::parse($bonus->tanggal_pengajuan)->format('d/m/Y')
                                        : $bonus->tanggal_pengajuan->format('d/m/Y'))
                                    : '-' }}
                            </td>
                        </tr>
                    @endforeach
                </tbody>
            </table>

            <div class="total">
                <span>Total Bonus: </span> Rp {{ number_format($item['total_bonus'], 0, ',', '.') }}
            </div>

        </div>
    @endforeach

    <!-- TTD SEKALI DI AKHIR -->
    <div class="signature">
        <table>
            <tr>
                <td>
                    Mengajukan<br>
                    <span class="signature-name">{{ $data[0]['pengaju'] ?? 'Bandi' }}</span>
                </td>
                <td>
                    Menyetujui<br>
                    <span class="signature-name">Priyadi</span>
                </td>
            </tr>
        </tr>
    </div>

    <div class="footer">
        {{ now()->format('d/m/Y H:i') }}
    </div>

</body>

</html>
