<?php

// Inicia a sessão
session_start();

// Verifica se o usuário está logado. Se não, redireciona para a página de login e encerra o script.
if (!isset($_SESSION['loggedin'])) {
    header('location:login.php');
    exit();
}

// Lógica de dados e configurações
// ---
try {
    // Conecta ao banco de dados SQLite
    $db = new SQLite3('./api/.boxbrpanels.db');

    // Executa a consulta e busca o primeiro registro (ID=1)
    $res = $db->query('SELECT * FROM USERS WHERE ID=\'1\'');
    $user = $res->fetchArray();

    // Atribui os valores a variáveis
    $name = $user['NAME'] ?? 'Apk Manager';
    $logo = $user['LOGO'] ?? './img/logo.png';
    $db->close();
} catch (Exception $e) {
    // Em caso de erro, define valores padrão
    $name = 'Apk Manager';
    $logo = './img/logo.png';
    // Você pode adicionar um log de erro aqui, se necessário
    // error_log('Erro ao conectar ao banco de dados: ' . $e->getMessage());
}

// Carrega a configuração do arquivo JSON
$json_data = file_get_contents('./includes/boxbr.json');
$config = json_decode($json_data, true);
$theme_style = $config['info']['aa'] ?? 'default';

?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="">
    <meta name="author" content="">
    <meta name="google" content="notranslate">
    
    <title>UniTV BR</title>
    <link rel="shortcut icon" href="./img/logo.png" type="image/png">
    <link rel="icon" href="./img/logo.png" type="image/png">
    
    <script src="https://kit.fontawesome.com/3794d2f89f.js" crossorigin="anonymous"></script>
    <link href="vendor/fontawesome-free/css/all.min.css" rel="stylesheet" type="text/css">
    <link href="https://fonts.googleapis.com/css?family=Nunito:200,200i,300,300i,400,400i,600,600i,700,700i,800,800i,900,900i" rel="stylesheet">
    
    <link href="css/sb-admin-<?= htmlspecialchars($theme_style) ?>.css" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="css/jquery.datetimepicker.min.css"/>
    
    <style>
        .sidebar {
            background-color: #2c3e50 !important;
            background-image: url('./img/sidebar-bg.jpg');
            background-size: cover;
            background-repeat: no-repeat;
        }
        .sidebar .nav-item .nav-link {
            color: #ecf0f1 !important;
            transition: all 0.3s ease;
        }
        .sidebar .nav-item .nav-link:hover {
            transform: translateX(5px) scale(1.02);
            background-color: rgba(255, 255, 255, 0.05) !important;
            color: #f39c12 !important;
        }
        .sidebar-divider {
            border-top: 1px solid rgba(255, 255, 255, 0.2) !important;
            margin: 0.8rem 0;
        }
        .sidebar-brand {
            background-color: rgba(0, 0, 0, 0.1) !important;
            border-bottom: 1px solid rgba(255, 255, 255, 0.1) !important;
        }
        .sidebar-brand .sidebar-brand-text {
            color: #ffffff !important;
            font-weight: bold;
            text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
        }
        .topbar {
            background-color: #34495e !important;
            border-bottom: 1px solid #2c3e50 !important;
            box-shadow: 0 0.15rem 0.25rem rgba(0, 0, 0, 0.1);
        }
        .topbar .navbar-nav .nav-item .nav-link {
            color: #ecf0f1 !important;
            transition: color 0.3s ease;
        }
        .topbar .navbar-nav .nav-item .nav-link:hover {
            color: #f39c12 !important;
        }
        .topbar .navbar-nav .nav-item .nav-link .badge {
            font-size: 0.7rem;
            font-weight: bold;
            position: absolute;
            top: 0.2rem;
            right: 0.1rem;
            border-radius: 50%;
            padding: 0.25rem 0.35rem;
        }
        .text-primary {
            color: #f39c12 !important;
        }
        #sidebarToggleTop {
            color: #ecf0f1 !important;
        }
        #sidebarToggleTop:hover {
            color: #f39c12 !important;
        }
        .sidebar-card {
            background: rgba(0, 0, 0, 0.1);
            color: #ffffff;
            border-radius: 0.35rem;
            margin: 1rem auto;
            padding: 1rem;
        }
    </style>
</head>
<body id="page-top">
    <div id="wrapper">
        <ul class="navbar-nav sidebar sidebar-dark accordion" id="accordionSidebar">
            <a class="sidebar-brand d-flex align-items-center justify-content-center" href="colour.php">
                <div class="sidebar-brand-icon">
                    <img class="img-profile rounded-circle" width="65px" src="img/logo.png">
                </div>
                <div class="sidebar-brand-text mx-3">UniTV BR</div>
            </a>

            <hr class="sidebar-divider my-0">

            <li class="nav-item">
                <a class="nav-link" href="dns.php">
                    <i class="fas fa-fw fa-solid fa-wrench"></i>
                    <span>Servidores</span>
                </a>
            </li>
            
             <hr class="sidebar-divider my-0">

            <li class="nav-item">
                <a class="nav-link" href="usuarios.php">
                <i class="fa fa-meteor"></i>
                    <span>Playlist</span>
                </a>
            </li>
            
              <hr class="sidebar-divider">

            <li class="nav-item">
                <a class="nav-link" href="painel_jogos.php">
                    <i class="fas fa-futbol"></i>
                    <span>URL Jogos</span>
                </a>
            </li>
            
             <hr class="sidebar-divider">

            <li class="nav-item">
                <a class="nav-link" href="upload_logo.php">
                    <i class="fas fa-fw fa-globe"></i>
                    <span>Painel Imagem</span>
                </a>
            </li>
            
            <hr class="sidebar-divider">

            <li class="nav-item">
                <a class="nav-link" href="upload_app.php">
                    <i class="fas fa-inbox"></i>
                    <span>Atualização OTA</span>
                </a>
            </li>

            <hr class="sidebar-divider">

            <li class="nav-item">
                <a class="nav-link" href="profile.php">
                    <i class="fas fa-fw fa-user"></i>
                    <span>ADM</span>
                </a>
            </li>
            <hr class="sidebar-divider d-none d-md-block">

            <div class="text-center d-none d-md-inline">
                <button class="rounded-circle border-0" id="sidebarToggle"></button>
            </div>

            <div class="sidebar-card d-none d-lg-flex text-center">
                <p class="text-white small mb-2">UniTV BR</p>
            </div>
        </ul>
        <div id="content-wrapper" class="d-flex flex-column">
            <div id="content">
                <nav class="navbar navbar-expand navbar-light topbar mb-4 static-top shadow">
                    <button id="sidebarToggleTop" class="btn btn-link d-md-none rounded-circle mr-3">
                        <i class="fa fa-bars"></i>
                    </button>

                    <div><h5 class="m-0 text-primary">BRAPPS PROJETOS</h5></div>

                    <ul class="navbar-nav ml-auto">
                        <li class="nav-item dropdown no-arrow mx-1">
                            <a class="nav-link dropdown-toggle" href="colour.php">
                                <i class="fas fa-palette text-gray-400"></i><span class="badge badge-warning">Tema</span>
                            </a>
                        </li>
                        <div class="topbar-divider d-none d-sm-block"></div>

                        <li class="nav-item dropdown no-arrow mx-1">
                            <a class="nav-link dropdown-toggle" href="logout.php">
                                <span class="badge badge-danger">Logout</span>
                                <i class="fas fa-sign-out-alt fa-sm fa-fw mr-2 text-red-400"></i>
                            </a>
                        </li>
                    </ul>
                </nav>
          
    </body>
</html>