<?= $this->extend('layout/email_layout') ?>

<?= $this->section('content') ?>
<div style="font-size:16px; font-family:Arial, Helvetica, sans-serif; color:#333;">
    <p>Dear <?= esc($parentName ?? '') ?>,</p>

    <p>We have received your payment. Below are the details of your transaction:</p>

    <table border="0" cellpadding="8" cellspacing="0" style="border-collapse:collapse; width:100%; font-size:16px;">
        <tr style="background-color:#f5f5f5;">
            <td><strong>Invoice Number:</strong></td>
            <td>
                #<?= esc(($invoiceNumber ?? null) !== null && $invoiceNumber !== '' ? $invoiceNumber : ($invoiceId ?? '')) ?>
            </td>
        </tr>
        <tr>
            <td><strong>Transaction ID:</strong></td>
            <td><?= esc($transactionId ?? '') ?></td>
        </tr>
        <tr style="background-color:#f5f5f5;">
            <td><strong>Payment Date:</strong></td>
            <td><?= esc($paymentDate ?? '') ?></td>
        </tr>
        <tr>
            <td><strong>Payment Method:</strong></td>
            <td>
                <?= esc($method ?? '') ?>
                <?php if (!empty($checkNumber)): ?>
                    (Check #<?= esc($checkNumber) ?>)
                <?php endif; ?>
            </td>
        </tr>
        <tr style="background-color:#f5f5f5;">
            <td><strong>Installment #:</strong></td>
            <td><?= esc((string)($installmentSeq ?? '')) ?></td>
        </tr>
        <tr>
            <td><strong>Amount Paid:</strong></td>
            <td><strong style="color:green;"><?= esc($amount ?? '$0.00') ?></strong></td>
        </tr>

        <?php if (!empty($invoiceDiscount)): ?>
            <tr style="background-color:#f5f5f5;">
                <td><strong>Discount Applied (This Invoice):</strong></td>
                <td><?= esc($invoiceDiscount) ?></td>
            </tr>
        <?php endif; ?>

        <tr style="background-color:#f5f5f5;">
            <td><strong>Total Invoice Amount:</strong></td>
            <td><?= esc($invoiceTotal ?? '$0.00') ?></td>
        </tr>
        <tr>
            <td><strong>Previous Balance:</strong></td>
            <td><?= esc($preBalance ?? '$0.00') ?></td>
        </tr>
        <tr style="background-color:#f5f5f5;">
            <td><strong>New Balance:</strong></td>
            <td><strong><?= esc($postBalance ?? '$0.00') ?></strong></td>
        </tr>
    </table>

    <?php if (!empty($students) && is_array($students)): ?>
        <p style="margin-top:20px;"><strong>Students linked to this invoice:</strong></p>
        <ul>
            <?php foreach ($students as $s): ?>
                <li><?= esc(trim(($s['firstname'] ?? '') . ' ' . ($s['lastname'] ?? ''))) ?></li>
            <?php endforeach; ?>
        </ul>
    <?php endif; ?>

    <p style="margin-top:16px;">
        You can view this invoice and your full payment history in your account:
    </p>

    <p>
        <a href="<?= esc($portalLink ?? base_url()) ?>" target="_blank" rel="noopener"
            style="display:inline-block; padding:10px 16px; text-decoration:none; border-radius:6px;
                background:#198754; color:#ffffff; font-weight:600; font-size:16px;">
            Access My Account
        </a>
    </p>

    <p>Thank you for your payment and continued support.</p>

    <p style="margin-top:20px;">Warm regards,<br>
        <strong>Al Rahma Sunday School</strong>
    </p>
</div>
<?= $this->endSection() ?>