<?php
    $route = request()->route()?->getName() ?? '';

    // Definición del menú completa
    $menu = [
        'plataforma' => [
            'label' => 'Plataforma',
            'icon'  => 'server',
            'routes' => ['sites.*','types.*', 'supports.*'],
            'items' => [
                ['icon' => 'globe-alt', 'route' => 'sites.index', 'text' => 'Sitios'],
                ['icon' => 'adjustments-horizontal', 'route' => 'types.index', 'text' => 'Tipos de sitio'],
                ['icon' => 'lifebuoy', 'route' => 'supports.index', 'text' => 'Tipos de soporte'],
            ]
        ],

        'usuarios' => [
            'label' => 'Usuarios',
            'icon'  => 'users',
            'routes' => ['users.*', 'roles.*', 'permissions.*'],
            'items' => [
                ['icon' => 'user', 'route' => 'users.index', 'text' => 'Usuarios'],
                ['icon' => 'shield-check', 'route' => 'roles.index', 'text' => 'Roles'],
                ['icon' => 'key', 'route' => 'permissions.index', 'text' => 'Permisos'],
            ]
        ],

        'clientes' => [
            'label' => 'Clientes',
            'icon'  => 'briefcase',
            'routes' => ['clients.*'],
            'items' => [
                ['icon' => 'building-office', 'route' => 'clients.index', 'text' => 'Clientes'],
            ]
        ],

        'licencias' => [
            'label' => 'Licencias',
            'icon'  => 'key',
            'routes' => ['products.*', 'license_tokens.*'],
            'items' => [
                ['icon' => 'cube', 'route' => 'products.index', 'text' => 'Productos'],
                ['icon' => 'finger-print', 'route' => 'license_tokens.index', 'text' => 'Tokens'],
            ]
        ],

        'config' => [
            'label' => 'Configuración',
            'icon'  => 'cog-6-tooth',
            'routes' => ['configs.*'],
            'items' => [
                ['icon' => 'wrench-screwdriver', 'route' => 'configs.index', 'text' => 'Parámetros'],
            ]
        ],

        'registros' => [
            'label' => 'Registros',
            'icon'  => 'document-text',
            'routes' => ['logs.*','notices.*'],
            'items' => [
                ['icon' => 'clipboard-document', 'route' => 'logs.index', 'text' => 'Logs'],
                ['icon' => 'bell-alert', 'route' => 'notices.index', 'text' => 'Avisos'],
            ]
        ],

        'reportes' => [
            'label' => 'Reportes',
            'icon'  => 'chart-bar',
            'routes' => ['reports.*'],
            'items' => [] // vacío por ahora
        ],
    ];

    // Determinar qué sección debe abrirse
    $open = collect($menu)
    ->first(fn($g) =>
        collect($g['routes'])->contains(fn($r) => request()->routeIs($r))
    )['label'] ?? null;

?>

<div x-data="{ open: '<?php echo e($open); ?>' }" class="space-y-5">

    
    <div class="px-4 pt-3 pb-1">
        <img
            src="<?php echo e(asset('images/tresipunt.png')); ?>"
            alt="Tresipunt Manager"
            class="h-10 w-auto opacity-90"
        >
    </div>

<?php $__currentLoopData = $menu; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key => $group): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
        <div class="px-2">

            
            <button
                @click="open = (open === '<?php echo e($group['label']); ?>') ? null : '<?php echo e($group['label']); ?>'"
                class="flex w-full items-center justify-between px-3 py-2.5
                       rounded-lg bg-white shadow-sm
                       hover:bg-gray-50 active:bg-gray-100
                       transition duration-150 border border-gray-200"
            >
                <span class="flex items-center space-x-3">
                    <?php if (isset($component)) { $__componentOriginal511d4862ff04963c3c16115c05a86a9d = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginal511d4862ff04963c3c16115c05a86a9d = $attributes; } ?>
