<?php
    use App\Enums\WorkAssignmentStatus;
    use App\Enums\WorkInternalStatus;
    use App\Enums\WorkStatus;
?>

<?php
    $authUser = auth()->user();
    $backHref = $authUser?->canManageWorksCatalog()
        ? route('works.index')
        : ($authUser?->isTechnician()
            ? route('assignments.index')
            : ($authUser?->isNoc() ? route('noc.tracking.open') : route('dashboard')));
?>

<div class="flex w-full flex-col gap-6">
    <div class="flex flex-col gap-3 sm:flex-row sm:flex-wrap sm:items-center sm:justify-between">
        <a href="<?php echo e($backHref); ?>" wire:navigate class="setel-btn-secondary inline-flex w-fit items-center gap-2">
            <?php if (isset($component)) { $__componentOriginale41799ef1b2ae0b0e320ff9b21dacd08 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginale41799ef1b2ae0b0e320ff9b21dacd08 = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'e60dd9d2c3a62d619c9acb38f20d5aa5::icon.arrow-left','data' => ['class' => 'size-4 shrink-0']] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('flux::icon.arrow-left'); ?>
<?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' => 'size-4 shrink-0']); ?>
<?php \Livewire\Features\SupportCompiledWireKeys\SupportCompiledWireKeys::processComponentKey($component); ?>

<?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginale41799ef1b2ae0b0e320ff9b21dacd08)): ?>
<?php $attributes = $__attributesOriginale41799ef1b2ae0b0e320ff9b21dacd08; ?>
<?php unset($__attributesOriginale41799ef1b2ae0b0e320ff9b21dacd08); ?>
<?php endif; ?>
<?php if (isset($__componentOriginale41799ef1b2ae0b0e320ff9b21dacd08)): ?>
<?php $component = $__componentOriginale41799ef1b2ae0b0e320ff9b21dacd08; ?>
<?php unset($__componentOriginale41799ef1b2ae0b0e320ff9b21dacd08); ?>
<?php endif; ?>
            Volver
        </a>
    </div>

    <div>
        <h1 class="text-2xl font-bold tracking-tight text-[var(--setel-text)]"><?php echo e($site->code); ?> · <?php echo e($site->name); ?></h1>
        <p class="mt-1 text-sm text-[var(--setel-text-muted)]">
            Todas las asignaciones por día registradas para OT de este sitio (todas las fechas si no filtra por rango).
            <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($site->project): ?>
                <span class="ms-1 inline-flex items-center gap-1">
                    <span class="size-2 shrink-0 rounded-full border border-[var(--setel-card-border)]" style="background-color: <?php echo e($site->project->color ?? '#64748b'); ?>"></span>
                    <?php echo e($site->project->name); ?>

                </span>
            <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
        </p>
    </div>

    <div class="setel-card overflow-hidden">
        <div class="setel-users-filter-strip border-b border-[var(--setel-card-border)] px-5 py-4">
            <p class="mb-3 text-xs font-semibold uppercase tracking-wide text-[var(--setel-text-muted)]">Filtros opcionales</p>
            <div class="grid gap-4 sm:grid-cols-2 lg:grid-cols-4 xl:grid-cols-5">
                <div class="setel-users-filter-field">
                    <label class="setel-users-filter-label" for="site-asg-from">Desde</label>
                    <input id="site-asg-from" type="date" class="setel-input w-full" wire:model.live="dateFrom" />
                </div>
                <div class="setel-users-filter-field">
                    <label class="setel-users-filter-label" for="site-asg-to">Hasta</label>
                    <input id="site-asg-to" type="date" class="setel-input w-full" wire:model.live="dateTo" />
                </div>
                <div class="setel-users-filter-field">
                    <label class="setel-users-filter-label" for="site-asg-status">Estado asignación</label>
                    <select id="site-asg-status" class="setel-input w-full py-0 pe-8" wire:model.live="statusFilter">
                        <option value="">Todos</option>
                        <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php \Livewire\Features\SupportCompiledWireKeys\SupportCompiledWireKeys::openLoop(); ?><?php endif; ?><?php $__currentLoopData = $assignmentStatusCases; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $case): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><?php \Livewire\Features\SupportCompiledWireKeys\SupportCompiledWireKeys::startLoopIteration(); ?><?php endif; ?>
                            <option value="<?php echo e($case->value); ?>"><?php echo e($case->label()); ?></option>
                        <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><?php \Livewire\Features\SupportCompiledWireKeys\SupportCompiledWireKeys::endLoop(); ?><?php endif; ?><?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php \Livewire\Features\SupportCompiledWireKeys\SupportCompiledWireKeys::closeLoop(); ?><?php endif; ?>
                    </select>
                </div>
                <div class="setel-users-filter-field">
                    <label class="setel-users-filter-label" for="site-asg-per">Por página</label>
                    <select id="site-asg-per" class="setel-input w-full py-0 pe-8" wire:model.live="perPage">
                        <option value="15">15</option>
                        <option value="25">25</option>
                        <option value="50">50</option>
                    </select>
                </div>
                <div class="setel-users-filter-field flex items-end">
                    <button type="button" class="setel-btn-secondary h-[2.5rem] w-full px-4 text-sm" wire:click="resetFilters">Limpiar filtros</button>
                </div>
            </div>
        </div>

        <div class="setel-table-wrap max-w-full overflow-x-auto px-5 py-4" wire:loading.class="opacity-60">
            <table class="setel-table min-w-[1200px]">
                <thead>
                    <tr>
                        <th>Fecha día</th>
                        <th>Proyecto</th>
                        <th>OT</th>
                        <th>Tipo</th>
                        <th class="text-center">Estado interno</th>
                        <th class="text-center">Estado externo</th>
                        <th class="text-center">Estado asignación</th>
                        <th class="text-center">Momento del estado</th>
                        <th>Técnico</th>
                        <th>Coordinador</th>
                        <th class="text-center">Hora asign.</th>
                        <th class="text-center">Cierre</th>
                        <th>NOC (cierre)</th>
                        <th class="w-[52px] text-center">
                            <span class="sr-only">Abrir ficha</span>
                            <?php if (isset($component)) { $__componentOriginal2e57535a42d25d5415c31aa83132341b = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginal2e57535a42d25d5415c31aa83132341b = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'e60dd9d2c3a62d619c9acb38f20d5aa5::icon.eye','data' => ['class' => 'mx-auto size-4 text-[var(--setel-text-muted)]','ariaHidden' => 'true']] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('flux::icon.eye'); ?>
