import{r as D,G as N,j as e,t as c}from"./app-C7YxHmQz.js";import{A as y,a as A,b as G,c as O,d as I}from"./alert-dialog-S-fo0VnI.js";import{B as m}from"./button-CJ9RiI_R.js";import{I as M}from"./input-BY0xThFe.js";import{L as u}from"./label-tf5I4axp.js";import{u as S}from"./useGradoStore-DNXbWJ5U.js";import{v as k}from"./validations-CdsIOtZM.js";import"./index-CCZex4bU.js";import"./index-Cp62Blk_.js";import"./index-w2AxdR7H.js";import"./utils-DjqsqOe8.js";import"./react-3TENqYnz.js";function Q(){const s=D.useId(),{grado:r,openModalCreateOrEditGrado:p,setOpenModalCreateOrEditGrado:t}=S(),{data:a,setData:f,post:x,put:b,reset:h,clearErrors:j,processing:g,errors:l}=N({id:(r==null?void 0:r.id)??null,nombre:(r==null?void 0:r.nombre)||""}),v=i=>{i.preventDefault();const o={preserveScroll:!0,onSuccess:n=>{var d;h();const E=((d=n.props.status)==null?void 0:d.success)||"Operación realizada con éxito.";c.success(E),t(!1)},onError:n=>{c.error(n.nombre||"Error en el formulario.")}};a.id?b(route("grados.update",{grado:a.id}),o):x(route("grados.store"),o),j()},C=i=>{const o=i.target.value;k(o)&&f("nombre",o)};return e.jsx(y,{open:p,onOpenChange:()=>t(!1),children:e.jsxs(A,{children:[e.jsxs(G,{children:[e.jsxs(O,{children:[r!=null&&r.id?"Editar":"Crear"," Grado Escolar"]}),e.jsx(I,{children:r!=null&&r.id?"Modifica los datos del grado y guarda los cambios.":"Ingresa los datos para registrar un nuevo grado."})]}),e.jsxs("form",{onSubmit:v,children:[e.jsx(u,{htmlFor:s,children:"Nombre"}),e.jsx(M,{id:s,type:"text",value:a.nombre,className:"mt-1 block w-full",placeholder:"Nombre del grado",onChange:C,required:!0}),l.nombre&&e.jsx(u,{className:"text-destructive",htmlFor:s,children:l.nombre}),e.jsxs("footer",{className:"flex justify-around gap-4 mt-4",children:[e.jsx(m,{type:"button",onClick:()=>t(!1),variant:"secondary",children:"Cancelar"}),e.jsx(m,{type:"submit",disabled:g,children:"Guardar"})]})]})]})})}export{Q as ModalCreateOrEdit};