<?php $component = Illuminate\View\DynamicComponent::resolve(['component' => 'icon.' . $group['icon']] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('dynamic-component'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag): ?>
<?php $attributes = $attributes->except(\Illuminate\View\DynamicComponent::ignoredParameterNames()); ?>
<?php endif; ?>
<?php $component->withAttributes(['class' => 'w-5 h-5 text-gray-700 opacity-80']); ?>
<?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginal511d4862ff04963c3c16115c05a86a9d)): ?>
<?php $attributes = $__attributesOriginal511d4862ff04963c3c16115c05a86a9d; ?>
<?php unset($__attributesOriginal511d4862ff04963c3c16115c05a86a9d); ?>
<?php endif; ?>
<?php if (isset($__componentOriginal511d4862ff04963c3c16115c05a86a9d)): ?>
<?php $component = $__componentOriginal511d4862ff04963c3c16115c05a86a9d; ?>
<?php unset($__componentOriginal511d4862ff04963c3c16115c05a86a9d); ?>
<?php endif; ?>
                    <span class="font-medium text-gray-800 tracking-tight">
                        <?php echo e($group['label']); ?>

                    </span>
                </span>

                <?php if (isset($component)) { $__componentOriginalaf73b0b04d41c4be26aea89fbf545dfa = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginalaf73b0b04d41c4be26aea89fbf545dfa = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.icon.chevron-down','data' => ['class' => 'w-4 h-4 text-gray-600 transition-transform duration-300','xBind:class' => '{ \'rotate-180\': open === \''.e($group['label']).'\' }']] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('icon.chevron-down'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag): ?>
<?php $attributes = $attributes->except(\Illuminate\View\AnonymousComponent::ignoredParameterNames()); ?>
<?php endif; ?>
<?php $component->withAttributes(['class' => 'w-4 h-4 text-gray-600 transition-transform duration-300','x-bind:class' => '{ \'rotate-180\': open === \''.e($group['label']).'\' }']); ?>
<?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginalaf73b0b04d41c4be26aea89fbf545dfa)): ?>
<?php $attributes = $__attributesOriginalaf73b0b04d41c4be26aea89fbf545dfa; ?>
<?php unset($__attributesOriginalaf73b0b04d41c4be26aea89fbf545dfa); ?>
<?php endif; ?>
<?php if (isset($__componentOriginalaf73b0b04d41c4be26aea89fbf545dfa)): ?>
<?php $component = $__componentOriginalaf73b0b04d41c4be26aea89fbf545dfa; ?>
<?php unset($__componentOriginalaf73b0b04d41c4be26aea89fbf545dfa); ?>
<?php endif; ?>
            </button>

            
            <div
                x-show="open === '<?php echo e($group['label']); ?>'"
                x-collapse
                class="mt-2 ml-4 space-y-1 border-l border-gray-200 pl-4"
            >
                <?php $__currentLoopData = $group['items']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <?php if (isset($component)) { $__componentOriginal3d3185cbc95d2b4d3b41182ae7d7a300 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginal3d3185cbc95d2b4d3b41182ae7d7a300 = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.sidebar-link','data' => ['icon' => $item['icon'],'route' => $item['route'],'text' => $item['text']]] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('sidebar-link'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag): ?>
<?php $attributes = $attributes->except(\Illuminate\View\AnonymousComponent::ignoredParameterNames()); ?>
<?php endif; ?>
<?php $component->withAttributes(['icon' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute($item['icon']),'route' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute($item['route']),'text' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute($item['text'])]); ?>
<?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginal3d3185cbc95d2b4d3b41182ae7d7a300)): ?>
<?php $attributes = $__attributesOriginal3d3185cbc95d2b4d3b41182ae7d7a300; ?>
<?php unset($__attributesOriginal3d3185cbc95d2b4d3b41182ae7d7a300); ?>
<?php endif; ?>
<?php if (isset($__componentOriginal3d3185cbc95d2b4d3b41182ae7d7a300)): ?>
<?php $component = $__componentOriginal3d3185cbc95d2b4d3b41182ae7d7a300; ?>
<?php unset($__componentOriginal3d3185cbc95d2b4d3b41182ae7d7a300); ?>
<?php endif; ?>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            </div>

        </div>
    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>

</div>
<?php /**PATH /var/www/html/resources/views/components/sidebar.blade.php ENDPATH**/ ?>