<?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' => 'mx-auto size-4 text-[var(--setel-text-muted)]','aria-hidden' => 'true']); ?>
<?php \Livewire\Features\SupportCompiledWireKeys\SupportCompiledWireKeys::processComponentKey($component); ?>

<?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginal2e57535a42d25d5415c31aa83132341b)): ?>
<?php $attributes = $__attributesOriginal2e57535a42d25d5415c31aa83132341b; ?>
<?php unset($__attributesOriginal2e57535a42d25d5415c31aa83132341b); ?>
<?php endif; ?>
<?php if (isset($__componentOriginal2e57535a42d25d5415c31aa83132341b)): ?>
<?php $component = $__componentOriginal2e57535a42d25d5415c31aa83132341b; ?>
<?php unset($__componentOriginal2e57535a42d25d5415c31aa83132341b); ?>
<?php endif; ?>
                        </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 = $this->rows; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $row): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><?php \Livewire\Features\SupportCompiledWireKeys\SupportCompiledWireKeys::startLoopIteration(); ?><?php endif; ?>
                        <tr <?php \Livewire\Features\SupportCompiledWireKeys\SupportCompiledWireKeys::$currentLoop['key'] = 'site-asg-'.e($row->id).''; ?>wire:key="site-asg-<?php echo e($row->id); ?>">
                            <td class="text-sm tabular-nums text-[var(--setel-text)]"><?php echo e($row->workAssignment?->assigned_on?->format('d/m/Y')); ?></td>
                            <td class="text-sm text-[var(--setel-text-muted)]"><?php echo e($row->workAssignment?->work?->site?->project?->name ?? '—'); ?></td>
                            <td class="font-mono text-sm font-semibold"><?php echo e($row->workAssignment?->work?->ot ?? '—'); ?></td>
                            <td class="text-sm text-[var(--setel-text-muted)]"><?php echo e(\Illuminate\Support\Str::limit((string) ($row->workAssignment?->work?->workType?->name ?? ''), 32)); ?></td>
                            <td class="text-center">
                                <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($row->workAssignment?->work): ?>
                                    <span class="<?php echo e(WorkInternalStatus::tryFrom($row->workAssignment->work->internal_status)?->badgeClass() ?? 'setel-badge setel-badge--neutral'); ?> text-xs"><?php echo e(WorkInternalStatus::tryFrom($row->workAssignment->work->internal_status)?->label() ?? $row->workAssignment->work->internal_status); ?></span>
                                <?php else: ?>
                                    <span class="text-xs text-[var(--setel-text-muted)]">—</span>
                                <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                            </td>
                            <td class="text-center">
                                <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($row->workAssignment?->work): ?>
                                    <span class="<?php echo e(WorkStatus::tryFrom($row->workAssignment->work->work_status)?->badgeClass() ?? 'setel-badge setel-badge--neutral'); ?> text-xs"><?php echo e(WorkStatus::tryFrom($row->workAssignment->work->work_status)?->label() ?? $row->workAssignment->work->work_status); ?></span>
                                <?php else: ?>
                                    <span class="text-xs text-[var(--setel-text-muted)]">—</span>
                                <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                            </td>
                            <td class="text-center">
                                <span class="<?php echo e(WorkAssignmentStatus::tryFrom((string) $row->status)?->badgeClass() ?? 'setel-badge setel-badge--neutral'); ?> text-xs">
                                    <?php echo e(WorkAssignmentStatus::tryFrom((string) $row->status)?->label() ?? $row->status); ?>

                                </span>
                            </td>
                            <td class="text-center text-xs tabular-nums text-[var(--setel-text-muted)]"><?php echo e($row->recorded_at?->format('d/m H:i') ?? '—'); ?></td>
                            <td class="text-sm"><?php echo e($row->workAssignment?->technician?->fullName() ?? '—'); ?></td>
                            <td class="text-sm"><?php echo e($row->workAssignment?->coordinator?->fullName() ?? '—'); ?></td>
                            <td class="text-center text-xs tabular-nums text-[var(--setel-text-muted)]"><?php echo e($row->workAssignment?->assigned_at?->format('d/m H:i') ?? '—'); ?></td>
                            <td class="text-center text-xs tabular-nums text-[var(--setel-text-muted)]"><?php echo e($row->workAssignment?->closed_at?->format('d/m H:i') ?? '—'); ?></td>
                            <td class="text-sm text-[var(--setel-text-muted)]"><?php echo e($row->workAssignment?->noc?->fullName() ?? '—'); ?></td>
                            <td class="text-center">
                                <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($row->workAssignment?->work): ?>
                                    <a
                                        href="<?php echo e(route('works.show', $row->workAssignment->work)); ?>"
                                        wire:navigate
                                        class="setel-btn-secondary inline-flex size-9 items-center justify-center p-0 text-xs"
                                        title="Abrir ficha"
                                        aria-label="Abrir ficha de la OT"
                                    >
                                        <?php if (isset($component)) { $__componentOriginal2e57535a42d25d5415c31aa83132341b = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginal2e57535a42d25d5415c31aa83132341b = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'e60dd9d2c3a62d619c9acb38f20d5aa5::icon.eye','data' => ['class' => 'size-3.5 shrink-0']] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('flux::icon.eye'); ?>
