import{c as te,r as m,j as e,t as D,u as fe}from"./index-DiwDH9aE.js";import{A as Ne,D as _e}from"./Alert-Cq7mXBD-.js";import{S as le,P as Se,M as ee}from"./Modal-tocKJOcW.js";import{F as Ee}from"./FullScreenModal-DHvf5XmH.js";import{C as H}from"./Can-w-eLoK-Q.js";import{T as ne}from"./Toggle-BNZnRjy7.js";import{B}from"./Button-Cu8l7rID.js";import{B as we,S as De}from"./BaseService-B6zq4ARl.js";import{E as q,b as Y}from"./endpoints-BUXROgJ9.js";import{a as Q}from"./multiUserApiClient-CKPzIhIr.js";import{C as G}from"./circle-check-big-CvbUXdGb.js";import{C as se}from"./circle-alert-B4Iu_AWZ.js";import{T as Ce,a as ae}from"./triangle-alert-BxjRBxgM.js";import{U as X}from"./user-Dm-qAtiL.js";import{u as oe,a as ie,C as $,h as ce}from"./handleFormErrors-CaWHVJ6Q.js";import{o as de,b as re,e as F,f as me,n as A,s as E,c as K,E as c,I as N}from"./schemas-BwNPnT22.js";import{S as R}from"./SearchableSelect-DESVOSo4.js";import{u as ue}from"./useShared-C-dQZUur.js";import{P as xe}from"./phone-DYXWN0h8.js";import{M as he}from"./map-pin-C8p0ntE-.js";import{S as ge}from"./school-CCnutwvi.js";import{X as pe}from"./x-D4vgwdOf.js";import{S as Ie}from"./settings-L85C4ab2.js";import"./search-h1vL1q1e.js";import"./chevron-down-4ep2ftiY.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 Oe=[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]],J=te("shield-check",Oe);/**
 * @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 Te=[["circle",{cx:"9",cy:"12",r:"3",key:"u3jwor"}],["rect",{width:"20",height:"14",x:"2",y:"5",rx:"7",key:"g7kal2"}]],Ae=te("toggle-left",Te);class ke extends we{constructor(){super(q.ADMIN.STUDENTS.BASE)}async toggleStatus(h){try{if(!h)throw new Error("ID es requerido para toggleStatus()");const d=Y(q.ADMIN.STUDENTS.TOGGLE_STATUS,{id:h});return await Q.patch(d)}catch(d){throw console.error("[PermissionsService] Error en toggleStatus:",d),d}}async toggleValidation(h){try{if(!h)throw new Error("ID es requerido para toggleValidation()");const d=Y(q.ADMIN.STUDENTS.TOGGLE_VALIDATION,{id:h});return await Q.patch(d)}catch(d){throw console.error("[PermissionsService] Error en toggleValidation:",d),d}}async resetPassword(h){try{if(!h)throw new Error("ID es requerido para resetPassword()");const d=Y(q.ADMIN.STUDENTS.RESET_PASSWORD,{id:h});return await Q.patch(d)}catch(d){throw console.error("[PermissionsService] Error en resetPassword:",d),d}}}const T=new ke,V=()=>{const[u,h]=m.useState(null),[d,r]=m.useState(!1),[l,n]=m.useState(null),_="el estudiante",v="los estudiantes";return{data:u,loading:d,error:l,fetchStudents:async(b={})=>{r(!0),n(null);try{const s=await T.getAll(b);return s.success?(h(s),s):(n(s.message),s)}catch(s){throw n(s.message||`Error al cargar ${v}`),console.error("Error en fetch:",s),s}finally{r(!1)}},getStudent:async(b,s={})=>{r(!0),n(null);try{const p=await T.getById(b,s);return p.success?p.data:(n(p.message),null)}catch(p){throw n(p.message||`Error al cargar ${_}`),console.error("Error en get:",p),p}finally{r(!1)}},createStudent:async b=>{r(!0),n(null);try{const s=await T.create(b);return console.log(s),s.success||n(s.message),s}catch(s){throw n(s.message||`Error al crear ${_}`),console.error("Error en create:",s),s}finally{r(!1)}},updateStudent:async(b,s)=>{r(!0),n(null);try{const p=await T.update(b,s);return p.success||n(p.message),p}catch(p){throw n(p.message||`Error al actualizar ${_}`),console.error("Error en update:",p),p}finally{r(!1)}},deleteStudent:async b=>{r(!0),n(null);try{const s=await T.delete(b);return s.success||n(s.message),s}catch(s){throw n(s.message||`Error al eliminar ${_}`),console.error("Error en delete:",s),s}finally{r(!1)}},toggleStatus:async b=>{try{r(!0);const s=await T.toggleStatus(b);return s.success||n(s.message||"Error al cambiar estado"),s}catch(s){throw n(s.message||"Error al cambiar estado"),console.error("Error en toggleStatus:",s),s}finally{r(!1)}},toggleValidation:async b=>{try{r(!0);const s=await T.toggleValidation(b);return s.success||n(s.message||"Error al cambiar estado"),s}catch(s){throw n(s.message||"Error al cambiar estado"),console.error("Error en toggleStatus:",s),s}finally{r(!1)}},resetPassword:async b=>{try{r(!0);const s=await T.resetPassword(b);return s.success||n(s.message||"Error al cambiar estado"),s}catch(s){throw n(s.message||"Error al cambiar estado"),console.error("Error en toggleStatus:",s),s}finally{r(!1)}},clearError:()=>{n(null)},reset:()=>{h(null),r(!1),n(null)}}},Me=({student:u,onStudentUpdate:h})=>{const{toggleStatus:d,loading:r}=V(),[l,n]=m.useState(u.active),_=async v=>{try{const g=await d(u.id);g?.success?(n(v),D.success(g.message||"Estado actualizado correctamente"),g.data&&h?.(g.data)):(n(!v),D.error(g?.message||"Error al cambiar estado"))}catch(g){n(!v),console.error("Error en toggleStatus:",g),D.error("Error inesperado al cambiar estado")}};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold text-gray-900 mb-2",children:"Cambiar Estado del Estudiante"}),e.jsx("p",{className:"text-sm text-gray-600",children:"Controla si el estudiante puede acceder al sistema y realizar acciones."})]}),e.jsx("div",{className:`border-2 rounded-lg p-4 ${l?"border-green-200 bg-green-50":"border-red-200 bg-red-50"}`,children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[l?e.jsx(G,{className:"w-6 h-6 text-green-600"}):e.jsx(se,{className:"w-6 h-6 text-red-600"}),e.jsxs("div",{children:[e.jsxs("p",{className:"font-semibold text-gray-900",children:["Estado actual: ",l?"Activo":"Inactivo"]}),e.jsx("p",{className:"text-sm text-gray-600 mt-1",children:l?"El estudiante puede iniciar sesión y acceder al sistema":"El estudiante no puede iniciar sesión ni realizar acciones"})]})]}),e.jsx(ne,{checked:l,onChange:_,disabled:r,loading:r,size:"lg",colorActive:"bg-green-600",colorInactive:"bg-red-600"})]})}),e.jsx("div",{className:"bg-blue-50 border border-blue-200 rounded-lg p-4",children:e.jsxs("div",{className:"flex gap-3",children:[e.jsx(se,{className:"w-5 h-5 text-blue-600 flex-shrink-0 mt-0.5"}),e.jsxs("div",{className:"text-sm text-blue-900",children:[e.jsx("p",{className:"font-semibold mb-1",children:"Nota importante:"}),e.jsxs("ul",{className:"list-disc list-inside space-y-1 text-blue-800",children:[e.jsx("li",{children:"Al desactivar, el estudiante será desconectado inmediatamente"}),e.jsx("li",{children:"No podrá realizar inscripciones ni pagos mientras esté inactivo"}),e.jsx("li",{children:"Sus datos se mantendrán seguros en el sistema"})]})]})]})})]})},Pe=({student:u,onStudentUpdate:h})=>{const{toggleValidation:d,loading:r}=V(),[l,n]=m.useState(u.validated_information),_=async v=>{try{const g=await d(u.id);g?.success?(n(v),D.success(g.message||"Validación actualizada correctamente"),g.data&&h?.(g.data)):(n(!v),D.error(g?.message||"Error al cambiar validación"))}catch(g){n(!v),console.error("Error en toggleValidation:",g),D.error("Error inesperado al cambiar validación")}};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold text-gray-900 mb-2",children:"Validar Información del Estudiante"}),e.jsx("p",{className:"text-sm text-gray-600",children:"Confirma que los datos personales del estudiante son correctos y verificados."})]}),e.jsx("div",{className:`border-2 rounded-lg p-4 ${l?"border-blue-200 bg-blue-50":"border-yellow-200 bg-yellow-50"}`,children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[l?e.jsx(J,{className:"w-6 h-6 text-blue-600"}):e.jsx(Ce,{className:"w-6 h-6 text-yellow-600"}),e.jsxs("div",{children:[e.jsxs("p",{className:"font-semibold text-gray-900",children:["Estado de validación: ",l?"Validado":"No validado"]}),e.jsx("p",{className:"text-sm text-gray-600 mt-1",children:l?"La información personal ha sido verificada y aprobada":"La información personal requiere revisión y aprobación"})]})]}),e.jsx(ne,{checked:l,onChange:_,disabled:r,loading:r,size:"lg",colorActive:"bg-blue-600",colorInactive:"bg-yellow-600"})]})}),e.jsx("div",{className:"bg-purple-50 border border-purple-200 rounded-lg p-4",children:e.jsxs("div",{className:"flex gap-3",children:[e.jsx(J,{className:"w-5 h-5 text-purple-600 flex-shrink-0 mt-0.5"}),e.jsxs("div",{className:"text-sm text-purple-900",children:[e.jsx("p",{className:"font-semibold mb-1",children:"¿Qué significa validar?"}),e.jsxs("ul",{className:"list-disc list-inside space-y-1 text-purple-800",children:[e.jsx("li",{children:"Se confirma que los datos personales son correctos"}),e.jsx("li",{children:"El estudiante puede continuar con procesos de inscripción"}),e.jsx("li",{children:"Una vez validado, algunos campos quedan bloqueados para edición"}),e.jsx("li",{children:"Solo administradores pueden revertir la validación"})]})]})]})})]})},Le=({student:u,onSuccess:h})=>{const[d,r]=m.useState("status"),[l,n]=m.useState(u);if(!l)return e.jsx("div",{className:"flex items-center justify-center h-64",children:e.jsx("p",{className:"text-gray-500",children:"No se ha seleccionado ningún estudiante"})});const _=S=>{n(S),h?.()},v=[{id:"status",label:"Estado",icon:Ae,component:Me},{id:"validation",label:"Validación",icon:G,component:Pe}],g=v.find(S=>S.id===d)?.component;return e.jsxs("div",{className:"max-w-6xl mx-auto",children:[e.jsx("div",{className:"bg-blue-50 border border-blue-200 rounded-lg p-4 mb-6",children:e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx("div",{className:"flex-shrink-0",children:e.jsx("div",{className:"w-16 h-16 bg-blue-600 rounded-full flex items-center justify-center",children:e.jsx(X,{className:"w-8 h-8 text-white"})})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("h3",{className:"text-lg font-bold text-gray-900",children:[l.names," ",l.paternal_surname," ",l.maternal_surname]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-2 mt-2 text-sm",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-gray-500",children:"Documento:"})," ",e.jsx("span",{className:"font-medium text-gray-900",children:l.document_number})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-gray-500",children:"Email:"})," ",e.jsx("span",{className:"font-medium text-gray-900",children:l.email})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-gray-500",children:"Estado:"}),l.active?e.jsxs("span",{className:"flex items-center gap-1 text-green-700",children:[e.jsx(G,{className:"w-4 h-4"}),"Activo"]}):e.jsxs("span",{className:"flex items-center gap-1 text-red-700",children:[e.jsx(J,{className:"w-4 h-4"}),"Inactivo"]})]})]})]})]})}),e.jsx("div",{className:"border-b border-gray-200 mb-6",children:e.jsx("nav",{className:"flex gap-4",children:v.map(S=>{const x=S.icon;return e.jsxs("button",{onClick:()=>r(S.id),className:`flex items-center gap-2 px-4 py-3 border-b-2 font-medium text-sm transition-colors ${d===S.id?"border-blue-600 text-blue-600":"border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300"}`,children:[e.jsx(x,{className:"w-4 h-4"}),S.label]},S.id)})})}),e.jsx("div",{className:"bg-white rounded-lg border border-gray-200 p-6",children:g&&e.jsx(g,{student:l,onStudentUpdate:_})})]})},be=K(["DNI","CE","PASSPORT"],{errorMap:()=>({message:"Tipo de documento inválido"})}),je=K(["SINGLE","MARRIED","DIVORCED","WIDOWED"],{errorMap:()=>({message:"Estado civil inválido"})}),ve=K(["M","F","OTHER"],{errorMap:()=>({message:"Género inválido"})}),U=E().min(9,"Debe tener 9 dígitos").max(9,"Debe tener 9 dígitos").regex(/^\d{9}$/,"Debe contener solo números"),ye=E().email("Email inválido").max(255,"Email muy largo"),$e=A().int("Debe ser un año válido").min(1900,"Año muy antiguo").max(new Date().getFullYear(),"El año no puede ser futuro"),Re=de({document_type:be,document_number:E().min(8,"Mínimo 8 caracteres").max(20,"Máximo 20 caracteres").regex(/^[a-zA-Z0-9]+$/,"Solo letras y números"),names:E().min(2,"Mínimo 2 caracteres").max(255,"Máximo 255 caracteres").regex(/^[a-zA-ZáéíóúÁÉÍÓÚñÑ\s]+$/,"Solo letras y espacios"),paternal_surname:E().min(2,"Mínimo 2 caracteres").max(255,"Máximo 255 caracteres").regex(/^[a-zA-ZáéíóúÁÉÍÓÚñÑ\s]+$/,"Solo letras y espacios"),maternal_surname:E().min(2,"Mínimo 2 caracteres").max(255,"Máximo 255 caracteres").regex(/^[a-zA-ZáéíóúÁÉÍÓÚñÑ\s]+$/,"Solo letras y espacios"),birth_date:E().refine(u=>new Date(u)<new Date,"La fecha debe ser anterior a hoy"),birth_place_id:A({required_error:"Lugar de nacimiento es requerido"}).int("Debe ser un ID válido").positive("Debe ser un ID válido"),marital_status:je,gender:ve,languages:F(E()).min(1,"Debe seleccionar al menos un idioma"),phone_number:U,whatsapp_number:U,email:ye,residence_address:E().min(5,"Mínimo 5 caracteres").max(255,"Máximo 255 caracteres"),residence_place_id:A({required_error:"Lugar de residencia es requerido"}).int("Debe ser un ID válido").positive("Debe ser un ID válido"),school_graduation_year:$e.optional().nullable(),school_id:A({required_error:"Colegio es requerido"}).int("Debe ser un ID válido").positive("Debe ser un ID válido"),family_data:F(me()).optional().nullable(),active:re().default(!0),validated_information:re().default(!1)}),ze=de({document_type:be,document_number:E().min(8,"Mínimo 8 caracteres").max(20,"Máximo 20 caracteres").regex(/^[a-zA-Z0-9]+$/,"Solo letras y números"),names:E().min(2,"Mínimo 2 caracteres").max(255,"Máximo 255 caracteres").regex(/^[a-zA-ZáéíóúÁÉÍÓÚñÑ\s]+$/,"Solo letras y espacios"),paternal_surname:E().min(2,"Mínimo 2 caracteres").max(255,"Máximo 255 caracteres").regex(/^[a-zA-ZáéíóúÁÉÍÓÚñÑ\s]+$/,"Solo letras y espacios"),maternal_surname:E().min(2,"Mínimo 2 caracteres").max(255,"Máximo 255 caracteres").regex(/^[a-zA-ZáéíóúÁÉÍÓÚñÑ\s]+$/,"Solo letras y espacios"),birth_date:E().refine(u=>new Date(u)<new Date,"La fecha debe ser anterior a hoy"),birth_place_id:A({required_error:"Lugar de nacimiento es requerido"}).int("Debe ser un ID válido").positive("Debe ser un ID válido"),marital_status:je,gender:ve,languages:F(E()).min(1,"Debe seleccionar al menos un idioma"),phone_number:U,whatsapp_number:U,email:ye,residence_address:E().min(5,"Mínimo 5 caracteres").max(255,"Máximo 255 caracteres"),residence_place_id:A({required_error:"Lugar de residencia es requerido"}).int("Debe ser un ID válido").positive("Debe ser un ID válido"),school_graduation_year:A().int("Debe ser un año válido").min(1900,"Año muy antiguo").max(new Date().getFullYear(),"El año no puede ser futuro").optional().nullable(),school_id:A().int("Debe ser un ID válido").positive("Debe ser un ID válido").optional().nullable(),family_data:F(me()).optional().nullable()}),Ge=[{value:"DNI",label:"DNI"},{value:"CE",label:"Carné de Extranjería"},{value:"PASSPORT",label:"Pasaporte"}],Ve=[{value:"SINGLE",label:"Soltero/a"},{value:"MARRIED",label:"Casado/a"},{value:"DIVORCED",label:"Divorciado/a"},{value:"WIDOWED",label:"Viudo/a"}],qe=[{value:"M",label:"Masculino"},{value:"F",label:"Femenino"},{value:"OTHER",label:"Otro"}],Be=[{value:"español",label:"Español"},{value:"quechua",label:"Quechua"},{value:"inglés",label:"Inglés"},{value:"chino",label:"Chino"},{value:"portugués",label:"Portugués"}],Fe=({onSuccess:u,onCancel:h})=>{const{createStudent:d,loading:r}=V(),{fetchDistricts:l,getDistrict:n,fetchSchools:_,getSchool:v}=ue(),[g,S]=m.useState({districts:[],schools:[]}),{register:x,handleSubmit:j,formState:{errors:o},setError:i,control:I,watch:O}=oe({resolver:ie(Re),mode:"onChange",defaultValues:{document_type:"DNI",document_number:"",names:"",paternal_surname:"",maternal_surname:"",birth_date:"",birth_place_id:null,marital_status:"SINGLE",gender:"M",languages:[],phone_number:"",whatsapp_number:"",email:"",residence_address:"",residence_place_id:null,school_graduation_year:null,school_id:null,active:!1,validated_information:!1,family_data:null}}),k=O("languages")||[],C=m.useCallback(async t=>{try{const a=(await l({search:t,include:"province.department.country"})).data||[];return S(y=>({...y,districts:a})),a}catch(f){return console.error("Error buscando distritos:",f),D.error("Error al buscar distritos"),[]}},[l]),b=m.useCallback(async t=>{try{return(await n(t)).data}catch(f){return console.error("Error cargando distrito:",f),null}},[n]),s=m.useCallback(t=>e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"font-medium text-gray-900",children:t.name}),e.jsxs("div",{className:"text-xs text-gray-500",children:[t.province?.name,", ",t.province?.department?.name]})]}),[]),p=m.useCallback(t=>t?[t.name,t.province?.name,t.province?.department?.name].filter(Boolean).join(", "):"",[]),P=m.useCallback(async t=>{try{const a=(await _({search:t,include:"district.province.department.country"})).data||[];return S(y=>({...y,schools:a})),a}catch(f){return console.error("Error buscando colegios:",f),D.error("Error al buscar colegios"),[]}},[_]),L=m.useCallback(async t=>{try{return(await v(t)).data}catch(f){return console.error("Error cargando colegio:",f),null}},[v]),w=m.useCallback(t=>e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"font-medium text-gray-900",children:t.name}),e.jsxs("div",{className:"text-xs text-gray-500",children:["Código: ",t.code," • ",t.level]})]}),[]),M=m.useCallback(t=>t?`${t.name} - ${t.code}`:"",[]),W=async t=>{try{const f=await d(t);f?.success?(D.success(f.message||"Estudiante creado exitosamente"),u?.()):ce(f,i)}catch(f){console.error("Error en onSubmit:",f),D.error("Error inesperado al crear estudiante")}};return e.jsxs("form",{onSubmit:j(W),className:"space-y-6",children:[e.jsxs("section",{children:[e.jsxs("h3",{className:"text-base font-semibold text-gray-900 mb-4 flex items-center gap-2",children:[e.jsx(X,{className:"w-5 h-5 text-blue-600"}),"Información Personal"]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1.5",children:"Tipo de Documento *"}),e.jsx("select",{...x("document_type"),disabled:r,className:"w-full px-3 py-2 text-sm border border-gray-300 rounded-lg",children:Ge.map(t=>e.jsx("option",{value:t.value,children:t.label},t.value))}),e.jsx(c,{message:o.document_type?.message})]}),e.jsxs("div",{children:[e.jsx(N,{label:"Número de Documento *",placeholder:"12345678",error:o.document_number?.message,disabled:r,...x("document_number")}),e.jsx(c,{message:o.document_number?.message})]}),e.jsxs("div",{children:[e.jsx(N,{label:"Nombres *",placeholder:"Juan Carlos",error:o.names?.message,disabled:r,...x("names")}),e.jsx(c,{message:o.names?.message})]}),e.jsxs("div",{children:[e.jsx(N,{label:"Apellido Paterno *",placeholder:"Pérez",error:o.paternal_surname?.message,disabled:r,...x("paternal_surname")}),e.jsx(c,{message:o.paternal_surname?.message})]}),e.jsxs("div",{children:[e.jsx(N,{label:"Apellido Materno *",placeholder:"García",error:o.maternal_surname?.message,disabled:r,...x("maternal_surname")}),e.jsx(c,{message:o.maternal_surname?.message})]}),e.jsxs("div",{children:[e.jsx(N,{type:"date",label:"Fecha de Nacimiento *",error:o.birth_date?.message,disabled:r,...x("birth_date")}),e.jsx(c,{message:o.birth_date?.message})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1.5",children:"Género *"}),e.jsx("select",{...x("gender"),disabled:r,className:"w-full px-3 py-2 text-sm border border-gray-300 rounded-lg",children:qe.map(t=>e.jsx("option",{value:t.value,children:t.label},t.value))}),e.jsx(c,{message:o.gender?.message})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1.5",children:"Estado Civil *"}),e.jsx("select",{...x("marital_status"),disabled:r,className:"w-full px-3 py-2 text-sm border border-gray-300 rounded-lg",children:Ve.map(t=>e.jsx("option",{value:t.value,children:t.label},t.value))}),e.jsx(c,{message:o.marital_status?.message})]})]}),e.jsxs("div",{className:"mt-4",children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1.5",children:"Lugar de Nacimiento *"}),e.jsx($,{name:"birth_place_id",control:I,render:({field:t})=>e.jsx(R,{value:t.value,onChange:t.onChange,onSearch:C,onLoadSelected:b,renderOption:s,getDisplayText:p,placeholder:"Buscar distrito...",error:o.birth_place_id?.message,disabled:r,minSearchLength:3,manualSearch:!0})}),e.jsx(c,{message:o.birth_place_id?.message})]}),e.jsxs("div",{className:"mt-4",children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:["Idiomas * ",k.length>0&&e.jsxs("span",{className:"ml-2 text-xs text-blue-600",children:["(",k.length,")"]})]}),e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 gap-3",children:Be.map(t=>e.jsxs("label",{className:"flex items-center gap-2 p-3 border rounded-lg cursor-pointer hover:bg-blue-50",children:[e.jsx("input",{type:"checkbox",value:t.value,...x("languages"),disabled:r,className:"w-4 h-4 text-blue-600 rounded"}),e.jsx("span",{className:"text-sm",children:t.label})]},t.value))}),e.jsx(c,{message:o.languages?.message})]})]}),e.jsxs("section",{className:"border-t pt-6",children:[e.jsxs("h3",{className:"text-base font-semibold text-gray-900 mb-4 flex items-center gap-2",children:[e.jsx(xe,{className:"w-5 h-5 text-blue-600"}),"Contacto"]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(N,{label:"Teléfono *",placeholder:"999999999",error:o.phone_number?.message,disabled:r,...x("phone_number")}),e.jsx(c,{message:o.phone_number?.message})]}),e.jsxs("div",{children:[e.jsx(N,{label:"WhatsApp *",placeholder:"999999999",error:o.whatsapp_number?.message,disabled:r,...x("whatsapp_number")}),e.jsx(c,{message:o.whatsapp_number?.message})]}),e.jsxs("div",{className:"md:col-span-2",children:[e.jsx(N,{type:"email",label:"Email *",placeholder:"estudiante@example.com",error:o.email?.message,disabled:r,...x("email")}),e.jsx(c,{message:o.email?.message})]})]})]}),e.jsxs("section",{className:"border-t pt-6",children:[e.jsxs("h3",{className:"text-base font-semibold text-gray-900 mb-4 flex items-center gap-2",children:[e.jsx(he,{className:"w-5 h-5 text-blue-600"}),"Residencia"]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx(N,{label:"Dirección *",placeholder:"Av. Principal 123",error:o.residence_address?.message,disabled:r,...x("residence_address")}),e.jsx(c,{message:o.residence_address?.message})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1.5",children:"Distrito *"}),e.jsx($,{name:"residence_place_id",control:I,render:({field:t})=>e.jsx(R,{value:t.value,onChange:t.onChange,onSearch:C,onLoadSelected:b,renderOption:s,getDisplayText:p,placeholder:"Buscar distrito...",error:o.residence_place_id?.message,disabled:r,minSearchLength:3,manualSearch:!0})}),e.jsx(c,{message:o.residence_place_id?.message})]})]})]}),e.jsxs("section",{className:"border-t pt-6",children:[e.jsxs("h3",{className:"text-base font-semibold text-gray-900 mb-4 flex items-center gap-2",children:[e.jsx(ge,{className:"w-5 h-5 text-blue-600"}),"Educación"]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1.5",children:"Colegio *"}),e.jsx($,{name:"school_id",control:I,render:({field:t})=>e.jsx(R,{value:t.value,onChange:t.onChange,onSearch:P,onLoadSelected:L,renderOption:w,getDisplayText:M,placeholder:"Buscar colegio...",error:o.school_id?.message,disabled:r,minSearchLength:3,manualSearch:!0})}),e.jsx(c,{message:o.school_id?.message})]}),e.jsxs("div",{children:[e.jsx(N,{type:"number",label:"Año de Graduación (opcional)",placeholder:"2020",error:o.school_graduation_year?.message,disabled:r,...x("school_graduation_year",{valueAsNumber:!0})}),e.jsx(c,{message:o.school_graduation_year?.message})]})]})]}),e.jsxs("div",{className:"flex items-center justify-end gap-3 pt-4 border-t",children:[e.jsx(B,{type:"button",variant:"ghost",text:"Cancelar",leftIcon:e.jsx(pe,{className:"w-4 h-4"}),onClick:h,disabled:r}),e.jsx(B,{type:"submit",variant:"primary",text:r?"Guardando...":"Crear",leftIcon:!r&&e.jsx(le,{className:"w-4 h-4"}),loading:r,disabled:r})]})]})},Ue=[{value:"DNI",label:"DNI"},{value:"CE",label:"Carné de Extranjería"},{value:"PASSPORT",label:"Pasaporte"}],We=[{value:"SINGLE",label:"Soltero/a"},{value:"MARRIED",label:"Casado/a"},{value:"DIVORCED",label:"Divorciado/a"},{value:"WIDOWED",label:"Viudo/a"}],Ze=[{value:"M",label:"Masculino"},{value:"F",label:"Femenino"},{value:"OTHER",label:"Otro"}],He=[{value:"español",label:"Español"},{value:"quechua",label:"Quechua"},{value:"inglés",label:"Inglés"},{value:"chino",label:"Chino"},{value:"portugués",label:"Portugués"}],Ye=({studentData:u,onSuccess:h,onCancel:d})=>{const{updateStudent:r,loading:l}=V(),{fetchDistricts:n,getDistrict:_,fetchSchools:v,getSchool:g}=ue(),[S,x]=m.useState({districts:[],schools:[]}),{register:j,handleSubmit:o,formState:{errors:i},setError:I,control:O,watch:k,setValue:C}=oe({resolver:ie(ze),mode:"onChange",defaultValues:{document_type:"",document_number:"",names:"",paternal_surname:"",maternal_surname:"",birth_date:"",birth_place_id:null,marital_status:"",gender:"",languages:[],phone_number:"",whatsapp_number:"",email:"",residence_address:"",residence_place_id:null,school_graduation_year:null,school_id:null}}),b=k("languages")||[];m.useEffect(()=>{u&&Object.keys(u).forEach(a=>{a==="birth_date"&&u[a]?C(a,u[a].split("T")[0]):C(a,u[a])})},[u,C]);const s=m.useCallback(async a=>{try{const z=(await n({search:a,include:"province.department.country"})).data||[];return x(Z=>({...Z,districts:z})),z}catch(y){return console.error("Error buscando distritos:",y),D.error("Error al buscar distritos"),[]}},[n]),p=m.useCallback(async a=>{try{return(await _(a)).data}catch(y){return console.error("Error cargando distrito:",y),null}},[_]),P=m.useCallback(a=>e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"font-medium text-gray-900",children:a.name}),e.jsxs("div",{className:"text-xs text-gray-500",children:[a.province?.name,", ",a.province?.department?.name]})]}),[]),L=m.useCallback(a=>a?[a.name,a.province?.name,a.province?.department?.name].filter(Boolean).join(", "):"",[]),w=m.useCallback(async a=>{try{const z=(await v({search:a,include:"district.province.department.country"})).data||[];return x(Z=>({...Z,schools:z})),z}catch(y){return console.error("Error buscando colegios:",y),D.error("Error al buscar colegios"),[]}},[v]),M=m.useCallback(async a=>{try{return(await g(a)).data}catch(y){return console.error("Error cargando colegio:",y),null}},[g]),W=m.useCallback(a=>e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"font-medium text-gray-900",children:a.name}),e.jsxs("div",{className:"text-xs text-gray-500",children:["Código: ",a.code," • ",a.level]})]}),[]),t=m.useCallback(a=>a?`${a.name} - ${a.code}`:"",[]),f=async a=>{try{const y=await r(u.id,a);y?.success?(D.success(y.message||"Estudiante actualizado exitosamente"),h?.()):ce(y,I)}catch(y){console.error("Error en onSubmit:",y),D.error("Error inesperado al actualizar estudiante")}};return e.jsxs("form",{onSubmit:o(f),className:"space-y-6",children:[e.jsxs("section",{children:[e.jsxs("h3",{className:"text-base font-semibold text-gray-900 mb-4 flex items-center gap-2",children:[e.jsx(X,{className:"w-5 h-5 text-blue-600"}),"Información Personal"]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1.5",children:"Tipo de Documento *"}),e.jsx("select",{...j("document_type"),disabled:l,className:"w-full px-3 py-2 text-sm border border-gray-300 rounded-lg",children:Ue.map(a=>e.jsx("option",{value:a.value,children:a.label},a.value))}),e.jsx(c,{message:i.document_type?.message})]}),e.jsxs("div",{children:[e.jsx(N,{label:"Número de Documento *",placeholder:"12345678",error:i.document_number?.message,disabled:l,...j("document_number")}),e.jsx(c,{message:i.document_number?.message})]}),e.jsxs("div",{children:[e.jsx(N,{label:"Nombres *",placeholder:"Juan Carlos",error:i.names?.message,disabled:l,...j("names")}),e.jsx(c,{message:i.names?.message})]}),e.jsxs("div",{children:[e.jsx(N,{label:"Apellido Paterno *",placeholder:"Pérez",error:i.paternal_surname?.message,disabled:l,...j("paternal_surname")}),e.jsx(c,{message:i.paternal_surname?.message})]}),e.jsxs("div",{children:[e.jsx(N,{label:"Apellido Materno *",placeholder:"García",error:i.maternal_surname?.message,disabled:l,...j("maternal_surname")}),e.jsx(c,{message:i.maternal_surname?.message})]}),e.jsxs("div",{children:[e.jsx(N,{type:"date",label:"Fecha de Nacimiento *",error:i.birth_date?.message,disabled:l,...j("birth_date")}),e.jsx(c,{message:i.birth_date?.message})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1.5",children:"Género *"}),e.jsx("select",{...j("gender"),disabled:l,className:"w-full px-3 py-2 text-sm border border-gray-300 rounded-lg",children:Ze.map(a=>e.jsx("option",{value:a.value,children:a.label},a.value))}),e.jsx(c,{message:i.gender?.message})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1.5",children:"Estado Civil *"}),e.jsx("select",{...j("marital_status"),disabled:l,className:"w-full px-3 py-2 text-sm border border-gray-300 rounded-lg",children:We.map(a=>e.jsx("option",{value:a.value,children:a.label},a.value))}),e.jsx(c,{message:i.marital_status?.message})]})]}),e.jsxs("div",{className:"mt-4",children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1.5",children:"Lugar de Nacimiento *"}),e.jsx($,{name:"birth_place_id",control:O,render:({field:a})=>e.jsx(R,{value:a.value,onChange:a.onChange,onSearch:s,onLoadSelected:p,renderOption:P,getDisplayText:L,initialItem:u?.birth_district,placeholder:"Buscar distrito...",error:i.birth_place_id?.message,disabled:l,minSearchLength:3,manualSearch:!0})}),e.jsx(c,{message:i.birth_place_id?.message})]}),e.jsxs("div",{className:"mt-4",children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:["Idiomas * ",b.length>0&&e.jsxs("span",{className:"ml-2 text-xs text-blue-600",children:["(",b.length,")"]})]}),e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 gap-3",children:He.map(a=>e.jsxs("label",{className:"flex items-center gap-2 p-3 border rounded-lg cursor-pointer hover:bg-blue-50",children:[e.jsx("input",{type:"checkbox",value:a.value,...j("languages"),disabled:l,className:"w-4 h-4 text-blue-600 rounded"}),e.jsx("span",{className:"text-sm",children:a.label})]},a.value))}),e.jsx(c,{message:i.languages?.message})]})]}),e.jsxs("section",{className:"border-t pt-6",children:[e.jsxs("h3",{className:"text-base font-semibold text-gray-900 mb-4 flex items-center gap-2",children:[e.jsx(xe,{className:"w-5 h-5 text-blue-600"}),"Contacto"]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(N,{label:"Teléfono *",placeholder:"999999999",error:i.phone_number?.message,disabled:l,...j("phone_number")}),e.jsx(c,{message:i.phone_number?.message})]}),e.jsxs("div",{children:[e.jsx(N,{label:"WhatsApp *",placeholder:"999999999",error:i.whatsapp_number?.message,disabled:l,...j("whatsapp_number")}),e.jsx(c,{message:i.whatsapp_number?.message})]}),e.jsxs("div",{className:"md:col-span-2",children:[e.jsx(N,{type:"email",label:"Email *",placeholder:"estudiante@example.com",error:i.email?.message,disabled:l,...j("email")}),e.jsx(c,{message:i.email?.message})]})]})]}),e.jsxs("section",{className:"border-t pt-6",children:[e.jsxs("h3",{className:"text-base font-semibold text-gray-900 mb-4 flex items-center gap-2",children:[e.jsx(he,{className:"w-5 h-5 text-blue-600"}),"Residencia"]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx(N,{label:"Dirección *",placeholder:"Av. Principal 123",error:i.residence_address?.message,disabled:l,...j("residence_address")}),e.jsx(c,{message:i.residence_address?.message})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1.5",children:"Distrito *"}),e.jsx($,{name:"residence_place_id",control:O,render:({field:a})=>e.jsx(R,{value:a.value,onChange:a.onChange,onSearch:s,onLoadSelected:p,renderOption:P,getDisplayText:L,initialItem:u?.residence_district,placeholder:"Buscar distrito...",error:i.residence_place_id?.message,disabled:l,minSearchLength:3,manualSearch:!0})}),e.jsx(c,{message:i.residence_place_id?.message})]})]})]}),e.jsxs("section",{className:"border-t pt-6",children:[e.jsxs("h3",{className:"text-base font-semibold text-gray-900 mb-4 flex items-center gap-2",children:[e.jsx(ge,{className:"w-5 h-5 text-blue-600"}),"Educación"]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1.5",children:"Colegio *"}),e.jsx($,{name:"school_id",control:O,render:({field:a})=>e.jsx(R,{value:a.value,onChange:a.onChange,onSearch:w,onLoadSelected:M,renderOption:W,getDisplayText:t,initialItem:u?.school,placeholder:"Buscar colegio...",error:i.school_id?.message,disabled:l,minSearchLength:3,manualSearch:!0})}),e.jsx(c,{message:i.school_id?.message})]}),e.jsxs("div",{children:[e.jsx(N,{type:"number",label:"Año de Graduación (opcional)",placeholder:"2020",error:i.school_graduation_year?.message,disabled:l,...j("school_graduation_year",{valueAsNumber:!0})}),e.jsx(c,{message:i.school_graduation_year?.message})]})]})]}),e.jsxs("div",{className:"flex items-center justify-end gap-3 pt-4 border-t",children:[e.jsx(B,{type:"button",variant:"ghost",text:"Cancelar",leftIcon:e.jsx(pe,{className:"w-4 h-4"}),onClick:d,disabled:l}),e.jsx(B,{type:"submit",variant:"primary",text:l?"Guardando...":"Actualizar",leftIcon:!l&&e.jsx(le,{className:"w-4 h-4"}),loading:l,disabled:l})]})]})},fs=()=>{fe();const{data:u,loading:h,error:d,fetchStudents:r}=V(),[l,n]=m.useState(!1),[_,v]=m.useState(!1),[g,S]=m.useState(!1),[x,j]=m.useState(null),o={sort_by:"id",order:"desc",per_page:10},i=[{key:"id",label:"ID",sortable:!0,wrap:!1,width:"w-16"},{key:"document_number",label:"Documento",sortable:!0,wrap:!1},{key:"names",label:"Nombres Completos",sortable:!0,wrap:!0,render:(w,M)=>`${M.names} ${M.paternal_surname} ${M.maternal_surname}`},{key:"active",label:"Estado",sortable:!0,wrap:!1,render:w=>w?e.jsx(G,{className:"w-5 h-5 text-green-600",title:"Activo"}):e.jsx(ae,{className:"w-5 h-5 text-red-600",title:"Inactivo"})},{key:"validated_information",label:"Validación",sortable:!0,wrap:!1,render:w=>w?e.jsx(G,{className:"w-5 h-5 text-blue-600",title:"Validado"}):e.jsx(ae,{className:"w-5 h-5 text-gray-400",title:"No validado"})}],I=()=>{n(!0)},O=w=>{j(w),v(!0)},k=w=>{j(w),S(!0)},C=()=>{n(!1)},b=()=>{v(!1),j(null)},s=()=>{S(!1),j(null)},p=()=>{n(!1),v(!1),j(null),r(o)},P=()=>{r(o)},L=w=>e.jsxs(e.Fragment,{children:[e.jsx(H,{permission:"students.update",children:e.jsx("button",{onClick:()=>k(w),className:"p-2 text-purple-600 hover:bg-purple-50 rounded-lg transition-colors cursor-pointer",title:"Operaciones",children:e.jsx(Ie,{className:"w-4 h-4"})})}),e.jsx(H,{permission:"students.update",children:e.jsx("button",{onClick:()=>O(w),className:"p-2 text-orange-600 hover:bg-orange-50 rounded-lg transition-colors cursor-pointer",title:"Editar",children:e.jsx(De,{className:"w-4 h-4"})})})]});return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold text-gray-800",children:"Gestión de Estudiantes"}),e.jsx("p",{className:"text-gray-600 mt-1",children:"Administra los estudiantes del sistema"})]}),e.jsx(H,{permission:"students.store",children:e.jsxs("button",{onClick:I,className:"flex items-center gap-2 px-4 py-2 text-white bg-[#00306e] rounded-lg hover:bg-[#002555] transition-colors",children:[e.jsx(Se,{className:"w-5 h-5"}),"Nuevo Estudiante"]})})]}),d&&e.jsx(Ne,{variant:"warning",message:"⚠️ Hubo un problema al realizar la operación.",autoClose:3e3}),e.jsx(_e,{columns:i,data:u,onFetchData:r,initialParams:o,renderActions:L,loading:h,searchable:!0,autoSearch:!1,sortable:!0,searchPlaceholder:"Buscar estudiantes...",emptyMessage:"No hay estudiantes registrados",perPageOptions:[10,25,50,100]}),e.jsx(ee,{isOpen:l,onClose:C,title:"Crear Estudiante",size:"xl",closeOnClickOutside:!1,children:e.jsx(Fe,{onSuccess:p,onCancel:C})}),e.jsx(ee,{isOpen:_,onClose:b,title:"Editar Estudiante",size:"xl",closeOnClickOutside:!1,children:e.jsx(Ye,{studentData:x,onSuccess:p,onCancel:b})}),e.jsx(Ee,{isOpen:g,onClose:s,title:"Operaciones del Estudiante",subtitle:x?`${x.names} ${x.paternal_surname} ${x.maternal_surname}`:"",closeOnEscape:!0,children:e.jsx(Le,{student:x,onSuccess:P})})]})};export{fs as default};
