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

<?= $this->section('email_content') ?>
<div style="font-size:16px; line-height:1.5;">
    <?php
    // Normalize: $studentName may be string or array
    $isMulti = isset($studentName) && is_array($studentName) && !empty($studentName);

    // Build a readable “A and B”/“A, B, and C” label for singular spots if needed
    $studentLabel = '';
    if ($isMulti) {
        $names = array_map(static fn($n) => trim($n), $studentName);
        if (count($names) === 1) {
            $studentLabel = $names[0];
            $isMulti = false; // effectively single
        } elseif (count($names) === 2) {
            $studentLabel = $names[0] . ' and ' . $names[1];
        } else {
            $last = array_pop($names);
            $studentLabel = implode(', ', $names) . ', and ' . $last;
        }
    } else {
        $studentLabel = $studentName ?? 'your student';
    }
    ?>

    <p>Dear <?= esc($parentName ?? 'Parent') ?>,</p>

    <?php if ($isMulti): ?>
        <p>
            Thank you for your interest in our school and for applying for admission for the following <?= count($studentName) ?> students:
        </p>
        <ul style="padding-left:20px;">
            <?php foreach ($studentName as $name): ?>
                <li><?= esc($name) ?></li>
            <?php endforeach; ?>
        </ul>

        <p>
            After careful review, we are unable to grant immediate admission at this time. However, we are pleased to place these students on our waitlist for the upcoming school year. Should seats become available, we will notify you right away.
        </p>

        <p>
            We understand this may not be the outcome you had hoped for, but please know that your applications remain active and under consideration. In the meantime, you may check the status of your applications at any time through the parent portal.
        </p>
    <?php else: ?>
        <p>
            Thank you for your interest in our school and for applying for <?= esc($studentLabel) ?>’s admission.
        </p>

        <p>
            After careful review, we are unable to grant immediate admission at this time. However, we are pleased to place <?= esc($studentLabel) ?> on our waitlist for the upcoming school year. Should a seat become available, we will notify you right away.
        </p>

        <p>
            We understand this may not be the outcome you had hoped for, but please know that the application remains active and under consideration. In the meantime, you may check the status of the application at any time through the parent portal.
        </p>
    <?php endif; ?>

    <p style="margin:16px 0;">
        <a href="<?= 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>Best regards,<br>Admissions Committee</p>
</div>
<?= $this->endSection() ?>