<?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' => 'size-3.5 shrink-0']); ?>
<?php \Livewire\Features\SupportCompiledWireKeys\SupportCompiledWireKeys::processComponentKey($component); ?>

<?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginal2e57535a42d25d5415c31aa83132341b)): ?>
<?php $attributes = $__attributesOriginal2e57535a42d25d5415c31aa83132341b; ?>
<?php unset($__attributesOriginal2e57535a42d25d5415c31aa83132341b); ?>
<?php endif; ?>
<?php if (isset($__componentOriginal2e57535a42d25d5415c31aa83132341b)): ?>
<?php $component = $__componentOriginal2e57535a42d25d5415c31aa83132341b; ?>
<?php unset($__componentOriginal2e57535a42d25d5415c31aa83132341b); ?>
<?php endif; ?>
                                    </a>
                                <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                            </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="14" class="py-12 text-center text-sm text-[var(--setel-text-muted)]">Sin asignaciones para este sitio con los filtros actuales.</td>
                        </tr>
                    <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                </tbody>
            </table>
        </div>

        <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($this->rows->hasPages()): ?>
            <div class="border-t border-[var(--setel-card-border)] px-5 py-4">
                <?php echo e($this->rows->links()); ?>

            </div>
        <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
    </div>
</div>
<?php /**PATH C:\laragon\www\setelsat-gilat-manager\resources\views/livewire/works/site-assignments-history.blade.php ENDPATH**/ ?>