

<?php $__env->startSection('title', 'Tickets'); ?>
<?php $__env->startSection('page-title', 'Gestión de Tickets'); ?>

<?php $__env->startSection('content'); ?>
<?php if (isset($component)) { $__componentOriginale19f62b34dfe0bfdf95075badcb45bc2 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginale19f62b34dfe0bfdf95075badcb45bc2 = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.breadcrumb','data' => ['items' => [
    ['label' => 'Tickets', 'icon' => 'ticket', 'active' => true]
]]] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? (array) $attributes->getIterator() : [])); ?>
<?php $component->withName('breadcrumb'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag && $constructor = (new ReflectionClass(Illuminate\View\AnonymousComponent::class))->getConstructor()): ?>
<?php $attributes = $attributes->except(collect($constructor->getParameters())->map->getName()->all()); ?>
<?php endif; ?>
<?php $component->withAttributes(['items' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute([
    ['label' => 'Tickets', 'icon' => 'ticket', 'active' => true]
])]); ?>
<?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginale19f62b34dfe0bfdf95075badcb45bc2)): ?>
<?php $attributes = $__attributesOriginale19f62b34dfe0bfdf95075badcb45bc2; ?>
<?php unset($__attributesOriginale19f62b34dfe0bfdf95075badcb45bc2); ?>
<?php endif; ?>
<?php if (isset($__componentOriginale19f62b34dfe0bfdf95075badcb45bc2)): ?>
<?php $component = $__componentOriginale19f62b34dfe0bfdf95075badcb45bc2; ?>
<?php unset($__componentOriginale19f62b34dfe0bfdf95075badcb45bc2); ?>
<?php endif; ?>

<div class="row mb-3">
    <div class="col-md-6">
        <form method="GET" action="<?php echo e(route('tickets.index')); ?>">
            <div class="input-group">
                <input type="text" class="form-control" name="search" placeholder="Buscar tickets..." value="<?php echo e(request('search')); ?>">
                <button class="btn btn-outline-secondary" type="submit">
                    <i class="bi bi-search"></i>
                </button>
            </div>
        </form>
    </div>
    <div class="col-md-6 text-end">
        <a href="<?php echo e(route('tickets.create')); ?>" class="btn btn-primary">
            <i class="bi bi-plus-circle me-2"></i>Nuevo Ticket
        </a>
    </div>
</div>

