<?php
require_once __DIR__ . '/theme-init.php';

// Mapa de slugs para títulos
$politicas_map = [
    'politica_entrega'         => 'Política de Entrega',
    'politica_troca_devolucao' => 'Política de Troca e Devolução',
    'politica_reembolso'       => 'Política de Reembolso',
    'politica_privacidade'     => 'Política de Privacidade',
    'termos_uso'               => 'Termos de Uso',
];

$slug = isset($_GET['slug']) ? trim($_GET['slug']) : '';

// Valida o slug
if (!array_key_exists($slug, $politicas_map)) {
    header('Location: index.php');
    exit;
}

$titulo_politica = $politicas_map[$slug];

// Busca conteúdo no banco
if (!isset($conn)) {
    include __DIR__ . '/../adm/config/db.php';
}
$stmtP = $conn->prepare("SELECT valor FROM configuracoes WHERE chave = ?");
$stmtP->bind_param('s', $slug);
$stmtP->execute();
$resP = $stmtP->get_result();
$rowP = $resP->fetch_assoc();
$conteudo = $rowP['valor'] ?? '';
$stmtP->close();

$pageTitle = $titulo_politica . ' — ' . ($nomeLoja ?? 'Loja');
?>
<?php include 'header.php'; ?>

    <!-- Hero Start -->
    <div class="container-fluid bg-primary py-5 hero-header mb-5">
        <div class="row py-3">
            <div class="col-12 text-center">
                <h1 class="display-4 text-white animated zoomIn"><?= htmlspecialchars($titulo_politica) ?></h1>
                <nav aria-label="breadcrumb" class="d-inline-block mt-2">
                    <ol class="breadcrumb mb-0 justify-content-center" style="background:transparent;">
                        <li class="breadcrumb-item"><a href="index.php" class="text-white">Home</a></li>
                        <li class="breadcrumb-item active text-white-50" aria-current="page"><?= htmlspecialchars($titulo_politica) ?></li>
                    </ol>
                </nav>
            </div>
        </div>
    </div>
    <!-- Hero End -->


    <!-- Policy Content Start -->
    <div class="container-fluid py-5">
        <div class="container">
            <div class="row justify-content-center">
                <div class="col-lg-9 wow fadeInUp" data-wow-delay="0.1s">

                    <!-- Sidebar navigation to other policies -->
                    <div class="mb-4 d-flex flex-wrap gap-2">
                        <?php foreach ($politicas_map as $s => $t): ?>
                            <a href="politica.php?slug=<?= urlencode($s) ?>"
                               class="btn btn-sm <?= $s === $slug ? 'btn-primary' : 'btn-outline-primary' ?>">
                                <?= htmlspecialchars($t) ?>
                            </a>
                        <?php endforeach; ?>
                    </div>

                    <div class="card border-0 shadow-sm rounded-3">
                        <div class="card-body p-4 p-lg-5">
                            <h2 class="mb-4 text-primary"><?= htmlspecialchars($titulo_politica) ?></h2>

                            <?php if (!empty($conteudo)): ?>
                                <div class="policy-content lh-lg">
                                    <?= $conteudo ?>
                                </div>
                            <?php else: ?>
                                <div class="alert alert-info">
                                    <i class="bi bi-info-circle me-2"></i>
                                    Esta política ainda não foi preenchida. Por favor, volte em breve.
                                </div>
                            <?php endif; ?>
                        </div>
                    </div>

                    <div class="mt-4 text-center">
                        <a href="index.php" class="btn btn-outline-primary rounded-pill px-4">
                            <i class="bi bi-arrow-left me-1"></i> Voltar para a Loja
                        </a>
                    </div>

                </div>
            </div>
        </div>
    </div>
    <!-- Policy Content End -->

<style>
.policy-content h1, .policy-content h2, .policy-content h3 {
    color: var(--primary, #06a3da);
    margin-top: 1.5rem;
}
.policy-content ul, .policy-content ol {
    padding-left: 1.5rem;
}
.policy-content p {
    color: #444;
}
</style>

<?php include 'footer.php'; ?>

    <!-- JavaScript Libraries -->
    <script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0/dist/js/bootstrap.bundle.min.js"></script>
    <script src="lib/wow/wow.min.js"></script>
    <script src="lib/easing/easing.min.js"></script>
    <script src="lib/waypoints/waypoints.min.js"></script>
    <script src="lib/owlcarousel/owl.carousel.min.js"></script>
    <script src="lib/tempusdominus/js/moment.min.js"></script>
    <script src="lib/tempusdominus/js/moment-timezone.min.js"></script>
    <script src="lib/tempusdominus/js/tempusdominus-bootstrap-4.min.js"></script>
    <script src="https://cdn.jsdelivr.net/gh/mcstudios/glightbox/dist/js/glightbox.min.js"></script>

    <!-- Template Javascript -->
    <script src="js/main.js?v=<?= time() ?>"></script>
</body>
</html>
