@model IEnumerable<foundation_system.Models.Nino>
@{
    ViewData["Title"] = "Gestión de Antecedentes";
}

<div class="d-flex justify-content-between align-items-center mb-4">
    <div>
        <h2 class="mb-1">Antecedentes</h2>
        <p class="text-muted small mb-0">Seleccione un niño para gestionar su historial de antecedentes y conducta.</p>
    </div>
</div>

<div class="card-custom mb-4">
    <form asp-action="Index" method="get" class="row g-3 align-items-center">
        <div class="col-md-10">
            <div class="input-group">
                <span class="input-group-text bg-white border-end-0">
                    <i class="bi bi-search text-muted"></i>
                </span>
                <input type="text" name="search" class="form-control border-start-0 ps-0" 
                       placeholder="Buscar por código o nombre..." value="@ViewBag.Search" />
            </div>
        </div>
        <div class="col-md-2 d-grid">
            <button type="submit" class="btn btn-primary">Buscar</button>
        </div>
    </form>
</div>

<div class="card-custom">
    <div class="table-responsive">
        <table class="table-custom">
            <thead>
                <tr>
                    <th>Código</th>
                    <th>Nombre Completo</th>
                    <th>Grado/Nivel</th>
                    <th>Estado</th>
                    <th>Acciones</th>
                </tr>
            </thead>
            <tbody>
                @if (!Model.Any())
                {
                    <tr>
                        <td colspan="5" class="text-center py-4 text-muted">No se encontraron niños.</td>
                    </tr>
                }
                @foreach (var item in Model)
                {
                    <tr>
                        <td class="fw-bold">@item.CodigoInscripcion</td>
                        <td>@item.Persona.NombreCompleto</td>
                        <td>@item.NivelGrado</td>
                        <td>
                            <span class="badge @(item.Estado == "ACTIVO" ? "bg-success" : "bg-secondary")">
                                @item.Estado
                            </span>
                        </td>
                        <td>
                            <a asp-action="Manage" asp-route-id="@item.Id" class="btn btn-sm btn-primary" title="Gestionar Antecedentes">
                                <i class="bi bi-journal-text me-1"></i> Gestionar
                            </a>
                        </td>
                    </tr>
                }
            </tbody>
        </table>
    </div>

    @if (ViewBag.TotalPages > 1)
    {
        <div class="d-flex justify-content-between align-items-center mt-4">
            <div class="text-muted small">
                Mostrando página @ViewBag.CurrentPage de @ViewBag.TotalPages
            </div>
            <nav aria-label="Page navigation">
                <ul class="pagination pagination-sm mb-0">
                    @for (int i = 1; i <= ViewBag.TotalPages; i++)
                    {
                        <li class="page-item @(i == ViewBag.CurrentPage ? "active" : "")">
                            <a class="page-link" asp-action="Index" asp-route-page="@i" asp-route-search="@ViewBag.Search">@i</a>
                        </li>
                    }
                </ul>
            </nav>
        </div>
    }
</div>
