<?php

if (!function_exists('brand_email_wrap')) {
    /**
     * Wrap email body content in the project-standard branded layout —
     * orange header, white content card, grey footer with brand + reply-to.
     * Used by the order confirmation; reused by password reset and any
     * future transactional email so the project's emails stay consistent.
     */
    function brand_email_wrap(string $bodyHtml, ?string $replyToEmail = null): string
    {
        $brand   = '#FF4800';
        $ink     = '#1A1A1A';
        $muted   = '#6B7280';
        $soft    = '#9CA3AF';
        $divider = '#E5E7EB';
        $page    = '#F4F4F4';

        $footerReply = '';
        if (!empty($replyToEmail)) {
            $footerReply = '<div style="font-size:11px; color:' . $soft . '; line-height:1.6; margin-top:4px;">'
                . 'For assistance, reply to this email or contact '
                . '<a href="mailto:' . esc($replyToEmail) . '" style="color:' . $muted . ';">' . esc($replyToEmail) . '</a>.'
                . '</div>';
        }

        $html  = '<!doctype html><html><body style="margin:0; padding:0; background:' . $page . '; font-family:Helvetica,Arial,sans-serif; color:' . $ink . ';">';
        $html .= '<table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0" style="background:' . $page . '; padding:32px 12px;"><tr><td align="center">';
        $html .= '<table role="presentation" width="600" cellpadding="0" cellspacing="0" border="0" style="background:#ffffff; max-width:600px;">';

        $html .= '<tr><td style="background:' . $brand . '; padding:22px 32px;">';
        $html .= '<div style="color:#ffffff; font-size:20px; font-weight:800; letter-spacing:-0.2px;">United Wholesale Scotland</div>';
        $html .= '</td></tr>';

        $html .= '<tr><td style="padding:32px 32px 24px 32px; font-size:14px; line-height:1.55; color:' . $ink . ';">';
        $html .= $bodyHtml;
        $html .= '</td></tr>';

        $html .= '<tr><td style="background:#FAFAFA; padding:24px 32px; border-top:1px solid ' . $divider . ';">';
        $html .= '<div style="font-size:12px; color:' . $muted . '; line-height:1.6;"><strong style="color:' . $ink . ';">United Wholesale Scotland Ltd</strong></div>';
        $html .= $footerReply;
        $html .= '</td></tr>';

        $html .= '</table></td></tr></table></body></html>';
        return $html;
    }
}
