<?php
use App\Core\Security;
use App\Models\DemoData;

$title = $title ?? 'CiviGO.eu';
$user = $user ?? DemoData::user();
$navGroups = [
    'Начало' => [
        ['href' => '/dashboard', 'label' => 'Начало', 'icon' => 'bi-house-fill'],
    ],
    'Действия' => [
        ['href' => '/reports/new', 'label' => 'Подай сигнал', 'icon' => 'bi-megaphone'],
        ['href' => '/assistant', 'label' => 'AI Асистент', 'icon' => 'bi-robot'],
        ['href' => '/zdoi', 'label' => 'ЗДОИ заявление', 'icon' => 'bi-file-earmark-text'],
        ['href' => '/petitions', 'label' => 'Петиция', 'icon' => 'bi-people'],
        ['href' => '/generators', 'label' => 'Генератори', 'icon' => 'bi-file-earmark-plus'],
    ],
    'Платформа' => [
        ['href' => '/map', 'label' => 'Карта', 'icon' => 'bi-map'],
        ['href' => '/institutions', 'label' => 'Институции', 'icon' => 'bi-bank'],
        ['href' => '/tracking', 'label' => 'Проследяване', 'icon' => 'bi-signpost-split'],
        ['href' => '/handbook', 'label' => 'Наръчник', 'icon' => 'bi-journal-bookmark'],
        ['href' => '/qr-library', 'label' => 'QR услуги', 'icon' => 'bi-qr-code'],
        ['href' => '/statistics', 'label' => 'Статистики', 'icon' => 'bi-bar-chart'],
        ['href' => '/transparency', 'label' => 'Прозрачност', 'icon' => 'bi-activity'],
    ],
    'Система' => [
        ['href' => '/profile', 'label' => 'Профил', 'icon' => 'bi-person-circle'],
        ['href' => '/admin', 'label' => 'Админ панел', 'icon' => 'bi-sliders2-vertical'],
    ],
];
?>
<!doctype html>
<html lang="bg">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="csrf-token" content="<?= e(Security::csrfToken()) ?>">
    <meta name="theme-color" content="#18B76A">
    <title><?= e($title) ?> | CiviGO.eu</title>
    <link rel="manifest" href="/manifest.json">
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800;900&display=swap" rel="stylesheet">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css" rel="stylesheet">
    <link href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" rel="stylesheet">
    <link href="<?= asset('css/app.css') ?>" rel="stylesheet">
</head>
<body class="app-body">
<div class="app-shell">
    <aside class="sidebar" id="sidebar">
        <a class="brand" href="/dashboard" aria-label="CiviGO.eu">
            <span class="brand-mark"><i class="bi bi-check2"></i></span>
            <span>civigo<span>.eu</span></span>
        </a>

        <nav class="side-nav">
            <?php foreach ($navGroups as $group => $items): ?>
                <div class="nav-group">
                    <div class="nav-label"><?= e($group) ?></div>
                    <?php foreach ($items as $item): ?>
                        <a class="nav-link <?= is_active($item['href']) ?>" href="<?= e($item['href']) ?>">
                            <i class="bi <?= e($item['icon']) ?>"></i>
                            <span><?= e($item['label']) ?></span>
                        </a>
                    <?php endforeach; ?>
                </div>
            <?php endforeach; ?>
        </nav>

        <div class="pro-card">
            <div class="pro-title">civigo PRO</div>
            <p>Разширени функции, автоматични напомняния и екипни работни пространства.</p>
            <a href="/profile" class="btn btn-sm btn-success w-100">Виж профил</a>
        </div>
    </aside>

    <div class="main-shell">
        <header class="topbar">
            <button class="icon-button d-lg-none" type="button" data-sidebar-toggle aria-label="Меню">
                <i class="bi bi-list"></i>
            </button>
            <form class="search-box" action="/institutions" method="get">
                <i class="bi bi-search"></i>
                <input type="search" name="q" placeholder="Търси сигнали, институции, документи...">
                <kbd>Ctrl K</kbd>
            </form>
            <div class="top-actions">
                <button class="icon-button" type="button" data-theme-toggle aria-label="Смени тема" data-bs-toggle="tooltip" data-bs-title="Смени тема">
                    <i class="bi bi-moon"></i>
                </button>
                <button class="icon-button notification" type="button" aria-label="Известия" data-bs-toggle="tooltip" data-bs-title="Известия">
                    <i class="bi bi-bell"></i>
                    <span>3</span>
                </button>
                <a class="btn btn-success d-none d-md-inline-flex align-items-center gap-2" href="/reports/new">
                    <i class="bi bi-plus-lg"></i>
                    Подай сигнал
                </a>
                <a class="user-chip" href="/profile">
                    <span class="avatar"><?= e(initials($user['name'])) ?></span>
                    <span class="d-none d-sm-block">
                        <strong><?= e($user['name']) ?></strong>
                        <small><?= e($user['level']) ?></small>
                    </span>
                    <i class="bi bi-chevron-down d-none d-sm-inline"></i>
                </a>
            </div>
        </header>

        <main class="content-area">
            <?= $content ?>
        </main>
    </div>
</div>

<div class="toast-stack" data-toast-stack></div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chart.js@4.4.1/dist/chart.umd.min.js"></script>
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>
<script src="<?= asset('js/app.js') ?>"></script>
</body>
</html>
