<?php
$base_dir = rtrim(str_replace('\\', '/', dirname($_SERVER['SCRIPT_NAME'] ?? '/')), '/');
$static_url = ($base_dir === '' || $base_dir === '.') ? '/assets/' : $base_dir . '/assets/';
$current_page = basename($_SERVER['PHP_SELF']);
$personalPages = ['logo.php', 'bg.php', 'themes.php', 'ajustescores.php'];
$personalOpen = in_array($current_page, $personalPages, true);
function menu_active(string $page, string $current): string { return $page === $current ? 'active' : ''; }
?>
<div id="kt_app_sidebar" class="app-sidebar" data-kt-drawer="true" data-kt-drawer-name="app-sidebar"
    data-kt-drawer-activate="{default: true, lg: false}" data-kt-drawer-overlay="true" data-kt-drawer-width="270px"
    data-kt-drawer-direction="start" data-kt-drawer-toggle="#kt_app_sidebar_toggle">

    <div class="d-none d-lg-flex flex-center px-6 pt-8 pb-7" id="kt_app_sidebar_header">
        <a href="dns.php" aria-label="TV VIP">
            <img alt="Logo" src="<?php echo $static_url; ?>media/logos/logo.png" class="h-70px" />
        </a>
    </div>

    <div class="flex-grow-1">
        <div id="kt_app_sidebar_menu_wrapper" class="hover-scroll-y" data-kt-scroll="true" data-kt-scroll-height="auto"
            data-kt-scroll-dependencies="#kt_app_sidebar_header, #kt_app_sidebar_footer" data-kt-scroll-offset="20px">
            <div class="app-sidebar-navs-default px-5 mb-10">
                <div id="kt_app_sidebar_menu" data-kt-menu="true" data-kt-menu-expand="false" class="menu menu-column menu-rounded menu-sub-indention">
                    <div class="menu-item pb-0 pt-0">
                        <div class="menu-content"><span class="menu-heading">CENTRAL TV VIP</span></div>
                    </div>
                    <div class="separator mb-4 mx-4"></div>

                    <div class="menu-item"><a class="menu-link <?php echo menu_active('dns.php', $current_page); ?>" href="dns.php"><span class="menu-title">🌐 Servidores DNS</span></a></div>
                    <div class="menu-item"><a class="menu-link <?php echo menu_active('mac.php', $current_page); ?>" href="mac.php"><span class="menu-title">📺 Dispositivos e Listas</span></a></div>
                    <div class="menu-item"><a class="menu-link <?php echo menu_active('teste.php', $current_page); ?>" href="teste.php"><span class="menu-title">⚡ Teste Automático</span></a></div>
                    <div class="menu-item"><a class="menu-link <?php echo menu_active('note.php', $current_page); ?>" href="note.php"><span class="menu-title">📢 Mensagem do App</span></a></div>

                    <div data-kt-menu-trigger="click" class="menu-item <?php echo $personalOpen ? 'here show' : ''; ?> menu-accordion">
                        <span class="menu-link"><span class="menu-title">🎨 Identidade Visual</span><span class="menu-arrow"></span></span>
                        <div class="menu-sub menu-sub-accordion">
                            <div class="menu-item"><a class="menu-link <?php echo menu_active('logo.php', $current_page); ?>" href="logo.php"><span class="menu-bullet"><span class="bullet bullet-dot"></span></span><span class="menu-title">Logotipo do App</span></a></div>
                            <div class="menu-item"><a class="menu-link <?php echo menu_active('bg.php', $current_page); ?>" href="bg.php"><span class="menu-bullet"><span class="bullet bullet-dot"></span></span><span class="menu-title">Background do App</span></a></div>
                            <div class="menu-item"><a class="menu-link <?php echo menu_active('themes.php', $current_page); ?>" href="themes.php"><span class="menu-bullet"><span class="bullet bullet-dot"></span></span><span class="menu-title">Layout Principal</span></a></div>
                            <div class="menu-item"><a class="menu-link <?php echo menu_active('ajustescores.php', $current_page); ?>" href="ajustescores.php"><span class="menu-bullet"><span class="bullet bullet-dot"></span></span><span class="menu-title">Cores e Foco</span></a></div>
                        </div>
                    </div>

                    <div class="menu-item"><a class="menu-link <?php echo menu_active('jogos.php', $current_page); ?>" href="jogos.php"><span class="menu-title">⚽ API de Jogos</span></a></div>
                    <div class="menu-item"><a class="menu-link <?php echo menu_active('qrcode.php', $current_page); ?>" href="qrcode.php"><span class="menu-title">🔳 QR Code</span></a></div>
                    <div class="menu-item"><a class="menu-link <?php echo menu_active('modobanner.php', $current_page); ?>" href="modobanner.php"><span class="menu-title">🖥️ Banner Inicial</span></a></div>
                    <div class="menu-item"><a class="menu-link <?php echo menu_active('manutencao.php', $current_page); ?>" href="manutencao.php"><span class="menu-title">🛠️ Manutenção</span></a></div>
                    <div class="menu-item"><a class="menu-link <?php echo menu_active('update_admin.php', $current_page); ?>" href="update_admin.php"><span class="menu-title">🚀 Atualização do APK</span></a></div>
                    <div class="menu-item"><a class="menu-link <?php echo menu_active('alerta_vencimento.php', $current_page); ?>" href="alerta_vencimento.php"><span class="menu-title">🔔 Alerta de Vencimento</span></a></div>
                    <div class="menu-item"><a class="menu-link <?php echo menu_active('users.php', $current_page); ?>" href="users.php"><span class="menu-title">👤 Meu Perfil</span></a></div>
                </div>
            </div>
        </div>
    </div>

    <div class="d-flex flex-column gap-3 px-6 pb-6" id="kt_app_sidebar_footer">
        <span class="tvvip-status justify-content-center">PAINEL CONECTADO</span>
        <div class="d-flex align-items-center justify-content-between px-2">
            <span class="text-gray-500 fs-8 fw-bold">TEMA DO PAINEL</span>
            <div data-bs-theme="dark" class="form-check form-switch form-check-custom form-check-solid mb-0">
                <input class="form-check-input h-25px w-45px" type="checkbox" value="1" id="kt_sidebar_theme_mode_toggle" />
            </div>
        </div>
    </div>
</div>
