<!DOCTYPE html>
<html lang="ru">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="theme-color" content="#0d6efd">
    <meta name="description" content="Administrative panel for Cascad360">
    {% if csrf_token %}<meta name="csrf-token" content="{{ csrf_token }}">{% endif %}
    <title>{% block title %}Административная панель{% endblock %} - Cascad360</title>
    <link rel="manifest" href="{{ url_for('static', filename='manifest.json') }}">
    <link rel="stylesheet" href="{{ url_for('static', filename='css/bootstrap.min.css') }}">
    <link rel="stylesheet" href="{{ url_for('static', filename='css/bootstrap-icons.css') }}">
    <link rel="stylesheet" href="{{ url_for('static', filename='css/style.css') }}">
    {% block extra_css %}{% endblock %}
</head>
<body class="{% block body_class %}{% endblock %}">
    <a href="#mainContent" class="skip-link" data-i18n="a11y.skip_to_content">Перейти к основному содержимому</a>
    <!-- Боковая панель навигации -->
    <aside class="sidebar" id="sidebar" role="complementary" aria-label="Боковое меню">
        <div class="sidebar-header">
            <div class="sidebar-logo">
                <i class="bi bi-diagram-3" aria-hidden="true"></i>
                <span class="sidebar-logo-text" data-i18n="app.name">Cascad360</span>
            </div>
            <button class="sidebar-toggle d-lg-none" id="sidebarToggle" aria-label="Закрыть меню" data-i18n-attr="aria-label:btn.menu_close">
                <i class="bi bi-x-lg" aria-hidden="true"></i>
            </button>
        </div>
        
        <nav class="sidebar-nav" aria-label="Основная навигация">
            <ul class="nav-menu" id="dynamicMenu">
                <!-- Меню загружается динамически через JavaScript -->
                <li class="nav-item">
                    <div class="text-center p-3">
                        <div class="spinner-border spinner-border-sm text-primary" role="status" aria-hidden="false">
                            <span class="visually-hidden" data-i18n="menu.loading">Загрузка меню...</span>
                        </div>
                    </div>
                </li>
            </ul>
        </nav>
        
        <div class="sidebar-footer">
            <div class="user-info">
                <div class="user-avatar">
                    <i class="bi bi-person-circle"></i>
                </div>
                <div class="user-details">
                    <div class="user-name">{{ session.username }}</div>
                    <div class="user-role">
                        {% if session.get('is_admin') %}
                            <span class="badge bg-danger" data-i18n="role.admin">Администратор</span>
                        {% else %}
                            <span class="badge bg-secondary" data-i18n="role.user">Пользователь</span>
                        {% endif %}
                    </div>
                </div>
            </div>
            <a href="{{ url_for('auth.logout') }}" class="btn-logout" data-i18n-attr="aria-label:nav.logout">
                <i class="bi bi-box-arrow-right" aria-hidden="true"></i>
                <span data-i18n="nav.logout">Выход</span>
            </a>
        </div>
    </aside>
    
    <!-- Основной контент -->
    <div class="main-content" id="mainContent">
        <!-- Верхняя панель -->
        <header class="topbar" role="banner">
            <div class="topbar-left">
                <button class="btn-menu-toggle d-lg-none" id="menuToggle" aria-label="Открыть меню" data-i18n-attr="aria-label:btn.menu_toggle">
                    <i class="bi bi-list" aria-hidden="true"></i>
                </button>
                <nav aria-label="breadcrumb" class="breadcrumb-nav">
                    <ol class="breadcrumb mb-0">
                        {% block breadcrumb %}
                        <li class="breadcrumb-item"><a href="{{ url_for('admin.dashboard') }}" data-i18n="nav.home">Главная</a></li>
                        {% endblock %}
                    </ol>
                </nav>
            </div>
            <div class="topbar-right">
                <div class="topbar-actions" role="group" aria-label="Действия панели">
                    <div class="dropdown d-inline-block">
                        <button class="btn btn-sm btn-outline-secondary dropdown-toggle" type="button" id="langDropdown" data-bs-toggle="dropdown" aria-expanded="false" aria-haspopup="true" data-i18n="lang.choose">Язык</button>
                        <ul class="dropdown-menu dropdown-menu-end" aria-labelledby="langDropdown">
                            <li><a class="dropdown-item" href="#" data-lang="ru" data-i18n="lang.ru">Русский</a></li>
                            <li><a class="dropdown-item" href="#" data-lang="en" data-i18n="lang.en">English</a></li>
                        </ul>
                    </div>
                    <div class="dropdown d-inline-block notifications-dropdown-wrap">
                        <button class="btn-icon" type="button" id="notificationsBtn"
                                data-bs-toggle="dropdown" data-bs-auto-close="outside"
                                aria-expanded="false" aria-haspopup="true"
                                data-i18n-attr="aria-label:btn.notifications">
                            <i class="bi bi-bell" aria-hidden="true"></i>
                            <span class="badge-notification" id="notificationsBadge" hidden aria-hidden="true"></span>
                        </button>
                        <div class="dropdown-menu dropdown-menu-end notifications-panel" id="notificationsPanel" aria-labelledby="notificationsBtn">
                            <div class="notifications-panel__header" data-i18n="notifications.title">Уведомления</div>
                            <ul class="list-unstyled mb-0" id="notificationsList" role="list"></ul>
                            <div class="notifications-panel__empty text-muted" id="notificationsEmpty" data-i18n="notifications.empty">Нет новых уведомлений</div>
                            <div class="notifications-panel__footer">
                                <a href="/admin/alerts" class="dropdown-item text-center" id="notificationsFooterLink" data-i18n="notifications.view_all">Все алерты</a>
                            </div>
                        </div>
                    </div>
                    <button class="btn-icon" id="searchBtn" aria-label="Поиск" data-i18n-attr="aria-label:btn.search">
                        <i class="bi bi-search" aria-hidden="true"></i>
                    </button>
                </div>
            </div>
        </header>
        
        <!-- Контент страницы -->
        <main class="content-wrapper" id="mainContent" role="main" tabindex="-1">
            {% block content %}{% endblock %}
        </main>
        
        <!-- Футер -->
        <footer class="footer" role="contentinfo">
            <div class="container-fluid">
                <div class="row align-items-center">
                    <div class="col-md-6">
                        <p class="mb-0 text-muted" data-i18n="footer.copyright">© 2025 Cascad360. Все права защищены.</p>
                    </div>
                    <div class="col-md-6 text-md-end">
                        <p class="mb-0 text-muted">
                            <span data-i18n="footer.version">Версия</span> {{ app_version|default('1.0.8') }}{% if app_beta %} <span class="badge bg-warning text-dark">Beta</span>{% endif %}
                        </p>
                    </div>
                </div>
            </div>
        </footer>
    </div>
    
    <!-- Overlay для мобильных устройств -->
    <div class="sidebar-overlay" id="sidebarOverlay"></div>
    
    <meta name="sw-url" content="{{ url_for('static', filename='sw.js') }}">
    <script src="{{ url_for('static', filename='js/bootstrap.bundle.min.js') }}"></script>
    <script src="{{ url_for('static', filename='js/csrf-fetch.js') }}"></script>
    <script src="{{ url_for('static', filename='js/i18n.js') }}"></script>
    <script src="{{ url_for('static', filename='js/base-init.js') }}"></script>
    <script src="{{ url_for('static', filename='js/admin-notifications.js') }}"></script>
    <!-- Динамическое меню -->
    <script src="{{ url_for('static', filename='js/menu.js') }}"></script>
    {% block scripts %}{% endblock %}
    {% block extra_js %}{% endblock %}
</body>
</html>
