<?php
// addons/global_announcements/main.php
require_once __DIR__ . '/../../config/db.php';

// 1. Obtenemos los ajustes de la base de datos
// Usamos FETCH_KEY_PAIR para que sea fácil de leer: ['clave' => 'valor']
$stmt = $pdo->prepare("SELECT setting_key, setting_value FROM addon_settings WHERE addon_name = 'global_announcements'");
$stmt->execute();
$settings = $stmt->fetchAll(PDO::FETCH_KEY_PAIR);

// 2. Definimos variables con valores por defecto por si la tabla está vacía
$text = $settings['announcement_text'] ?? "Welcome to VVault!";
$color = $settings['announcement_color'] ?? "#00ff88"; // Verde neón por defecto
?>

<style>
    .v-announcement-bar {
        background: <?php echo $color; ?>; /* COLOR DESDE LA PALETA DEL ADMIN */
        color: #000;
        text-align: center;
        padding: 12px;
        font-size: 13px;
        font-weight: 800;
        text-transform: uppercase;
        letter-spacing: 1px;
        position: relative;
        z-index: 9999;
        display: block;
        text-decoration: none;
        border-bottom: 2px solid rgba(0,0,0,0.1);
        transition: 0.3s ease;
    }
    
    .v-announcement-bar:hover {
        filter: brightness(1.1);
    }

    .v-announcement-bar i {
        margin-right: 8px;
    }
</style>

<div class="v-announcement-bar">
    <i class="fa-solid fa-bullhorn"></i> 
    <?php echo htmlspecialchars($text); ?>
</div>