<?php
require_once __DIR__ . '/../includes/functions.php';

$settings = get_support_settings();
$branding = get_branding();
$waUrl = build_support_whatsapp_url($settings);
$logo = $branding['logo_url'] ?? '';
$message = $settings['whatsapp_message'] ?? 'Ola, vim pelo aplicativo. Preciso de suporte ou renovacao.';
$qrUrl = $waUrl !== '' ? 'https://api.qrserver.com/v1/create-qr-code/?size=260x260&margin=10&data=' . rawurlencode($waUrl) : '';

header('Content-Type: text/html; charset=utf-8');
header('Access-Control-Allow-Origin: *');
?><!DOCTYPE html>
<html lang="pt-BR">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
    html,body{margin:0;padding:0;width:100%;height:100%;background:#fff;font-family:Arial,Helvetica,sans-serif;overflow:hidden;}
    .wrap{width:100%;height:100%;display:flex;align-items:center;justify-content:center;background:#fff;color:#111;}
    .box{text-align:center;width:100%;height:100%;display:flex;flex-direction:column;align-items:center;justify-content:center;padding:6px;box-sizing:border-box;}
    .logo{max-width:82px;max-height:38px;object-fit:contain;margin-bottom:4px;}
    .qr{width:135px;height:135px;object-fit:contain;display:block;}
    .title{font-weight:800;font-size:12px;color:#4b118e;margin-top:4px;line-height:1.1;}
    .sub{font-size:9px;color:#555;margin-top:2px;line-height:1.15;}
    .warn{font-size:11px;color:#111;padding:8px;line-height:1.25;}
</style>
</head>
<body>
<div class="wrap"><div class="box">
    <?php if (!empty($logo)): ?><img class="logo" src="<?php echo htmlspecialchars($logo); ?>" alt="Logo"><?php endif; ?>
    <?php if ($qrUrl): ?>
        <img class="qr" src="<?php echo htmlspecialchars($qrUrl); ?>" alt="QR Code WhatsApp">
        <div class="title">SCAN PARA SUPORTE</div>
        <div class="sub">Renovacao • Duvidas • Reclamar</div>
    <?php else: ?>
        <div class="warn">Configure o WhatsApp no painel em QR Suporte.</div>
    <?php endif; ?>
</div></div>
</body>
</html>
