<div class="section-title">{{ __('Incidencias (Issues)') }}</div>

@if(empty($issues))
    <div class="text-center text-gray-400 py-8">
        <p>{{ __('No hay incidencias en el rango seleccionado.') }}</p>
    </div>
@else
    <div class="overflow-x-auto">
        <table>
            <thead>
                <tr>
                    <th>ID</th>
                    <th>Título</th>
                    <th>Elemento</th>
                    <th>Fase</th>
                    <th>Prioridad</th>
                    <th>Estado</th>
                    <th>Reportado por</th>
                    <th>Asignado a</th>
                    <th>Creado</th>
                    <th>Cerrado</th>
                    <th>Días abierto</th>
                    <th>Tareas</th>
                </tr>
            </thead>
            <tbody>
                @foreach($issues as $issue)
                    @php
                        $priorityColor = match($issue['priority']) {
                            'critical' => 'text-red-600',
                            'high' => 'text-orange-600',
                            'medium' => 'text-amber-600',
                            'low' => 'text-gray-600',
                            default => 'text-gray-600',
                        };
                        $statusColor = match($issue['status']) {
                            'open' => 'badge-error',
                            'in_review' => 'badge-warning',
                            'closed' => 'badge-success',
                            default => 'badge-ghost',
                        };
                    @endphp
                <tr>
                    <td>{{ $issue['id'] }}</td>
                    <td class="font-medium max-w-xs truncate">{{ $issue['title'] }}</td>
                    <td>{{ $issue['feature'] }}</td>
                    <td>{{ $issue['phase'] }}</td>
                    <td>
                        <span class="badge {{ match($issue['priority']) {
                            'critical' => 'badge-error',
                            'high' => 'badge-warning',
                            'medium' => 'badge-info',
                            'low' => 'badge-ghost',
                            default => 'badge-ghost',
                        } }}">
                            {{ $issue['priority_label'] }}
                        </span>
                    </td>
                    <td>
                        <span class="badge {{ $statusColor }}">
                            {{ $issue['status_label'] }}
                        </span>
                    </td>
                    <td>{{ $issue['reporter'] }}</td>
                    <td>{{ $issue['assignee'] }}</td>
                    <td>{{ $issue['created_at'] }}</td>
                    <td>{{ $issue['closed_at'] ?? '—' }}</td>
                    <td>{{ $issue['days_open'] }}</td>
                    <td>{{ $issue['tasks_completed'] }} / {{ $issue['tasks_total'] }}</td>
                </tr>
                @endforeach
            </tbody>
        </table>
    </div>
@endif