<?php
$currentPage = $currentPage ?? basename($_SERVER['PHP_SELF'], '.php');

$navItems = [
    ['page' => 'dashboard', 'href' => '/notifier/dashboard/', 'label' => 'Dashboard', 'icon' => 'dashboard'],
    ['page' => 'notifications', 'href' => '/notifier/notifications/', 'label' => 'Notifications', 'icon' => 'bell'],
    ['page' => 'notification-edit', 'href' => '/notifier/notifications/new/', 'label' => 'Notifications', 'icon' => 'bell', 'hidden' => true],
    ['page' => 'categories', 'href' => '/notifier/categories/', 'label' => 'Categories', 'icon' => 'tag'],
    ['page' => 'history', 'href' => '/notifier/history/', 'label' => 'History', 'icon' => 'clock'],
    ['page' => 'console', 'href' => '/notifier/console/', 'label' => 'Console', 'icon' => 'code'],
];

function getIcon($type) {
    switch($type) {
        case 'dashboard':
            return '<path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M4 6a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2H6a2 2 0 01-2-2V6zM14 6a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2h-2a2 2 0 01-2-2V6zM4 16a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2H6a2 2 0 01-2-2v-2zM14 16a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2h-2a2 2 0 01-2-2v-2z"/>';
        case 'bell':
            return '<path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M15 17h5l-1.405-1.405A2.032 2.032 0 0118 14.158V11a6.002 6.002 0 00-4-5.659V5a2 2 0 10-4 0v.341C7.67 6.165 6 8.388 6 11v3.159c0 .538-.214 1.055-.595 1.436L4 17h5m6 0v1a3 3 0 11-6 0v-1m6 0H9"/>';
        case 'tag':
            return '<path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M7 7h.01M7 3h5c.512 0 1.024.195 1.414.586l7 7a2 2 0 010 2.828l-7 7a2 2 0 01-2.828 0l-7-7A1.994 1.994 0 013 12V7a4 4 0 014-4z"/>';
        case 'clock':
            return '<path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"/>';
        case 'code':
            return '<path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M10 20l4-16m4 4l4 4-4 4M6 16l-4-4 4-4"/>';
        case 'logout':
            return '<path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M17 16l4-4m0 0l-4-4m4 4H7m6 4v1a3 3 0 01-3 3H6a3 3 0 01-3-3V7a3 3 0 013-3h4a3 3 0 013 3v1"/>';
        default:
            return '';
    }
}
?>
<aside class="hidden lg:flex w-48 bg-white border-r border-slate-200 flex-col h-full fixed left-0 top-0 bottom-0">
    <div class="p-3 border-b border-slate-100">
        <div class="flex items-center gap-2">
            <div class="w-7 h-7 bg-indigo-500 rounded-lg flex items-center justify-center">
                <svg class="w-3.5 h-3.5 text-white" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 17h5l-1.405-1.405A2.032 2.032 0 0118 14.158V11a6.002 6.002 0 00-4-5.659V5a2 2 0 10-4 0v.341C7.67 6.165 6 8.388 6 11v3.159c0 .538-.214 1.055-.595 1.436L4 17h5m6 0v1a3 3 0 11-6 0v-1m6 0H9"/>
                </svg>
            </div>
            <span class="font-semibold text-sm text-slate-900">Notifier</span>
        </div>
    </div>

    <nav class="flex-1 p-2">
        <?php foreach ($navItems as $item): ?>
            <?php if (!empty($item['hidden'])) continue; ?>
            <?php $isActive = $currentPage === $item['page'] || ($item['page'] === 'notifications' && $currentPage === 'notification-edit'); ?>
            <a href="<?= $item['href'] ?>"
               class="flex items-center gap-2.5 px-2.5 py-1.5 rounded-md mb-0.5 <?= $isActive ? 'bg-slate-100 text-slate-900 font-medium' : 'text-slate-500 hover:bg-slate-50 hover:text-slate-700' ?> transition-colors">
                <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                    <?= getIcon($item['icon']) ?>
                </svg>
                <?= $item['label'] ?>
            </a>
        <?php endforeach; ?>
    </nav>

    <div class="p-2 border-t border-slate-100">
        <a href="/notifier/logout/" class="flex items-center gap-2.5 px-2.5 py-1.5 rounded-md w-full text-slate-500 hover:bg-slate-50 hover:text-slate-700 transition-colors">
            <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                <?= getIcon('logout') ?>
            </svg>
            Logout
        </a>
    </div>
</aside>
