import{r as i,S as I,j as e,a as y,J as b}from"./app-BZJf8lgN.js";import{F as w}from"./fileupload.esm-CWt4e-Qk.js";import{I as g}from"./inputtext.esm-B1lZn37a.js";import{B as N}from"./button.esm-D_cwsnQR.js";import{I as F}from"./image.esm-DhzuK4QZ.js";import{I as T}from"./InputLabel-Dd3VnoK3.js";import{L as R}from"./layout-DZ5xjWdd.js";import{T as A}from"./toast.esm-CYGIlaDH.js";import{M as m}from"./message.esm-Do6SkgWF.js";import"./hooks.esm-UVLztt_0.js";import"./index.esm-Ckth6fI3.js";import"./index.esm-hRnQzR_k.js";import"./csstransition.esm-BNRxTMOa.js";import"./CSSTransition-DBuKQJwM.js";import"./index.esm-CygY3Qsw.js";import"./index.esm-B5zYYMSp.js";const Z=({servicio:o,isEdit:r=!1})=>{var u;const l=i.useRef(null),[L,C]=i.useState(r?o.imagenes:[]),[M,P]=i.useState(!r||!((u=o.imagenes)!=null&&u.length)),[p,q]=i.useState(r?o.imagen:null),{data:c,setData:a,post:x,errors:s,reset:v}=I({orden:r?o.orden:null,titulo:r?o.titulo:null,newImgFile:null,_method:r?"PUT":null}),h=t=>{t.preventDefault();const f=r?"servicios.update":"servicios.store",j=r?{id:o.id}:{},S=r?"Servicio Editado":"Servicio Agregado";x(route(f,j),{onSuccess:n=>{if(l.current.show({severity:"success",summary:"Exito",detail:S,life:3e3}),r){const{servicio:d}=n.props;a("orden",d.orden),a("titulo",d.titulo)}else v(),setTimeout(()=>{location.reload()},1100)},onError:n=>{console.error("Error submitting form:",n),l.current.show({severity:"error",summary:"Error",detail:"Ocurrió un error al guardar el servicio.",life:3e3})}})};return e.jsxs(R,{children:[e.jsx(A,{ref:l}),e.jsx(y,{title:r?"Editar Servicio":"Agregar Servicio"}),e.jsx("div",{className:"grid",children:e.jsx("div",{className:"col-12",children:e.jsxs("div",{className:"card",children:[e.jsxs("div",{className:"card-header mb-2",style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("h2",{className:"text-lg font-medium text-gray-900",children:r?"Editar Servicio":"Agregar Servicio"}),e.jsx(b,{className:"p-button text-white",href:route("servicios.index"),children:"Volver"})]}),e.jsxs("form",{onSubmit:h,children:[e.jsx(g,{className:"w-full mb-2",placeholder:"Orden",value:c.orden,name:"orden",onChange:t=>a("orden",t.target.value)}),s.orden&&e.jsx(m,{severity:"error",text:s.orden}),e.jsx(g,{className:"w-full mb-2",placeholder:"Titulo",value:c.titulo,name:"titulo",onChange:t=>a("titulo",t.target.value)}),s.titulo&&e.jsx(m,{severity:"error",text:s.titulo}),e.jsx(F,{src:p,alt:"Imagen",width:"200px",height:"200px"})," ",e.jsx(w,{mode:"basic",name:"newImgFile",className:"mt-3",accept:"image/*",chooseLabel:"Subir Imagen",onSelect:t=>{a("newImgFile",t.files[0])}}),e.jsx(T,{children:"Resolucion recomendada 288*392px"}),s.newImgFile&&e.jsx(m,{severity:"error",text:s.newImgFile}),e.jsx(N,{type:"submit",className:"mt-5",style:{display:"block",margin:"auto"},children:r?"Editar Servicio":"Agregar Servicio"})]})]})})})]})};export{Z as default};
//# sourceMappingURL=FormServicios-B6HDlhCt.js.map