<!-- Filters -->
<div class="card mb-3">
    <div class="card-body">
        <form method="GET" action="<?php echo e(route('tickets.index')); ?>" id="filterForm">
            <div class="row g-3">
                <div class="col-md-3">
                    <label class="form-label">
                        Estado
                        <i class="bi bi-info-circle help-icon" 
                           data-bs-toggle="tooltip" 
                           data-bs-placement="top" 
                           title="Filtra tickets por su estado actual: Abierto (nuevo), En Progreso (trabajando), Resuelto (solucionado) o Cerrado (finalizado)"></i>
                    </label>
                    <select name="status" class="form-select" onchange="document.getElementById('filterForm').submit()">
                        <option value="">Todos</option>
                        <option value="abierto" <?php echo e(request('status') == 'abierto' ? 'selected' : ''); ?>>Abierto</option>
                        <option value="en_progreso" <?php echo e(request('status') == 'en_progreso' ? 'selected' : ''); ?>>En Progreso</option>
                        <option value="resuelto" <?php echo e(request('status') == 'resuelto' ? 'selected' : ''); ?>>Resuelto</option>
                        <option value="cerrado" <?php echo e(request('status') == 'cerrado' ? 'selected' : ''); ?>>Cerrado</option>
                    </select>
                </div>
                <div class="col-md-3">
                    <label class="form-label">
                        Prioridad
                        <i class="bi bi-info-circle help-icon" 
                           data-bs-toggle="tooltip" 
                           data-bs-placement="top" 
                           title="Nivel de urgencia: Baja (puede esperar), Media (normal), Alta (pronto) o Crítica (inmediato)"></i>
                    </label>
                    <select name="priority" class="form-select" onchange="document.getElementById('filterForm').submit()">
                        <option value="">Todas</option>
                        <option value="baja" <?php echo e(request('priority') == 'baja' ? 'selected' : ''); ?>>Baja</option>
                        <option value="media" <?php echo e(request('priority') == 'media' ? 'selected' : ''); ?>>Media</option>
                        <option value="alta" <?php echo e(request('priority') == 'alta' ? 'selected' : ''); ?>>Alta</option>
                        <option value="critica" <?php echo e(request('priority') == 'critica' ? 'selected' : ''); ?>>Crítica</option>
                    </select>
                </div>
                <div class="col-md-3">
                    <label class="form-label">
                        Proyecto
                        <i class="bi bi-info-circle help-icon" 
                           data-bs-toggle="tooltip" 
                           data-bs-placement="top" 
                           title="Filtra tickets asociados a un proyecto específico"></i>
                    </label>
                    <select name="project_id" class="form-select" onchange="document.getElementById('filterForm').submit()">
                        <option value="">Todos</option>
                        <?php $__currentLoopData = $projects; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $project): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <option value="<?php echo e($project->id); ?>" <?php echo e(request('project_id') == $project->id ? 'selected' : ''); ?>>
                            <?php echo e($project->name); ?>

                        </option>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </select>
                </div>
                <div class="col-md-3">
                    <label class="form-label">&nbsp;</label>
                    <div>
                        <?php if(request()->hasAny(['status', 'priority', 'project_id', 'search'])): ?>
                        <a href="<?php echo e(route('tickets.index')); ?>" class="btn btn-outline-secondary w-100">
                            <i class="bi bi-x-circle me-2"></i>Limpiar Filtros
                        </a>
                        <?php endif; ?>
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>

