
<div class="w-full" style="font-size:14px; display:flex; flex-direction:column; gap:14px;">

    
    <?php if (isset($component)) { $__componentOriginal2544aeb3df80db4e8cf42f27632fe7f3 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginal2544aeb3df80db4e8cf42f27632fe7f3 = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.cabecera','data' => ['volver' => ['ruta' => route('configurations.index'), 'texto' => 'Configuración'],'rotulo' => 'Configuración','titulo' => 'API de administración','descripcion' => 'Los tokens con los que Sistemas automatiza las altas de plataformas en el Manager: clientes, licencias y entornos. Cada token solo puede hacer lo que se le marca al crearlo, y se puede revocar en cualquier momento.']] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('cabecera'); ?>
<?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(['volver' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute(['ruta' => route('configurations.index'), 'texto' => 'Configuración']),'rotulo' => 'Configuración','titulo' => 'API de administración','descripcion' => 'Los tokens con los que Sistemas automatiza las altas de plataformas en el Manager: clientes, licencias y entornos. Cada token solo puede hacer lo que se le marca al crearlo, y se puede revocar en cualquier momento.']); ?>

         <?php $__env->slot('icono', null, []); ?> 
            <?php if (isset($component)) { $__componentOriginalb86967db162ccc0bceeb1ac50f169b8f = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginalb86967db162ccc0bceeb1ac50f169b8f = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.nav-icon','data' => ['name' => 'settings','tint' => 'orange']] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('nav-icon'); ?>
<?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(['name' => 'settings','tint' => 'orange']); ?>
<?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginalb86967db162ccc0bceeb1ac50f169b8f)): ?>
<?php $attributes = $__attributesOriginalb86967db162ccc0bceeb1ac50f169b8f; ?>
<?php unset($__attributesOriginalb86967db162ccc0bceeb1ac50f169b8f); ?>
<?php endif; ?>
<?php if (isset($__componentOriginalb86967db162ccc0bceeb1ac50f169b8f)): ?>
<?php $component = $__componentOriginalb86967db162ccc0bceeb1ac50f169b8f; ?>
<?php unset($__componentOriginalb86967db162ccc0bceeb1ac50f169b8f); ?>
<?php endif; ?>
         <?php $__env->endSlot(); ?>

         <?php $__env->slot('acciones', null, []); ?> 
            
            <a href="<?php echo e(route('configurations.api-tokens.docs')); ?>"
               class="inline-flex items-center gap-1.5 rounded-lg border px-3.5 py-2 text-[13px] font-semibold"
               style="border-color:var(--border-default); background:var(--surface-card); color:var(--text-link);">
                <svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round"><path d="M2 3h6a4 4 0 0 1 4 4v14a3 3 0 0 0-3-3H2z"/><path d="M22 3h-6a4 4 0 0 0-4 4v14a3 3 0 0 1 3-3h7z"/></svg>
                Documentación de la API (Swagger)
            </a>
         <?php $__env->endSlot(); ?>
     <?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginal2544aeb3df80db4e8cf42f27632fe7f3)): ?>
