<?php
// Incluir los helpers necesarios
require_once __DIR__ . '/../includes/url_helper.php';
require_once __DIR__ . '/../includes/translation_helper.php';

// Inicializar el idioma de la sesión si no está definido
if (!isset($_SESSION['language'])) {
    $_SESSION['language'] = 'es'; // Idioma por defecto
}
?>
<!DOCTYPE html>
<html lang="es" data-bs-theme="light">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Bot Discord</title>
    <!-- Bootstrap CSS -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous">
    <!-- Bootstrap Icons -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css" rel="stylesheet">
    <!-- Estilos personalizados -->
    <link rel="stylesheet" href="<?php echo asset('css/style.css'); ?>" type="text/css">
    <!-- Contenido extra del head (opcional) -->
    <?php if (isset($extraHead)) echo $extraHead; ?>
</head>
<body>

<!-- Top Navigation Bar -->
<nav class="navbar navbar-expand-lg navbar-dark bg-dark border-bottom">
    <div class="container-fluid">
        <!-- Logo y nombre -->
        <a class="navbar-brand d-flex align-items-center" href="<?php echo site_url('index.php'); ?>">
            <img src="<?php echo asset('images/logo.png'); ?>" alt="Logo" style="height: 30px; margin-right: 10px;">
            <strong>Bot Discord</strong>
        </a>

        <!-- Toggle button para móvil -->
        <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarMenu" aria-controls="navbarMenu" aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
        </button>

        <!-- Menu items -->
        <div class="collapse navbar-collapse" id="navbarMenu">
            <ul class="navbar-nav me-auto">
                <!-- Inicio -->
                <li class="nav-item">
                    <a class="nav-link" href="<?php echo site_url('index.php'); ?>" data-translate="true">
                        <i class="bi bi-house-door-fill me-1"></i>Inicio
                    </a>
                </li>

                <!-- Mensajes -->
                <li class="nav-item dropdown">
                    <a class="nav-link dropdown-toggle" href="#" id="navMensajes" role="button" data-bs-toggle="dropdown" aria-expanded="false" data-translate="true">
                        <i class="bi bi-chat-dots-fill me-1"></i>Mensajes
                    </a>
                    <ul class="dropdown-menu" aria-labelledby="navMensajes">
                        <li><a class="dropdown-item" href="<?php echo site_url('create_message.php'); ?>" data-translate="true"><i class="bi bi-plus-square-fill me-2"></i>Crear Mensaje</a></li>
                        <li><a class="dropdown-item" href="<?php echo site_url('scheduled_messages.php'); ?>" data-translate="true"><i class="bi bi-clock-fill me-2"></i>Programados</a></li>
                        <li><a class="dropdown-item" href="<?php echo site_url('recurrentes.php'); ?>" data-translate="true"><i class="bi bi-arrow-repeat me-2"></i>Plantillas</a></li>
                        <li><a class="dropdown-item" href="<?php echo site_url('sent_messages.php'); ?>" data-translate="true"><i class="bi bi-send-fill me-2"></i>Enviados</a></li>
                    </ul>
                </li>

                <!-- Recursos -->
                <li class="nav-item">
                    <a class="nav-link" href="<?php echo site_url('gallery.php'); ?>" data-translate="true">
                        <i class="bi bi-images me-1"></i>Galería
                    </a>
                </li>

                <!-- Admin (solo si es admin) -->
                <?php if ($_SESSION['role'] === 'admin'): ?>
                <li class="nav-item dropdown">
                    <a class="nav-link dropdown-toggle" href="#" id="navAdmin" role="button" data-bs-toggle="dropdown" aria-expanded="false" data-translate="true">
                        <i class="bi bi-gear-fill me-1"></i>Admin
                    </a>
                    <ul class="dropdown-menu" aria-labelledby="navAdmin">
                        <li><h6 class="dropdown-header">Gestión</h6></li>
                        <li><a class="dropdown-item" href="<?php echo site_url('admin/users.php'); ?>" data-translate="true"><i class="bi bi-people-fill me-2"></i>Usuarios</a></li>
                        <li><a class="dropdown-item" href="<?php echo site_url('admin/recipients.php'); ?>" data-translate="true"><i class="bi bi-person-rolodex me-2"></i>Destinatarios</a></li>
                        <li><hr class="dropdown-divider"></li>
                        <li><h6 class="dropdown-header">Configuración</h6></li>
                        <li><a class="dropdown-item" href="<?php echo site_url('admin/languages.php'); ?>" data-translate="true"><i class="bi bi-translate me-2"></i>Idiomas</a></li>
                        <li><a class="dropdown-item" href="<?php echo site_url('admin/comandos.php'); ?>" data-translate="true"><i class="bi bi-terminal-fill me-2"></i>Comandos</a></li>
                        <li><hr class="dropdown-divider"></li>
                        <li><h6 class="dropdown-header">Bots</h6></li>
                        <li><a class="dropdown-item" href="<?php echo site_url('telegram/admin/telegram_welcome.php'); ?>" data-translate="true"><i class="bi bi-telegram me-2"></i>Telegram Config</a></li>
                        <li><a class="dropdown-item" href="<?php echo site_url('telegram/admin/telegram_bot_interactions.php'); ?>" data-translate="true"><i class="bi bi-robot me-2"></i>Interacciones Bot</a></li>
                        <li><a class="dropdown-item" href="<?php echo site_url('telegram/admin/chat_telegram.php'); ?>" data-translate="true"><i class="bi bi-chat-dots-fill me-2"></i>Chat Telegram</a></li>
                        <li><hr class="dropdown-divider"></li>
                        <li><h6 class="dropdown-header">Monitoreo</h6></li>
                        <li><a class="dropdown-item" href="<?php echo site_url('admin/activity.php'); ?>" data-translate="true"><i class="bi bi-clipboard-data-fill me-2"></i>Actividad</a></li>
                        <li><a class="dropdown-item" href="<?php echo site_url('admin/test_discord_connection.php'); ?>" data-translate="true"><i class="bi bi-bug-fill me-2"></i>Test</a></li>
                    </ul>
                </li>
                <?php endif; ?>

                <!-- User menu -->
                <li class="nav-item dropdown">
                    <a class="nav-link dropdown-toggle" href="#" id="navUser" role="button" data-bs-toggle="dropdown" aria-expanded="false" style="cursor: pointer;">
                        <i class="bi bi-person-circle me-1"></i><?php echo htmlspecialchars($_SESSION['username']); ?>
                    </a>
                    <ul class="dropdown-menu" aria-labelledby="navUser">
                        <li><a class="dropdown-item" href="<?php echo site_url('profile.php'); ?>" data-translate="true"><i class="bi bi-person-circle me-2"></i>Perfil</a></li>
                        <li><hr class="dropdown-divider"></li>
                        <li><a class="dropdown-item" href="<?php echo site_url('logout.php'); ?>" data-translate="true"><i class="bi bi-box-arrow-right me-2"></i>Cerrar Sesión</a></li>
                    </ul>
                </li>
            </ul>

            <!-- Right side: Theme toggle, Language selector, DB info -->
            <div class="d-flex align-items-center gap-2 flex-wrap ms-auto">
                <!-- Theme Toggle -->
                <button class="btn btn-sm theme-toggle-btn" id="theme-toggle" title="Cambiar tema" aria-label="Cambiar tema claro/oscuro">
                    <i class="bi bi-sun-fill" id="theme-icon"></i>
                </button>
                
                <select class="form-select form-select-sm w-auto" id="language-selector" style="max-width: 120px;">
                    <!-- Options will be populated by translate_frontend.js -->
                </select>

                <?php if ($_SESSION['role'] === 'admin'): ?>
                <div class="card border-secondary bg-dark text-light" style="width: 150px; box-shadow: 0 2px 6px rgba(0,0,0,0.3); margin: 0; flex-shrink: 0;">
                    <div class="card-body p-1 text-center" style="font-size: 0.8rem;">
                        <div class="mb-1">
                            <i class="bi bi-database text-info" style="font-size: 14px;"></i>
                        </div>
                        <div class="mb-1">
                            <small class="text-muted d-block" style="font-size: 8px;">BASE DE DATOS</small>
                            <strong class="d-block text-light" style="font-size: 11px;"><?php echo htmlspecialchars(DB_NAME); ?></strong>
                        </div>
                        <hr class="my-1" style="margin: 0.3rem 0;">
                        <div>
                            <small class="text-muted d-block" style="font-size: 8px;">SERVIDOR</small>
                            <code class="text-info" style="font-size: 10px;"><?php echo htmlspecialchars(DB_HOST); ?>:<?php echo htmlspecialchars(DB_PORT); ?></code>
                        </div>
                    </div>
                </div>
                <?php endif; ?>
            </div>
        </div>
    </div>
</nav>

<!-- Main Content -->
<div id="page-content-wrapper">

        <main class="container-fluid p-4">

<!-- Conflicting language script removed -->