@php
    $modules = [
        ['name' => 'home',                'displayName' => 'Főoldal',               'icon' => 'home',           'link' => route('legacy.show', ['path' => 'dashboard']),              'roles' => ['root','admin','developer','profit-center']],
        ['name' => 'order',               'displayName' => 'Új megrendelés',         'icon' => 'bevetelezes',    'link' => route('legacy.show', ['path' => 'order']),                  'roles' => ['root','profit-center']],
        ['name' => 'activeOrder',         'displayName' => 'Megrendelések',          'icon' => 'tranzakciok',    'link' => route('legacy.show', ['path' => 'orderArchive']),           'roles' => ['root','developer','admin','profit-center']],
        ['name' => 'productGroup',        'displayName' => 'Termékcsoportok',        'icon' => 'category',       'link' => route('legacy.show', ['path' => 'admin/productGroup']),     'roles' => ['root','developer','admin']],
        ['name' => 'product',             'displayName' => 'Termék',                 'icon' => 'raktar',         'link' => route('legacy.show', ['path' => 'admin/product']),          'roles' => ['root','developer','admin']],
        ['name' => 'supplier',            'displayName' => 'Beszállító adatbázis',   'icon' => 'supplier',       'link' => route('legacy.show', ['path' => 'admin/supplier']),         'roles' => ['root','developer','admin','profit-center']],
        ['name' => 'priceList',           'displayName' => 'Webrendelős árlisták',   'icon' => 'price_list2',    'link' => route('legacy.show', ['path' => 'admin/priceList']),        'roles' => ['root','developer','admin','profit-center']],
        ['name' => 'priceListProfitCenter','displayName' => 'PC Árlista',            'icon' => 'price_list_user','link' => route('legacy.show', ['path' => 'admin/priceListProfitCenter']), 'roles' => ['root','developer','admin']],
        ['name' => 'profitCenter',        'displayName' => 'Profitcenter',           'icon' => 'profitCenter',   'link' => route('legacy.show', ['path' => 'admin/profitCenter']),     'roles' => ['root','developer','admin']],
        ['name' => 'fileBatchUpload',     'displayName' => 'Tömeges Feltöltés',      'icon' => 'upload',         'link' => route('legacy.show', ['path' => 'admin/fileBatchUpload']),  'roles' => ['root','developer','admin']],
        ['name' => 'statistics',          'displayName' => 'Statisztikák',           'icon' => 'kimutatasok',    'link' => route('legacy.show', ['path' => 'admin/statistics']),       'roles' => ['root','developer','admin']],
        ['name' => 'export',              'displayName' => 'Export',                 'icon' => 'export',         'link' => route('legacy.show', ['path' => 'admin/export']),           'roles' => ['root','developer','admin']],
        ['name' => 'priceListProcessor',  'displayName' => 'Árlista feldolgozó',     'icon' => 'price_list',     'link' => '/admin/pricelist-files',                                   'roles' => ['root','developer','admin']],
        ['name' => 'delivery',            'displayName' => 'Szállítás',              'icon' => 'timetable3',    'roles' => ['root','admin','developer'], 'children' => [
            ['displayName' => 'Szállítási sablonok', 'link' => \App\Filament\Resources\DeliverySchedules\DeliveryScheduleResource::getUrl()],
            ['displayName' => 'Beszállítói felülbírálások', 'link' => \App\Filament\Resources\DeliveryCalendarOverrides\DeliveryCalendarOverrideResource::getUrl()],
            ['displayName' => 'Profitcenter ütemezés', 'link' => \App\Filament\Resources\ProfitCenterSupplierSchedules\ProfitCenterSupplierScheduleResource::getUrl()],
            ['displayName' => 'Munkanaptárak', 'link' => \App\Filament\Resources\WorkCalendars\WorkCalendarResource::getUrl()],
        ]],
        ['name' => 'calendarTest', 'displayName' => 'Naptár Teszt', 'icon' => 'idopontok', 'link' => \App\Filament\Pages\CalendarTest::getUrl(), 'roles' => ['root','developer','admin']],
    ];