<?php $attributes = $__attributesOriginal2544aeb3df80db4e8cf42f27632fe7f3; ?>
<?php unset($__attributesOriginal2544aeb3df80db4e8cf42f27632fe7f3); ?>
<?php endif; ?>
<?php if (isset($__componentOriginal2544aeb3df80db4e8cf42f27632fe7f3)): ?>
<?php $component = $__componentOriginal2544aeb3df80db4e8cf42f27632fe7f3; ?>
<?php unset($__componentOriginal2544aeb3df80db4e8cf42f27632fe7f3); ?>
<?php endif; ?>

    <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php $__currentLoopData = ['success' => 'success', 'warning' => 'warning', 'error' => 'danger']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $clave => $color): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
        <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if(session($clave)): ?>
            <div class="rounded-lg px-4 py-2.5 text-[13px]"
                 style="background:var(--<?php echo e($color); ?>-50); color:var(--<?php echo e($color); ?>-500);">
                <?php echo e(session($clave)); ?>

            </div>
        <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>

    
    
    <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($recienCreado): ?>
        <section class="rounded-xl border-2 px-5 pb-4 pt-3.5"
                 style="background:var(--warning-50); border-color:var(--warning-500);"
                 x-data="{ copiado: false }">
            <h2 style="font-family:'Plus Jakarta Sans',sans-serif; font-size:15px; font-weight:700; color:var(--text-strong); margin:0;">
                Token «<?php echo e($recienCreado['nombre']); ?>» creado: cópialo ahora
            </h2>
            <div class="mt-0.5 text-[12.5px]" style="color:var(--text-body);">
                <strong>No se volverá a ver.</strong> El Manager solo guarda una huella del token,
                no el token: si lo pierdes, revócalo y crea otro. Cópialo antes de hacer nada más
                en esta página y guárdalo en el gestor de secretos de Sistemas.
            </div>

            <div class="mt-3 flex flex-wrap items-center gap-2">
                <code class="min-w-0 flex-1 break-all rounded-lg border px-3 py-2 font-mono text-[13px]"
                      style="border-color:var(--border-default); background:var(--surface-card); color:var(--text-strong);"><?php echo e($recienCreado['token']); ?></code>
                <button type="button"
                        @click="copiado = await copiarAlPortapapeles(<?php echo \Illuminate\Support\Js::from($recienCreado['token'])->toHtml() ?>); setTimeout(() => copiado = false, 2000)"
                        class="flex-none rounded-lg px-4 py-2 text-[13px] font-semibold text-white"
                        style="background:var(--orange-500);">
                    <span x-text="copiado ? '¡Copiado!' : 'Copiar'">Copiar</span>
                </button>
            </div>

            <div class="mt-3">
                <button type="button" wire:click="cerrarAviso"
                        class="text-[12.5px] font-semibold" style="color:var(--text-link);">
                    Ya lo he guardado, cerrar
                </button>
            </div>
        </section>
    <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>

    
    <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('admin.api-tokens.create')): ?>
        <section class="rounded-xl border px-5 pb-4 pt-3.5"
                 style="background:var(--surface-card); border-color:var(--border-subtle);">
            <h2 style="font-family:'Plus Jakarta Sans',sans-serif; font-size:15px; font-weight:700; color:var(--text-strong); margin:0;">
                Crear un token
            </h2>
            <div class="mt-0.5 max-w-3xl text-[12px]" style="color:var(--text-muted);">
                Uno por script o integración, con un nombre que diga para qué es: así, si hay que
                cortar uno, se corta solo ese. Marca solo lo que vaya a necesitar.
            </div>

            <form wire:submit="crear" class="mt-3 flex flex-col gap-3">
                <div class="flex flex-wrap items-start gap-3">
                    <div class="min-w-[240px] flex-[2]">
                        <label for="at-nombre" class="text-[11px] font-semibold uppercase tracking-[0.05em]"
                               style="color:var(--text-muted);">
                            Nombre
                        </label>
                        <input id="at-nombre" type="text" wire:model="nombre"
                               placeholder="Script de altas de Sistemas"
                               class="mt-1 w-full rounded-lg border px-3 py-2 text-[13px] outline-none focus:ring-0"
                               style="border-color:var(--border-default); background:var(--surface-page); color:var(--text-body);">
                        <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php $__errorArgs = ['nombre'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                            <div class="mt-1 text-[12px]" style="color:var(--danger-500);"><?php echo e($message); ?></div>
                        <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                    </div>

                    <div class="min-w-[180px] flex-1">
                        <label for="at-caducidad" class="text-[11px] font-semibold uppercase tracking-[0.05em]"
                               style="color:var(--text-muted);">
                            Caduca el <span class="font-normal normal-case">(opcional)</span>
                        </label>
                        <input id="at-caducidad" type="date" wire:model="caducidad"
                               min="<?php echo e(now()->addDay()->format('Y-m-d')); ?>"
                               class="mt-1 w-full rounded-lg border px-3 py-2 text-[13px] outline-none focus:ring-0"
                               style="border-color:var(--border-default); background:var(--surface-page); color:var(--text-body);">
                        <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php $__errorArgs = ['caducidad'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                            <div class="mt-1 text-[12px]" style="color:var(--danger-500);"><?php echo e($message); ?></div>
                        <?php else: ?>
                            
                            <div class="mt-1 text-[11.5px]" style="color:var(--text-subtle);">
                                Sin fecha no caduca nunca. Mejor ponerle una: un año, por ejemplo.
                            </div>
                        <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                    </div>
                </div>

                <fieldset>
                    <legend class="text-[11px] font-semibold uppercase tracking-[0.05em]"
                            style="color:var(--text-muted);">
                        Qué puede hacer
                    </legend>
                    <div class="mt-1.5 grid grid-cols-1 gap-x-6 gap-y-1.5 sm:grid-cols-2">
                        <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php $__currentLoopData = $catalogo; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $ability => $etiqueta): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <label class="flex cursor-pointer items-start gap-2 text-[13px]" style="color:var(--text-body);">
                                <input type="checkbox" wire:model="permisos" value="<?php echo e($ability); ?>"
                                       class="mt-0.5 rounded" style="border-color:var(--border-default);">
                                <span>
                                    <?php echo e($etiqueta); ?>

                                    <span class="font-mono text-[11px]" style="color:var(--text-subtle);"><?php echo e($ability); ?></span>
                                </span>
                            </label>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                    </div>
                    <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php $__errorArgs = ['permisos'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                        <div class="mt-1 text-[12px]" style="color:var(--danger-500);"><?php echo e($message); ?></div>
                    <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                    <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php $__errorArgs = ['permisos.*'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                        <div class="mt-1 text-[12px]" style="color:var(--danger-500);"><?php echo e($message); ?></div>
                    <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                </fieldset>

                <div>
                    <button type="submit" wire:loading.attr="disabled"
                            class="rounded-lg px-4 py-2 text-[13px] font-semibold text-white disabled:opacity-60"
                            style="background:var(--orange-500);">
                        Crear token
                    </button>
                </div>
            </form>
        </section>
    <?php endif; ?>

    
    <section class="overflow-hidden rounded-xl border"
             style="background:var(--surface-card); border-color:var(--border-subtle);">
        <div class="flex flex-wrap items-baseline justify-between gap-4 px-5 pb-2.5 pt-3.5">
            <h2 style="font-family:'Plus Jakarta Sans',sans-serif; font-size:15px; font-weight:700; color:var(--text-strong); margin:0;">
                Tokens emitidos
            </h2>
            <span class="text-[12px]" style="color:var(--text-muted);">
                <?php echo e($tokens->count()); ?> <?php echo e($tokens->count() === 1 ? 'token' : 'tokens'); ?>

            </span>
        </div>

        <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php $__empty_1 = true; $__currentLoopData = $tokens; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $token): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
            <div class="apitok-grid border-t px-5 py-2.5 text-[12.5px] hover:bg-[var(--surface-alt)]"
                 style="border-color:var(--divider);"
                 wire:key="token-<?php echo e($token['id']); ?>"
                 x-data="{ confirmando: false }">
                <div class="min-w-0">
                    <div class="truncate font-semibold" style="color:var(--text-strong);">
                        <?php echo e($token['nombre']); ?>

                    </div>
                    <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($token['caducado']): ?>
                        <span class="rounded-full px-2 py-px text-[11px] font-semibold"
                              style="color:var(--danger-500); background:var(--danger-50);">caducado</span>
                    <?php else: ?>
                        <span class="rounded-full px-2 py-px text-[11px] font-semibold"
                              style="color:var(--success-500); background:var(--success-50);">activo</span>
                    <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                </div>

                <div class="flex min-w-0 flex-wrap gap-1">
                    <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php $__empty_2 = true; $__currentLoopData = $token['permisos']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $etiqueta): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_2 = false; ?>
                        <span class="rounded px-1.5 py-px text-[11.5px]"
                              style="color:var(--text-body); background:var(--surface-sunken);"><?php echo e($etiqueta); ?></span>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_2): ?>
                        <span style="color:var(--text-subtle);">sin permisos</span>
                    <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                </div>

                <div class="text-[12px]" style="color:var(--text-muted);">
                    <div title="<?php echo e($token['creado']?->format('d/m/Y H:i')); ?>">
                        creado <?php echo e($token['creado']?->format('d/m/Y')); ?>

                    </div>
                    <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($token['usado']): ?>
                        <div title="<?php echo e($token['usado']->format('d/m/Y H:i')); ?>">
                            usado <?php echo e($token['usado']->diffForHumans()); ?>

                        </div>
                    <?php else: ?>
                        <div style="color:var(--text-subtle);">nunca usado</div>
                    <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                </div>

                <div class="text-[12px]" style="color:var(--text-muted);">
                    <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($token['caduca']): ?>
                        <?php echo e($token['caducado'] ? 'caducó el' : 'caduca el'); ?>

                        <?php echo e($token['caduca']->format('d/m/Y')); ?>

                    <?php else: ?>
                        <span style="color:var(--warning-500);">no caduca</span>
                    <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                </div>

                <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('admin.api-tokens.destroy')): ?>
                    
                    <div class="justify-self-start lg:justify-self-end">
                        <button type="button" x-show="!confirmando" @click="confirmando = true"
                                class="text-[12px] font-semibold" style="color:var(--danger-500);"
                                title="Lo que use este token dejará de funcionar al momento.">
                            Revocar
                        </button>
                        <div x-show="confirmando" x-cloak class="flex flex-col items-start gap-1 lg:items-end">
                            <span class="text-[11.5px]" style="color:var(--text-muted);">¿Seguro? No se deshace.</span>
                            <div class="flex gap-3">
                                <button type="button" wire:click="revocar(<?php echo e($token['id']); ?>)"
                                        class="text-[12px] font-semibold" style="color:var(--danger-500);">
                                    Sí, revocar
                                </button>
                                <button type="button" @click="confirmando = false"
                                        class="text-[12px]" style="color:var(--text-muted);">
                                    Cancelar
                                </button>
                            </div>
                        </div>
                    </div>
                <?php else: ?>
                    <span></span>
                <?php endif; ?>
            </div>
        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
            <div class="border-t px-5 py-6 text-center text-[13px]"
                 style="border-color:var(--divider); color:var(--text-muted);">
                Todavía no se ha emitido ningún token. Hasta que no se cree uno, nadie puede usar la
                API de administración.
            </div>
        <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
    </section>
</div><?php /**PATH /var/www/html/resources/views/livewire/configurations/api-tokens.blade.php ENDPATH**/ ?>