<?php
/**
 * Optional production-ready admin sidebar component.
 * Existing admin pages can keep using admin_tool_helper.php. This file is safe
 * to add now and can be adopted gradually during the enterprise rebuild.
 */

if (!function_exists('admin_sidebar_items')) {
    function admin_sidebar_items(): array
    {
        return [
            ['url' => 'control_panel.php', 'label' => 'Control Panel', 'key' => 'control_panel'],
            ['url' => 'api_monitor.php', 'label' => 'API Monitor', 'key' => 'api_monitor'],
            ['url' => 'api_provider_usage_logs.php', 'label' => 'API Provider Logs', 'key' => 'api_logs'],
            ['url' => 'api_settings.php', 'label' => 'API Settings', 'key' => 'api_settings'],
            ['url' => 'symbols.php', 'label' => 'Symbols', 'key' => 'symbols'],
            ['url' => 'timeframes.php', 'label' => 'Timeframes', 'key' => 'timeframes'],
            ['url' => 'candles.php', 'label' => 'Candles', 'key' => 'candles'],
            ['url' => 'trading_styles.php', 'label' => 'Trading Styles', 'key' => 'trading_styles'],
            ['url' => 'news_engine.php', 'label' => 'News Engine', 'key' => 'news_engine'],
            ['url' => 'institutional_engine.php', 'label' => 'Institutional Engine', 'key' => 'institutional_engine'],
            ['url' => 'alert_engine.php', 'label' => 'Alert Engine', 'key' => 'alert_engine'],
            ['url' => 'suggested_setup_rules.php', 'label' => 'Suggested Setup Rules', 'key' => 'suggested_setup_rules'],
            ['url' => 'active_alerts.php', 'label' => 'Active Alerts', 'key' => 'active_alerts'],
            ['url' => 'alert_logs.php', 'label' => 'Alert Logs', 'key' => 'alert_logs'],
            ['url' => 'alert_settings.php', 'label' => 'SMTP & Telegram', 'key' => 'alert_settings'],
            ['url' => 'users.php', 'label' => 'Users', 'key' => 'users'],
            ['url' => 'system_settings.php', 'label' => 'System Settings', 'key' => 'system_settings'],
        ];
    }
}

if (!function_exists('admin_sidebar_render')) {
    function admin_sidebar_render(string $activeKey = ''): void
    {
        if (!function_exists('e')) {
            function e($value) { return htmlspecialchars((string)$value, ENT_QUOTES, 'UTF-8'); }
        }
        echo '<aside class="admin-sidebar-shell">';
        echo '<div class="admin-sidebar-brand">ITA Admin</div>';
        echo '<nav class="admin-sidebar-nav">';
        foreach (admin_sidebar_items() as $item) {
            $active = $activeKey === ($item['key'] ?? '') ? ' is-active' : '';
            echo '<a class="admin-sidebar-link' . $active . '" href="' . e($item['url']) . '">' . e($item['label']) . '</a>';
        }
        echo '</nav></aside>';
    }
}
