<?php
declare(strict_types=1);
require_once __DIR__ . '/../includes/auth.php';
require_once __DIR__ . '/../includes/api_helpers.php';
gpc_session_start();
if (empty($_SESSION['reseller_id'])) { header('Location: index.php'); exit; }
$db = gpc_db();
$resellerId = (int)$_SESSION['reseller_id'];
$today = date('Y-m-d');
$current = basename($_SERVER['PHP_SELF'] ?? '');
$stmt = $db->prepare('SELECT * FROM resellers WHERE id=:id LIMIT 1');
$stmt->execute([':id'=>$resellerId]);
$reseller = $stmt->fetch();
$resellerValid = $reseller && syntra_reseller_is_valid($reseller);
if (!$resellerValid) { unset($_SESSION['reseller_id'], $_SESSION['reseller_user'], $_SESSION['reseller_name']); header('Location: index.php?expired=1'); exit; }
$pageTitle = $pageTitle ?? 'Revenda';
$flash = gpc_take_flash();
function rv_h($s): string { return htmlspecialchars((string)$s, ENT_QUOTES, 'UTF-8'); }
$canMac = syntra_reseller_can_mac($reseller);
$canDns = syntra_reseller_can_dns($reseller);
$canBulk = ((int)($reseller['can_bulk_dns'] ?? 0) === 1) && $canDns;
$planLabel = syntra_reseller_plan_label((string)($reseller['reseller_plan'] ?? 'basic'));
?><!doctype html><html lang="pt-BR"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title><?= rv_h($pageTitle) ?> - SYNTRA Revenda</title><link rel="stylesheet" href="../assets/style.css"></head><body><div class="backdrop" id="backdrop"></div><div class="shell"><aside class="sidebar" id="sidebar"><div class="sidebar-head"><div class="mark"><i data-lucide="tv-minimal-play"></i></div><span>SYNTRA Revenda</span></div><ul class="nav"><li class="nav-section">Painel <?= rv_h($planLabel) ?></li><li><a class="<?= $current==='dashboard.php'?'active':'' ?>" href="dashboard.php"><i data-lucide="layout-dashboard"></i><span>Início</span></a></li><?php if($canMac): ?><li class="nav-section">Licenças</li><li><a class="<?= $current==='licenses.php'?'active':'' ?>" href="licenses.php"><i data-lucide="badge-check"></i><span>Licenças MAC</span></a></li><?php endif; ?><?php if($canDns): ?><li class="nav-section">Parceiros</li><li><a class="<?= $current==='dns.php'?'active':'' ?>" href="dns.php"><i data-lucide="server-cog"></i><span>Código Parceiro</span></a></li><?php if($canBulk): ?><li><a class="<?= $current==='troca_dns.php'?'active':'' ?>" href="troca_dns.php"><i data-lucide="repeat"></i><span>Troca em Massa</span></a></li><?php endif; ?><?php endif; ?><li class="nav-divider" role="presentation"></li><li><a href="index.php?logout=1"><i data-lucide="log-out"></i><span>Sair</span></a></li></ul></aside><div class="main"><header class="topbar"><div class="topbar-left"><button type="button" class="icon-btn" id="menuBtn" aria-label="Menu"><i data-lucide="menu"></i></button><h1><?= rv_h($pageTitle) ?></h1></div><div class="user-chip"><span class="avatar"><?= strtoupper(substr((string)$reseller['name'],0,1)) ?></span><span><?= rv_h($reseller['name']) ?> · <?= rv_h($planLabel) ?></span></div></header><main class="page">
