<?php
/**
 * email_template.php
 * One consistent, good-looking HTML email shell used for every kind of
 * notification (OTP, login alert, subscription reminder, etc.) so emails
 * don't look like plain unstyled text.
 */

/**
 * @param string $brandName
 * @param string $headline      Big bold line at the top of the card
 * @param string $bodyHtml      Inner content (already-safe HTML)
 * @param string|null $ctaText  Optional button text
 * @param string|null $ctaUrl   Optional button link
 */
function render_email_template($brandName, $headline, $bodyHtml, $ctaText = null, $ctaUrl = null) {
    $year = date('Y');
    $ctaBlock = '';
    if ($ctaText && $ctaUrl) {
        $ctaBlock = '
        <tr><td style="padding:28px 40px 6px;text-align:center">
            <a href="' . htmlspecialchars($ctaUrl) . '" style="display:inline-block;background:linear-gradient(135deg,#6c63ff,#e040fb);color:#ffffff;text-decoration:none;font-weight:700;font-size:15px;padding:14px 34px;border-radius:10px">' . htmlspecialchars($ctaText) . '</a>
        </td></tr>';
    }

    return '<!DOCTYPE html>
<html>
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"></head>
<body style="margin:0;padding:0;background:#f2f1f8;font-family:-apple-system,Segoe UI,Roboto,Helvetica,Arial,sans-serif">
<table role="presentation" width="100%" cellpadding="0" cellspacing="0" style="background:#f2f1f8;padding:32px 12px">
<tr><td align="center">
<table role="presentation" width="100%" cellpadding="0" cellspacing="0" style="max-width:520px;background:#ffffff;border-radius:18px;overflow:hidden;box-shadow:0 6px 24px rgba(20,20,40,.08)">

<tr><td style="background:linear-gradient(135deg,#6c63ff,#e040fb);padding:26px 40px;text-align:center">
    <span style="color:#ffffff;font-size:22px;font-weight:800;letter-spacing:.3px">' . htmlspecialchars($brandName) . '</span>
</td></tr>

<tr><td style="padding:34px 40px 4px">
    <h1 style="margin:0 0 18px;font-size:20px;color:#14141f;font-weight:800">' . htmlspecialchars($headline) . '</h1>
    <div style="font-size:14.5px;line-height:1.7;color:#3a3a4a">' . $bodyHtml . '</div>
</td></tr>
' . $ctaBlock . '

<tr><td style="padding:30px 40px 26px">
    <div style="border-top:1px solid #eeeef4;padding-top:18px;font-size:12px;color:#9a9aab;line-height:1.6">
        Yeh ek automated security email hai, is par reply na karein.<br>
        &copy; ' . $year . ' ' . htmlspecialchars($brandName) . '. All rights reserved.
    </div>
</td></tr>

</table>
</td></tr>
</table>
</body>
</html>';
}

/**
 * A large, easy-to-read OTP code block for the email body.
 */
function render_otp_block($otp) {
    return '<div style="text-align:center;margin:22px 0">
        <div style="display:inline-block;background:#f4f3fb;border:1.5px dashed #6c63ff;border-radius:12px;padding:16px 34px;font-size:32px;font-weight:800;letter-spacing:10px;color:#4a3fd6">' . htmlspecialchars($otp) . '</div>
    </div>';
}
