import{r as d,X as M,G as k,j as e,t as x}from"./app-C7YxHmQz.js";import{A as P,a as T,b as $,c as q,d as B}from"./alert-dialog-S-fo0VnI.js";import{B as j}from"./button-CJ9RiI_R.js";import{I as v}from"./input-BY0xThFe.js";import{L as o}from"./label-tf5I4axp.js";import{u as G}from"./useConductaStore-BQNmL948.js";import{v as b}from"./validations-CdsIOtZM.js";import{f as L,C as _,a as z,e as H}from"./calendar-mAPtQ_t5.js";import{c as R}from"./utils-DjqsqOe8.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";function ie(){const u=d.useId(),m=d.useId(),C=d.useId(),{estudiante:g}=M().props,{conducta:t,openModalCreateOrEditConducta:D,setOpenModalCreateOrEditConducta:p}=G(),{data:r,setData:h,post:N,put:O,reset:y,clearErrors:E,processing:S,errors:i}=k({id:(t==null?void 0:t.id)??null,fecha:(t==null?void 0:t.fecha)||"",conducta:(t==null?void 0:t.conducta)||"",observacion:(t==null?void 0:t.observacion)||"",id_estudiante:(t==null?void 0:t.id_estudiante)||g.id||void 0}),F=a=>{a.preventDefault();const s={preserveScroll:!0,onSuccess:l=>{var c;y();const f=((c=l.props.status)==null?void 0:c.success)||"Operación realizada con éxito.";x.success(f),p(!1)},onError:l=>{l?Object.entries(l).forEach(([f,c])=>{x.error(`${f}: ${c}`)}):x.error("Error en el formulario.")}};r.id?O(route("conductas.update",{id:r.id}),s):N(route("conductas.store"),s),E()},I=a=>{const s=a.target.value;b(s)&&h("conducta",s)},w=a=>{const s=a.target.value;b(s)&&h("observacion",s)},[n,A]=d.useState(r.fecha?new Date(r.fecha):void 0);return e.jsx(P,{open:D,onOpenChange:()=>p(!1),children:e.jsxs(T,{children:[e.jsxs($,{children:[e.jsxs(q,{children:[t!=null&&t.id?"Editar":"Crear"," Conducta"]}),e.jsx(B,{children:t!=null&&t.id?"Modifica los datos de la conducta y guarda los cambios.":"Ingresa los datos para registrar una nueva conducta."})]}),e.jsxs("form",{onSubmit:F,children:[e.jsx(o,{htmlFor:u,children:"Conducta"}),e.jsx(v,{id:u,type:"text",value:r.conducta,className:"mt-1 block w-full",placeholder:"Nombre de la conducta",onChange:I,required:!0}),i.conducta&&e.jsx(o,{className:"text-destructive",htmlFor:u,children:i.conducta}),e.jsx(o,{htmlFor:m,children:"Observación"}),e.jsx(v,{id:m,type:"text",value:r.observacion,className:"mt-1 block w-full",placeholder:"Nombre de la conducta",onChange:w,required:!0}),i.observacion&&e.jsx(o,{className:"text-destructive",htmlFor:m,children:i.observacion}),e.jsx(o,{children:"Fecha"}),e.jsx(o,{htmlFor:C,children:"Fecha"}),e.jsxs("div",{className:" mt-4",children:[e.jsxs(j,{variant:"outline",type:"button",className:R("w-full pl-3 text-left font-normal",!n&&"text-muted-foreground"),children:[n?L(n,"PPP",{locale:H}):e.jsx("span",{children:"Selecciona una fecha"}),e.jsx(_,{className:"ml-auto h-4 w-4 opacity-50"})]}),e.jsx("div",{className:" flex justify-center",children:e.jsx(z,{mode:"single",selected:n,onSelect:a=>{A(a),a&&h("fecha",a.toISOString().split("T")[0])},disabled:a=>a>new Date||a<new Date("1900-01-01"),initialFocus:!0})})]}),e.jsxs("footer",{className:"flex justify-around gap-4 mt-4",children:[e.jsx(j,{type:"button",onClick:()=>p(!1),variant:"secondary",children:"Cancelar"}),e.jsx(j,{type:"submit",disabled:S,children:"Guardar"})]})]})]})})}export{ie as ModalCreateOrEditConducta};
