<?php

declare(strict_types=1);

if (!function_exists('af_public_e')) {
    function af_public_e(mixed $value): string
    {
        return htmlspecialchars((string) $value, ENT_QUOTES, 'UTF-8');
    }
}

$afPublicBrand = trim((string) ($ui_title_system ?? 'Ave Fénix')) ?: 'Ave Fénix';
$afPublicFooterSubtitle = trim((string) ($ui_footer_subtitle ?? 'Soporte y acceso seguro'));
$afPublicFooterIcon = trim((string) ($ui_footer_icon_path ?? ''));
$afPublicSupportLabel = trim((string) ($ui_footer_support_text ?? 'Soporte')) ?: 'Soporte';
$afPublicSupport = preg_replace('/\D+/', '', (string) ($ui_support_whatsapp_number ?? ''));
$afPublicSupportText = rawurlencode((string) ($ui_support_whatsapp_message ?? 'Hola, necesito soporte con la plataforma.'));
$afPublicSupportUrl = $afPublicSupport !== ''
    ? 'https://wa.me/' . $afPublicSupport . '?text=' . $afPublicSupportText
    : (!empty($ui_support_email) ? 'mailto:' . (string) $ui_support_email : '');
$afFooterLegal = trim((string) ($ui_footer_text ?? ''));
if ($afFooterLegal === '') {
    $afFooterLegal = '© ' . date('Y') . ' ' . $afPublicBrand . '. Todos los derechos reservados.';
}

$afFooterBg = (string) ($ui_color_footer_hex ?? '#08111f');
$afFooterText = (string) ($ui_color_footer_text_hex ?? '#cbd5e1');
$afFooterIconColor = (string) ($ui_color_public_icons_hex ?? $ui_color_primary_bg_hex ?? '#dc2626');
?>
<style>
.public-footer{min-height:66px;background:<?= af_public_e($afFooterBg) ?>!important;color:<?= af_public_e($afFooterText) ?>!important;border-top-color:<?= af_public_e($afFooterIconColor) ?>!important}
.public-footer .public-footer-inner{width:min(1380px,calc(100% - 32px));min-height:63px;margin:0 auto;display:grid;grid-template-columns:minmax(210px,.8fr) minmax(280px,1.35fr) minmax(150px,.65fr);align-items:center;gap:18px}
.public-footer-copy,.public-footer-brand small,.public-footer-links a{color:<?= af_public_e($afFooterText) ?>!important}.public-footer-copy{font-size:10px;text-align:center;line-height:1.4}.public-footer-support i{color:<?= af_public_e($afFooterIconColor) ?>!important}.public-footer-mark{overflow:hidden;background:#fff;color:var(--public-red)}.public-footer-mark img,.public-footer-mark svg{width:100%;height:100%;object-fit:cover;padding:3px}.public-footer-support{display:inline-flex;align-items:center;gap:6px;padding:7px 11px;border:1px solid rgba(255,255,255,.14);border-radius:9px;background:rgba(255,255,255,.06)}.public-footer-links--support{display:flex;justify-content:flex-end}
@media(max-width:760px){.public-footer{min-height:auto}.public-footer .public-footer-inner{min-height:auto;padding:13px 0;grid-template-columns:1fr;justify-items:center;gap:8px}.public-footer-copy{text-align:center}.public-footer-links--support{justify-content:center}.public-footer-brand{text-align:left}}
</style>
<footer class="public-footer" data-public-footer>
    <div class="public-footer-inner">
        <a href="index.php" class="public-footer-brand">
            <span class="public-footer-mark <?= $afPublicFooterIcon !== '' ? 'has-image' : '' ?>">
                <?php if ($afPublicFooterIcon !== ''): ?><img src="<?= af_public_e($afPublicFooterIcon) ?>" alt="Streaming" onerror="this.style.display='none';this.nextElementSibling.style.display='block'"><?php endif; ?>
                <svg viewBox="0 0 64 64" role="img" aria-label="Smart TV"<?= $afPublicFooterIcon !== '' ? ' style="display:none"' : '' ?>><rect x="7" y="12" width="50" height="36" rx="7" fill="#0f172a"/><rect x="11" y="16" width="42" height="28" rx="4" fill="url(#tvGradient)"/><path d="M28 23.5 42 30 28 36.5Z" fill="#fff"/><path d="M24 54h16M31 48v6M33 48v6" stroke="#0f172a" stroke-width="4" stroke-linecap="round"/><defs><linearGradient id="tvGradient" x1="11" y1="16" x2="53" y2="44"><stop stop-color="<?= af_public_e($afFooterIconColor) ?>"/><stop offset="1" stop-color="<?= af_public_e($ui_color_secondary_hex ?? $afFooterIconColor) ?>"/></linearGradient></defs></svg>
            </span>
            <span><strong><?= af_public_e($afPublicBrand) ?></strong><small><?= af_public_e($afPublicFooterSubtitle) ?></small></span>
        </a>
        <div class="public-footer-copy"><?= af_public_e($afFooterLegal) ?></div>
        <nav class="public-footer-links public-footer-links--support" aria-label="Soporte">
            <?php if ($afPublicSupportUrl !== ''): ?><a class="public-footer-support" href="<?= af_public_e($afPublicSupportUrl) ?>"<?= str_starts_with($afPublicSupportUrl, 'http') ? ' target="_blank" rel="noopener"' : '' ?>><i class="fas fa-headset"></i> <?= af_public_e($afPublicSupportLabel) ?></a><?php endif; ?>
        </nav>
    </div>
</footer>
