<!-- ══ CARROSSEL DE BANNERS ═══════════════════════════════════════════════════════ -->
<?php


// Verifica se existe pelo menos 1 banner ativo
$sqlBan = "SELECT id, titulo, imagem, link, tem_botao, botao_texto 
           FROM banners 
           WHERE status = 'ativo'
           ORDER BY posicao ASC";
$resBan = $conn->query($sqlBan);

if ($resBan && $resBan->num_rows > 0) {

    // -------- CAROUSEL GERADO PELO BANCO --------
    echo '
    <div class="container-fluid p-0">
      <div id="header-carousel" class="carousel slide carousel-fade" data-bs-ride="carousel">
        <div class="carousel-inner">
    ';

    $first = true;
    while ($b = $resBan->fetch_assoc()) {

        $active = $first ? 'active' : '';
        $first = false;

        echo '
        <div class="carousel-item ' . $active . '">
            <img class="w-100" src="../adm/uploads/banners/' . htmlspecialchars($b['imagem']) . '" alt="">
            <div class="carousel-caption d-flex flex-column align-items-center justify-content-center">
                <div class="p-3" style="max-width: 900px;">
                <h1 class="display-1 text-white mb-md-4">' . htmlspecialchars($b['titulo']) . '</h1>';

        if (isset($b['tem_botao']) && $b['tem_botao'] === 'Sim') {
            $linkUrl = !empty($b['link']) ? htmlspecialchars($b['link']) : '#';
            $btnText = !empty($b['botao_texto']) ? htmlspecialchars($b['botao_texto']) : 'Saiba Mais';
            echo '
                    <a href="' . $linkUrl . '" target="_blank" class="btn btn-primary py-md-3 px-md-5 me-3 animated slideInLeft">' . $btnText . '</a>';
        }

        echo '
                </div>
            </div>
        </div>';
    }

    echo '
        </div>

        <button class="carousel-control-prev" type="button" data-bs-target="#header-carousel" data-bs-slide="prev">
            <span class="carousel-control-prev-icon" aria-hidden="true"></span>
            <span class="visually-hidden">Previous</span>
        </button>

        <button class="carousel-control-next" type="button" data-bs-target="#header-carousel" data-bs-slide="next">
            <span class="carousel-control-next-icon" aria-hidden="true"></span>
            <span class="visually-hidden">Next</span>
        </button>

      </div>
    </div>';

} else {

    // -------- SE NÃO HOUVER BANNERS ATIVOS --------
    echo '';

}
?>

<!-- ══ FIM CARROSSEL DE BANNERS ═══════════════════════════════════════════════════════ -->