@model IEnumerable<foundation_system.Models.Colaborador>

@{
    Layout = null;
    var selectedDate = (DateOnly)ViewBag.SelectedDate;
    var asistencias = (Dictionary<long, foundation_system.Models.AsistenciaColaborador>)ViewBag.Asistencias;
}

<!DOCTYPE html>
<html lang="es">
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Asistencia - @selectedDate.ToString("dd/MM/yyyy")</title>
    <link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
    <style>
        body { font-family: 'Inter', sans-serif; padding: 20px; background: white; }
        .report-header { border-bottom: 2px solid #333; margin-bottom: 20px; padding-bottom: 10px; }
        .table th { background-color: #f8f9fa !important; }
        @@media print {
            .no-print { display: none !important; }
            body { padding: 0; }
            .table th { background-color: #f8f9fa !important; -webkit-print-color-adjust: exact; }
        }
        .status-PRESENTE { color: #198754; font-weight: bold; }
        .status-AUSENTE { color: #dc3545; font-weight: bold; }
        .status-TARDANZA { color: #fd7e14; font-weight: bold; }
        .status-JUSTIFICADO { color: #0dcaf0; font-weight: bold; }
    </style>
</head>
<body>
    <div class="container-fluid">
        <div class="d-flex justify-content-between align-items-center no-print mb-4">
            <a href="javascript:window.history.back()" class="btn btn-secondary"><i class="bi bi-arrow-left"></i> Volver</a>
            <button onclick="window.print()" class="btn btn-primary"><i class="bi bi-printer"></i> Imprimir Reporte</button>
        </div>

        <div class="report-header text-center">
            <h2>Misión Esperanza (MIES)</h2>
            <h4>Control de Asistencia de Colaboradores</h4>
            <p class="mb-0"><strong>Fecha:</strong> @selectedDate.ToString("dddd, dd de MMMM de yyyy")</p>
        </div>

        <table class="table table-bordered table-striped align-middle">
            <thead>
                <tr>
                    <th style="width: 50px;">#</th>
                    <th>Colaborador</th>
                    <th>Cargo</th>
                    <th class="text-center">Estado</th>
                    <th>Observaciones</th>
                </tr>
            </thead>
            <tbody>
                @{ int i = 1; }
                @foreach (var item in Model)
                {
                    var asistencia = asistencias.ContainsKey(item.Id) ? asistencias[item.Id] : null;
                    <tr>
                        <td>@i++</td>
                        <td>
                            <strong>@item.Persona.Apellidos, @item.Persona.Nombres</strong>
                        </td>
                        <td>@(item.Cargo?.Nombre ?? "Sin Cargo")</td>
                        <td class="text-center">
                            @if (asistencia != null)
                            {
                                <span class="status-@asistencia.Estado">@asistencia.Estado</span>
                            }
                            else
                            {
                                <span class="text-muted">SIN REGISTRO</span>
                            }
                        </td>
                        <td>@(asistencia?.Observaciones ?? "-")</td>
                    </tr>
                }
            </tbody>
        </table>

        <div class="mt-5 row">
            <div class="col-6 text-center">
                <div style="border-top: 1px solid #000; width: 200px; margin: 50px auto 0;"></div>
                <p>Firma Responsable</p>
            </div>
            <div class="col-6 text-center">
                <div style="border-top: 1px solid #000; width: 200px; margin: 50px auto 0;"></div>
                <p>Sello Institucional</p>
            </div>
        </div>
        
        <div class="mt-4 text-end small text-muted">
            Generado el @DateTime.Now.ToString("dd/MM/yyyy HH:mm")
        </div>
    </div>
</body>
</html>
