<?php
    use App\Enums\NocTrackingStatus;
    use App\Enums\WorkStatus;
?>

<div>
    <div class="mb-2">
        <h1 class="text-2xl font-bold text-[var(--setel-text)]">Panel NOC</h1>
        <p class="mt-1 text-sm text-[var(--setel-text-muted)]">
            Vista global de OT: cierre de pendientes/observadas y revisión de cerradas.
        </p>
    </div>

    <div class="grid gap-4 sm:grid-cols-2 xl:grid-cols-3">
        <div class="setel-card p-5">
            <p class="text-sm text-[var(--setel-text-muted)]">OT en sistema</p>
            <p class="mt-1 text-3xl font-bold tabular-nums text-[var(--setel-text)]"><?php echo e(number_format((int) ($stats['queue_total'] ?? 0))); ?></p>
            <p class="mt-2 text-xs text-[var(--setel-text-muted)]">Total registrado</p>
        </div>
        <div class="setel-card p-5">
            <p class="text-sm text-[var(--setel-text-muted)]">Pendiente seguimiento</p>
            <p class="mt-1 text-3xl font-bold tabular-nums text-[var(--setel-text)]"><?php echo e(number_format((int) ($stats['noc_pendiente'] ?? 0))); ?></p>
        </div>
        <div class="setel-card p-5">
            <p class="text-sm text-[var(--setel-text-muted)]">Observadas</p>
            <p class="mt-1 text-3xl font-bold tabular-nums text-[var(--setel-text)]"><?php echo e(number_format((int) ($stats['noc_observado'] ?? 0))); ?></p>
        </div>
        <div class="setel-card p-5">
            <p class="text-sm text-[var(--setel-text-muted)]">Cerradas (tracking)</p>
            <p class="mt-1 text-3xl font-bold tabular-nums text-[var(--setel-text)]"><?php echo e(number_format((int) ($stats['noc_cerrado'] ?? 0))); ?></p>
        </div>
        <div class="setel-card p-5">
            <p class="text-sm text-[var(--setel-text-muted)]">Cierres este mes</p>
            <p class="mt-1 text-3xl font-bold tabular-nums text-[var(--setel-text)]"><?php echo e(number_format((int) ($stats['noc_closed_month'] ?? 0))); ?></p>
            <p class="mt-2 text-xs text-[var(--setel-text-muted)]">OT con seguimiento NOC cerrado y actualización en <?php echo e(now()->translatedFormat('F')); ?></p>
        </div>
        <div class="setel-card border-l-4 border-l-amber-500 p-5">
            <p class="text-sm text-[var(--setel-text-muted)]">SLA vencido en cola</p>
            <p class="mt-1 text-3xl font-bold tabular-nums text-amber-700 dark:text-amber-400"><?php echo e(number_format((int) ($stats['sla_breached_queue'] ?? 0))); ?></p>
        </div>
    </div>

    <div class="setel-card overflow-hidden">
        <div class="flex items-center justify-between border-b border-[var(--setel-card-border)] px-5 py-4">
            <h2 class="text-lg font-semibold text-[var(--setel-text)]">Últimas OT actualizadas</h2>
            <div class="flex flex-wrap gap-3">
                <a href="<?php echo e(route('noc.tracking.open')); ?>" wire:navigate class="text-sm font-medium text-[var(--setel-primary)] hover:underline">Pendientes / observadas</a>
                <a href="<?php echo e(route('noc.tracking.review')); ?>" wire:navigate class="text-sm font-medium text-[var(--setel-primary)] hover:underline">Cerradas (revisión)</a>
            </div>
        </div>
        <div class="setel-table-wrap">
            <table class="setel-table">
                <thead>
                    <tr>
                        <th>OT</th>
                        <th>Sitio</th>
                        <th>Técnico</th>
                        <th>Estado OT</th>
                        <th>Seguimiento NOC</th>
                        <th>Actualizado</th>
                    </tr>
                </thead>
                <tbody>
                    <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php \Livewire\Features\SupportCompiledWireKeys\SupportCompiledWireKeys::openLoop(); ?><?php endif; ?><?php $__empty_1 = true; $__currentLoopData = $stats['recent_works'] ?? []; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $work): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><?php \Livewire\Features\SupportCompiledWireKeys\SupportCompiledWireKeys::startLoopIteration(); ?><?php endif; ?>
                        <tr>
                            <td class="font-mono text-xs">
                                <a href="<?php echo e(route('works.show', $work)); ?>" wire:navigate class="text-[var(--setel-primary)] hover:underline"><?php echo e($work->ot); ?></a>
                            </td>
                            <td><?php echo e($work->site?->name ?? '—'); ?></td>
                            <td class="text-sm"><?php echo e($work->technician?->fullName() ?? '—'); ?></td>
                            <td>
                                <?php $st = WorkStatus::tryFrom((string) $work->work_status); ?>
                                <span class="<?php echo e($st?->badgeClass() ?? 'setel-badge setel-badge--neutral'); ?> text-xs"><?php echo e($st?->label() ?? $work->work_status); ?></span>
                            </td>
                            <td>
                                <?php $nt = NocTrackingStatus::tryFrom((string) ($work->noc_tracking_status ?? '')); ?>
                                <span class="<?php echo e($nt?->badgeClass() ?? 'setel-badge setel-badge--neutral'); ?> text-xs"><?php echo e($nt?->label() ?? ($work->noc_tracking_status ?? '—')); ?></span>
                            </td>
                            <td class="text-xs text-[var(--setel-text-muted)]"><?php echo e($work->updated_at?->format('d/m/Y H:i')); ?></td>
                        </tr>
                    <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><?php \Livewire\Features\SupportCompiledWireKeys\SupportCompiledWireKeys::endLoop(); ?><?php endif; ?><?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><?php \Livewire\Features\SupportCompiledWireKeys\SupportCompiledWireKeys::closeLoop(); ?><?php endif; ?>
                        <tr>
                            <td colspan="6" class="py-8 text-center text-sm text-[var(--setel-text-muted)]">No hay OT recientes.</td>
                        </tr>
                    <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                </tbody>
            </table>
        </div>
    </div>
</div>
<?php /**PATH C:\laragon\www\setelsat-gilat-manager\resources\views/livewire/dashboard/variants/noc.blade.php ENDPATH**/ ?>