import{r as c,X as I,G as O,j as e,t as h}from"./app-C7YxHmQz.js";import{A as w,a as T,b as M,c as P,d as z}from"./alert-dialog-S-fo0VnI.js";import{B as f}from"./button-CJ9RiI_R.js";import{I as G}from"./input-BY0xThFe.js";import{L as a}from"./label-tf5I4axp.js";import{u as H}from"./useAsistenciaStore-BisxXSTq.js";import{f as $,C as k,a as B,e as L}from"./calendar-mAPtQ_t5.js";import{c as V}from"./utils-DjqsqOe8.js";import{S as _,a as q,b as R,c as X,e as J,d as x}from"./select-mU9SGeCM.js";import"./index-CCZex4bU.js";import"./index-Cp62Blk_.js";import"./index-w2AxdR7H.js";import"./react-3TENqYnz.js";import"./createLucideIcon-CBwNTxoJ.js";import"./chevron-right-DHVrRgbL.js";import"./index-Djfxw5dv.js";import"./index-BvfrUVYs.js";import"./index-rT265Z_w.js";function ue(){const j=c.useId(),d=c.useId(),S=c.useId(),{estudiante:v}=I().props,{asistencia:t,openModalCreateOrEditAsistencia:C,setOpenModalCreateOrEditAsistencia:p}=H(),{data:s,setData:u,post:b,put:A,reset:D,clearErrors:E,processing:y,errors:o}=O({id:(t==null?void 0:t.id)??null,fecha:(t==null?void 0:t.fecha)||"",tipo:(t==null?void 0:t.tipo)||"",hora:(t==null?void 0:t.hora.slice(0,5))||"",id_estudiante:(t==null?void 0:t.id_estudiante)||v.id||void 0}),F=r=>{r.preventDefault();const g={preserveScroll:!0,onSuccess:i=>{var n;D();const m=((n=i.props.status)==null?void 0:n.success)||"Operación realizada con éxito.";h.success(m),p(!1)},onError:i=>{i?Object.entries(i).forEach(([m,n])=>{h.error(`${m}: ${n}`)}):h.error("Error en el formulario.")}};s.id?A(route("asistencias.update",{id:s.id}),g):b(route("asistencias.store"),g),E()},[l,N]=c.useState(s.fecha?new Date(s.fecha):void 0);return e.jsx(w,{open:C,onOpenChange:()=>p(!1),children:e.jsxs(T,{children:[e.jsxs(M,{children:[e.jsxs(P,{children:[t!=null&&t.id?"Editar":"Crear"," Asistencia"]}),e.jsx(z,{children:t!=null&&t.id?"Modifica los datos de la asistencia y guarda los cambios.":"Ingresa los datos para registrar una nueva asistencia."})]}),e.jsxs("form",{onSubmit:F,children:[e.jsx(a,{htmlFor:j,children:"Tipo de Asistencia"}),e.jsxs(_,{value:s.tipo,onValueChange:r=>u("tipo",r),children:[e.jsx(q,{className:"w-full",children:e.jsx(R,{placeholder:"Seleccione un tipo"})}),e.jsx(X,{children:e.jsxs(J,{children:[e.jsx(x,{value:"presente",children:"Presente"}),e.jsx(x,{value:"tardanza",children:"Tardanza"}),e.jsx(x,{value:"falta",children:"Falta"})]})})]}),o.tipo&&e.jsx(a,{className:"text-destructive",htmlFor:j,children:o.tipo}),e.jsx(a,{htmlFor:S,children:"Fecha de Asistencia"}),e.jsxs("div",{className:" mt-4",children:[e.jsxs(f,{variant:"outline",type:"button",className:V("w-full pl-3 text-left font-normal",!l&&"text-muted-foreground"),children:[l?$(l,"PPP",{locale:L}):e.jsx("span",{children:"Selecciona una fecha"}),e.jsx(k,{className:"ml-auto h-4 w-4 opacity-50"})]}),e.jsx("div",{className:" flex justify-center",children:e.jsx(B,{mode:"single",selected:l,onSelect:r=>{N(r),r&&u("fecha",r.toISOString().split("T")[0])},disabled:r=>r>new Date||r<new Date("1900-01-01"),initialFocus:!0})})]}),e.jsx(a,{htmlFor:d,children:"Hora"}),e.jsx(G,{id:d,type:"time",step:"60",value:s.hora,className:"mt-1 block w-full",placeholder:"Seleccione la hora",onChange:r=>u("hora",r.target.value),required:!0}),o.hora&&e.jsx(a,{className:"text-destructive",htmlFor:d,children:o.hora}),e.jsxs("footer",{className:"flex justify-around gap-4 mt-4",children:[e.jsx(f,{type:"button",onClick:()=>p(!1),variant:"secondary",children:"Cancelar"}),e.jsx(f,{type:"submit",disabled:y,children:"Guardar"})]})]})]})})}export{ue as ModalCreateOrEditAsistencia};