@endphp

<nav class="fi-speed-button-nav flex items-center h-full ml-4 w-full">
    <!-- Alkalmazás neve elrejtve a topbar-ból -->
    <style>
        .fi-topbar-header-container > a { display: none !important; }
        .fi-breadcrumbs { display: none !important; }

        .fi-topbar-content-start > a { display: none !important; }
        .fi-topbar-nav { display: none !important; }
        .fi-header-heading-group { display: none !important; }
    </style>
    <ul class="flex items-center gap-x-1">
        @foreach ($modules as $module)
            @role($module['roles'])
                @php
                    $isActive = isset($module['link']) ? request()->is(ltrim(parse_url($module['link'], PHP_URL_PATH), '/') . '*') : false;
                    if (!$isActive && isset($module['children'])) {
                        foreach ($module['children'] as $child) {
                            if (request()->is(ltrim(parse_url($child['link'], PHP_URL_PATH), '/') . '*')) {
                                $isActive = true;
                                break;
                            }
                        }
                    }
                @endphp
                <li class="flex-none relative" x-data="{ open: false }" @mouseenter="open = true" @mouseleave="open = false">
                    @if(isset($module['children']))
                        <button type="button"
                           title="{{ $module['displayName'] }}"
                           class="flex flex-col items-center justify-center w-[110px] h-[105px] rounded-md transition-colors duration-200 {{ $isActive ? 'bg-white/50 shadow-inner' : 'hover:bg-white/30' }}">
                            <img src="{{ asset('images/icons/ico_'.$module['icon'].'.png') }}"
                                 class="w-16 h-16 object-contain mb-1"
                                 alt="">
                            <span class="text-[11px] font-bold text-[#453821] truncate w-full text-center px-1 leading-tight">
                                {{ $module['displayName'] }}
                            </span>
                        </button>
                        <div x-show="open"
                             x-transition
                             class="absolute top-[100px] left-0 z-50 w-[200px] bg-white border border-gray-200 rounded-md shadow-lg py-1"
                             style="display: none;">
                            @foreach($module['children'] as $child)
                                <a href="{{ $child['link'] }}" class="block px-4 py-2 text-sm text-[#453821] hover:bg-gray-100 font-bold">
                                    {{ $child['displayName'] }}
                                </a>
                            @endforeach
                        </div>
                    @else
                        <a href="{{ $module['link'] }}"
                           title="{{ $module['displayName'] }}"
                           class="flex flex-col items-center justify-center w-[110px] h-[105px] rounded-md transition-colors duration-200 {{ $isActive ? 'bg-white/50 shadow-inner' : 'hover:bg-white/30' }}">
                            <img src="{{ asset('images/icons/ico_'.$module['icon'].'.png') }}"
                                 class="w-16 h-16 object-contain mb-1"
                                 alt="">
                            <span class="text-[11px] font-bold text-[#453821] truncate w-full text-center px-1 leading-tight">
                                {{ $module['displayName'] }}
                            </span>
                        </a>
                    @endif
                </li>
            @endrole
        @endforeach
    </ul>
    @if (env('APP_STAGE', 'DEV') != 'PROD')
        <h2 class="text-[#b83400] font-bold text-lg ml-4">site:{{ env('APP_STAGE', 'DEV') }}</h2>
    @endif
    <div class="ml-auto flex items-center pr-2">
        <img style="max-width: none; height: 59px; vertical-align: middle; margin-top: 20px;"
             src="{{ asset('images/pictures/Delirest_logo_green_128x59.png') }}"
             alt="Delirest logo">
    </div>
</nav>

<style>
    /* Biztosítjuk, hogy a topbar ne essen szét */
    .fi-topbar {
        height: auto !important;
    }
    .fi-topbar-content {
        height: auto !important;
        min-height: 64px;
        padding-top: 4px;
        padding-bottom: 4px;
    }
</style>