<!-- Tickets Table -->
<div class="card">
    <div class="card-body">
        <!-- Mobile Card View -->
        <?php $__currentLoopData = $tickets; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $ticket): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
        <div class="ticket-card-mobile priority-<?php echo e($ticket->priority); ?>">
            <div class="ticket-card-header">
                <div class="ticket-card-number">
                    <?php echo e($ticket->ticket_number); ?>

                    <?php if(isset($ticket->unreadCount) && $ticket->unreadCount > 0): ?>
                        <span class="badge bg-danger ms-1" style="font-size: 0.7rem;">
                            <i class="bi bi-chat-fill"></i> <?php echo e($ticket->unreadCount); ?>

                        </span>
                    <?php endif; ?>
                </div>
                <div class="ticket-card-badges">
                    <span class="badge badge-priority-<?php echo e($ticket->priority); ?>">
                        <?php echo e(ucfirst($ticket->priority)); ?>

                    </span>
                    <span class="badge badge-status-<?php echo e($ticket->status); ?>">
                        <?php echo e(ucfirst(str_replace('_', ' ', $ticket->status))); ?>

                    </span>
                </div>
            </div>
            
            <div class="ticket-card-title">
                <a href="<?php echo e(route('tickets.show', $ticket)); ?>" class="text-decoration-none text-dark">
                    <?php echo e($ticket->title); ?>

                </a>
            </div>
            
            <div class="ticket-card-meta">
                <?php if($ticket->project): ?>
                <div class="ticket-card-meta-item">
                    <i class="bi bi-folder"></i>
                    <span><?php echo e($ticket->project->name); ?></span>
                </div>
                <?php endif; ?>
                
                <div class="ticket-card-meta-item">
                    <i class="bi bi-person"></i>
                    <span><?php echo e($ticket->requester->name); ?></span>
                </div>
                
                <?php if($ticket->assignedUser): ?>
                <div class="ticket-card-meta-item">
                    <i class="bi bi-person-check"></i>
                    <span>Asignado a: <?php echo e($ticket->assignedUser->name); ?></span>
                </div>
                <?php endif; ?>
                
                <div class="ticket-card-meta-item">
                    <i class="bi bi-calendar"></i>
                    <span><?php echo e($ticket->created_at->format('d/m/Y H:i')); ?></span>
                </div>
            </div>
            
            <div class="ticket-card-footer">
                <div>
                    <?php if($ticket->isOverdue()): ?>
                    <span class="badge bg-danger">
                        <i class="bi bi-exclamation-triangle"></i> Vencido
                    </span>
                    <?php endif; ?>
                </div>
                <div class="btn-group btn-group-sm">
                    <a href="<?php echo e(route('tickets.show', $ticket)); ?>" class="btn btn-outline-primary btn-sm">
                        <i class="bi bi-eye"></i> Ver
                    </a>
                </div>
            </div>
        </div>
        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
        
        <!-- Desktop Table View -->
        <div class="table-responsive">
            <table class="table table-hover align-middle">
                <thead>
                    <tr>
                        <th style="width: 100px;">ID</th>
                        <th>Título</th>
                        <th>Proyecto</th>
                        <th>Solicitante</th>
                        <th>Asignado a</th>
                        <th>Prioridad</th>
                        <th>Estado</th>
                        <?php if(in_array(auth()->user()->role, ['responsable', 'ingeniero', 'supervisor', 'administrador'])): ?>
                        <th style="width: 100px;">Tiempo</th>
                        <?php endif; ?>
                        <th style="width: 120px;">Fecha</th>
                        <th style="width: 100px;">Acciones</th>
                    </tr>
                </thead>
                <tbody>
                    <?php $__empty_1 = true; $__currentLoopData = $tickets; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $ticket): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                    <tr>
                        <td>
                            <strong><?php echo e($ticket->ticket_number); ?></strong>
                            <?php if(isset($ticket->unreadCount) && $ticket->unreadCount > 0): ?>
                                <span class="badge bg-danger ms-1" title="Comentarios nuevos">
                                    <i class="bi bi-chat-fill"></i> <?php echo e($ticket->unreadCount); ?>

                                </span>
                            <?php endif; ?>
                        </td>
                        <td>
                            <a href="<?php echo e(route('tickets.show', $ticket)); ?>" class="text-decoration-none">
                                <?php echo e(Str::limit($ticket->title, 50)); ?>

                            </a>
                            <?php if($ticket->isOverdue()): ?>
                            <i class="bi bi-exclamation-triangle-fill text-danger ms-1" title="Vencido"></i>
                            <?php endif; ?>
                        </td>
                        <td>
                            <?php if($ticket->project): ?>
                            <span class="badge bg-secondary"><?php echo e($ticket->project->name); ?></span>
                            <?php else: ?>
                            <span class="text-muted">-</span>
                            <?php endif; ?>
                        </td>
                        <td><?php echo e($ticket->requester->name); ?></td>
                        <td>
                            <?php if($ticket->assignedUser): ?>
                            <?php echo e($ticket->assignedUser->name); ?>

                            <?php else: ?>
                            <span class="text-muted">Sin asignar</span>
                            <?php endif; ?>
                        </td>
                        <td>
                            <span class="badge badge-priority-<?php echo e($ticket->priority); ?>"
                                  data-bs-toggle="tooltip"
                                  data-bs-placement="top"
                                  title="<?php if($ticket->priority == 'critica'): ?>Atención urgente requerida - Impacto crítico en operaciones <?php elseif($ticket->priority == 'alta'): ?>Alta prioridad - Requiere atención pronta <?php elseif($ticket->priority == 'media'): ?>Prioridad normal - Atención en orden de llegada <?php else: ?> Prioridad baja - Puede procesarse después <?php endif; ?>">
                                <?php echo e(ucfirst($ticket->priority)); ?>

                            </span>
                        </td>
                        <td>
                            <span class="badge badge-status-<?php echo e($ticket->status); ?>"
                                  data-bs-toggle="tooltip"
                                  data-bs-placement="top"
                                  title="<?php if($ticket->status == 'abierto'): ?>Ticket nuevo - Pendiente de asignación <?php elseif($ticket->status == 'en_progreso'): ?>En proceso - Asignado y trabajando <?php elseif($ticket->status == 'resuelto'): ?>Resuelto - Esperando confirmación del solicitante <?php else: ?> Cerrado - Ticket finalizado <?php endif; ?>">
                                <?php echo e(ucfirst(str_replace('_', ' ', $ticket->status))); ?>

                            </span>
                        </td>
                        <?php if(in_array(auth()->user()->role, ['responsable', 'ingeniero', 'supervisor', 'administrador'])): ?>
                        <td>
                            <?php
                                $totalTime = $ticket->getTotalWorkTime();
                            ?>
                            <?php if($totalTime > 0): ?>
                                <span class="badge bg-info" title="Tiempo total invertido">
                                    <i class="bi bi-clock"></i> <?php echo e(\App\Models\TicketWorkSession::formatDuration($totalTime)); ?>

                                </span>
                            <?php else: ?>
                                <span class="text-muted">-</span>
                            <?php endif; ?>
                        </td>
                        <?php endif; ?>
                        <td><?php echo e($ticket->created_at->format('d/m/Y')); ?></td>
                        <td>
                            <div class="btn-group btn-group-sm">
                                <a href="<?php echo e(route('tickets.show', $ticket)); ?>" 
                                   class="btn btn-outline-primary" 
                                   data-bs-toggle="tooltip"
                                   data-bs-placement="top"
                                   title="Ver detalles del ticket">
                                    <i class="bi bi-eye"></i>
                                </a>
                                <?php if(auth()->user()->hasRole(['administrador', 'supervisor']) || auth()->id() == $ticket->requester_id): ?>
                                <a href="<?php echo e(route('tickets.edit', $ticket)); ?>" 
                                   class="btn btn-outline-secondary"
                                   data-bs-toggle="tooltip"
                                   data-bs-placement="top"
                                   title="Editar ticket">
                                    <i class="bi bi-pencil"></i>
                                </a>
                                <?php endif; ?>
                            </div>
                        </td>
                    </tr>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                    <tr>
                        <td colspan="10" class="p-0">
                            <?php if (isset($component)) { $__componentOriginal074a021b9d42f490272b5eefda63257c = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginal074a021b9d42f490272b5eefda63257c = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.empty-state','data' => ['icon' => 'ticket','title' => 'No hay tickets para mostrar','description' => 'No se encontraron tickets con los filtros seleccionados. Intenta ajustar los criterios de búsqueda o crea un nuevo ticket.','action' => route('tickets.create'),'actionText' => 'Crear Primer Ticket','actionIcon' => 'plus-circle']] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? (array) $attributes->getIterator() : [])); ?>
<?php $component->withName('empty-state'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag && $constructor = (new ReflectionClass(Illuminate\View\AnonymousComponent::class))->getConstructor()): ?>
<?php $attributes = $attributes->except(collect($constructor->getParameters())->map->getName()->all()); ?>
<?php endif; ?>
<?php $component->withAttributes(['icon' => 'ticket','title' => 'No hay tickets para mostrar','description' => 'No se encontraron tickets con los filtros seleccionados. Intenta ajustar los criterios de búsqueda o crea un nuevo ticket.','action' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute(route('tickets.create')),'actionText' => 'Crear Primer Ticket','actionIcon' => 'plus-circle']); ?>
<?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginal074a021b9d42f490272b5eefda63257c)): ?>
<?php $attributes = $__attributesOriginal074a021b9d42f490272b5eefda63257c; ?>
<?php unset($__attributesOriginal074a021b9d42f490272b5eefda63257c); ?>
<?php endif; ?>
<?php if (isset($__componentOriginal074a021b9d42f490272b5eefda63257c)): ?>
<?php $component = $__componentOriginal074a021b9d42f490272b5eefda63257c; ?>
<?php unset($__componentOriginal074a021b9d42f490272b5eefda63257c); ?>
<?php endif; ?>
                        </td>
                    </tr>
                    <?php endif; ?>
                </tbody>
            </table>
        </div>
        
        <div class="mt-3">
            <?php echo e($tickets->links()); ?>

        </div>
    </div>
</div>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.app', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH C:\xampp_1\htdocs\Ticketera\resources\views/tickets/index.blade.php ENDPATH**/ ?>