<?php $attributes ??= new \Illuminate\View\ComponentAttributeBag;

$__newAttributes = [];
$__propNames = \Illuminate\View\ComponentAttributeBag::extractPropNames((['selected']));

foreach ($attributes->all() as $__key => $__value) {
    if (in_array($__key, $__propNames)) {
        $$__key = $$__key ?? $__value;
    } else {
        $__newAttributes[$__key] = $__value;
    }
}

$attributes = new \Illuminate\View\ComponentAttributeBag($__newAttributes);

unset($__propNames);
unset($__newAttributes);

foreach (array_filter((['selected']), 'is_string', ARRAY_FILTER_USE_KEY) as $__key => $__value) {
    $$__key = $$__key ?? $__value;
}

$__defined_vars = get_defined_vars();

foreach ($attributes->all() as $__key => $__value) {
    if (array_key_exists($__key, $__defined_vars)) unset($$__key);
}

unset($__defined_vars, $__key, $__value); ?>


<?php
    use App\Models\Environments\Plugin;
    use App\Models\Environments\Environment;

    $estado = \Illuminate\Support\Facades\Cache::remember('plugins:menu', 60, function () {
        // **La prueba de que hay datos**, que es lo que hace que el verde signifique algo.
        // Sin ningún entorno enviando inventario, «cero componentes con actualización» no
        // dice que el parque esté al día: dice que no sabemos nada de él.
        $envian = Plugin::distinct()->count('environment_id');

        if ($envian === 0) {
            return ['vacio' => true];
        }

        return [
            'vacio' => false,
            // Componentes con alguna actualización pendiente en algún sitio. `has_updates`
            // es la marca que manda el propio Moodle, que es de donde sale el resto de la
            // sección: calcularlo aquí de otra forma daría dos números distintos.
            'actualizables' => Plugin::where('has_updates', true)->distinct()->count('component'),
        ];
    });

    $paginas = [
        ['clave' => 'resumen', 'ruta' => 'plugins.index', 'titulo' => 'Resumen'],
        ['clave' => 'nuestros', 'ruta' => 'plugins.nuestros', 'titulo' => 'Plugins Tresipunt'],
        ['clave' => 'sin-instalar', 'ruta' => 'plugins.sin-instalar', 'titulo' => 'Licenciado y sin instalar'],
        ['clave' => 'inventario', 'ruta' => 'plugins.inventario', 'titulo' => 'Inventario', 'aviso' => $estado['vacio'] ? null : ($estado['actualizables'] ?: null)],
        ['clave' => 'core', 'ruta' => 'plugins.core', 'titulo' => 'Versiones de Moodle'],
    ];
?>

<div class="flex flex-wrap items-center gap-1.5">
    <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php $__currentLoopData = $paginas; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $pagina): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
        <?php $activa = $selected === $pagina['clave']; ?>

        <a href="<?php echo e(route($pagina['ruta'])); ?>" wire:navigate
           class="flex items-center gap-2 rounded-lg border px-3 py-1.5 text-[12.5px] font-semibold"
           style="border-color:<?php echo e($activa ? 'var(--text-strong)' : 'var(--border-default)'); ?>;
                  background:<?php echo e($activa ? 'var(--surface-card)' : 'transparent'); ?>;
                  color:<?php echo e($activa ? 'var(--text-strong)' : 'var(--text-muted)'); ?>;">
            <?php echo e($pagina['titulo']); ?>


            <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if(! empty($pagina['aviso'])): ?>
                <span class="rounded px-1.5 py-px text-[10.5px] font-bold"
                      title="Con actualización disponible"
                      style="color:var(--warning-500); background:var(--warning-50);"><?php echo e($pagina['aviso']); ?></span>
            <?php elseif($estado['vacio']): ?>
                
                <span class="h-1.5 w-1.5 rounded-full" title="Todavía no hay inventario de ningún sitio"
                      style="background:var(--text-subtle);"></span>
            <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
        </a>
    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
</div><?php /**PATH /var/www/html/resources/views/livewire/plugins/components/menu.blade.php ENDPATH**/ ?>