import{c as N,r as i,u as C,f as j,j as t}from"./index-DiwDH9aE.js";import{A as k,D}from"./Alert-Cq7mXBD-.js";import{C as S}from"./Can-w-eLoK-Q.js";import{b as y,E as h}from"./endpoints-BUXROgJ9.js";import{a as E}from"./multiUserApiClient-CKPzIhIr.js";import{E as _}from"./eye-Dp7PbQrC.js";import"./search-h1vL1q1e.js";import"./x-D4vgwdOf.js";import"./triangle-alert-BxjRBxgM.js";import"./circle-check-big-CvbUXdGb.js";/**
 * @license lucide-react v0.544.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const v=[["path",{d:"m12 19-7-7 7-7",key:"1l729n"}],["path",{d:"M19 12H5",key:"x3x0zl"}]],I=N("arrow-left",v);class L{async getEnrollments(n,d={}){const o=y(h.ADMIN.CYCLES.ENROLLMENTS.INDEX,{cycle_id:n});return E.get(o,{params:d})}async getEnrollmentDetail(n,d,o={}){const m=y(h.ADMIN.CYCLES.ENROLLMENTS.SHOW,{cycle_id:n,id:d});return E.get(m,{params:o})}}const w=new L,P=()=>{const[p,n]=i.useState(null),[d,o]=i.useState(null),[m,s]=i.useState(null),[b,u]=i.useState(!1),g=i.useCallback(async(a,r={})=>{u(!0),s(null);try{const l=await w.getEnrollments(a,r);return l.success?(n(l),l):(s(l.message||"Error al cargar matrículas"),l)}catch(l){throw s(l.message||"Error de conexión"),l}finally{u(!1)}},[]),x=i.useCallback(async(a,r,l={})=>{u(!0),s(null);try{const c=await w.getEnrollmentDetail(a,r,l);return c.success?(o(c),c):(s(c.message||"Error al cargar detalle"),c)}catch(c){throw s(c.message||"Error de conexión"),c}finally{u(!1)}},[]),f=i.useCallback(()=>{s(null)},[]),e=i.useCallback(()=>{n(null),o(null),u(!1),s(null)},[]);return{data:p,item:d,loading:b,error:m,fetchEnrollments:g,fetchEnrollment:x,clearError:f,reset:e}},H=()=>{const p=C(),{cycleId:n}=j(),{data:d,loading:o,error:m,fetchEnrollments:s}=P(),b={sort_by:"id",order:"desc",per_page:25,include:"student,career,cycle"},u=[{key:"id",label:"ID",sortable:!0,wrap:!1,width:"w-16"},{key:"student_name",label:"Estudiante",sortable:!1,wrap:!1,render:(e,a)=>{const r=a.student;return r?`${r.first_name} ${r.last_name}`:"-"}},{key:"student_dni",label:"DNI",sortable:!1,wrap:!1,render:(e,a)=>a.student?.document_number||"-"},{key:"career",label:"Carrera",sortable:!1,wrap:!1,render:(e,a)=>a.career?.name||"-"},{key:"status",label:"Estado",sortable:!0,wrap:!1,render:e=>{const r={pending:{bg:"bg-yellow-100",text:"text-yellow-800",label:"Pendiente"},approved:{bg:"bg-green-100",text:"text-green-800",label:"Aprobado"},rejected:{bg:"bg-red-100",text:"text-red-800",label:"Rechazado"},closed:{bg:"bg-blue-100",text:"text-blue-800",label:"Cerrado"}}[e]||{bg:"bg-gray-100",text:"text-gray-800",label:e};return t.jsx("span",{className:`px-2 py-1 text-xs font-medium rounded-full ${r.bg} ${r.text}`,children:r.label})}},{key:"payment_type",label:"Tipo Pago",sortable:!0,wrap:!1,render:e=>e?{full:"Completo",installment:"Cuotas"}[e]||e:"-"},{key:"total_amount",label:"Monto Total",sortable:!0,wrap:!1,render:e=>e?`S/ ${parseFloat(e).toFixed(2)}`:"-"},{key:"total_amount_pending",label:"Pendiente",sortable:!1,wrap:!1,render:e=>{const a=parseFloat(e)||0,r=a>0?"text-red-600":"text-green-600";return t.jsxs("span",{className:`font-medium ${r}`,children:["S/ ",a.toFixed(2)]})}}],g=e=>{p(`/admin/cycles/${n}/enrollments/${e.id}`)},x=()=>{p("/admin/cycles")},f=e=>t.jsx(S,{permission:"enrollments.show",children:t.jsx("button",{onClick:()=>g(e),className:"p-2 text-blue-600 hover:bg-blue-50 rounded-lg transition-colors cursor-pointer",title:"Ver Detalle",children:t.jsx(_,{className:"w-4 h-4"})})});return t.jsxs("div",{children:[t.jsx("div",{className:"flex items-center justify-between mb-6",children:t.jsxs("div",{className:"flex items-center gap-4",children:[t.jsx("button",{onClick:x,className:"p-2 text-gray-600 hover:bg-gray-100 rounded-lg transition-colors",title:"Volver a Ciclos",children:t.jsx(I,{className:"w-5 h-5"})}),t.jsxs("div",{children:[t.jsx("h1",{className:"text-2xl font-bold text-gray-800",children:"Matrículas del Ciclo"}),t.jsx("p",{className:"text-gray-600 mt-1",children:"Administra las matrículas del ciclo seleccionado"})]})]})}),m&&t.jsx(k,{variant:"warning",message:m,autoClose:5e3}),t.jsx(D,{columns:u,data:d,onFetchData:e=>s(n,e),initialParams:b,renderActions:f,loading:o,searchable:!0,autoSearch:!0,sortable:!0,searchPlaceholder:"Buscar por nombre, DNI...",emptyMessage:"No hay matrículas registradas en este ciclo",perPageOptions:[10,25,50,100]})]})};export{H as default};
