import{q,r as a,S as z,j as e,a as H,f}from"./app-BZJf8lgN.js";import{T as M}from"./toast.esm-CYGIlaDH.js";import{B as r}from"./button.esm-D_cwsnQR.js";import{L as R}from"./layout-DZ5xjWdd.js";import{D as V,C as y}from"./column.esm-BrHEUUD7.js";import{D as b}from"./dialog.esm-B_DzXfDY.js";import{I as n}from"./inputtext.esm-B1lZn37a.js";import{c as F,C as P}from"./confirmdialog.esm-DF1Ea2vk.js";import{M as w}from"./message.esm-Do6SkgWF.js";import"./csstransition.esm-BNRxTMOa.js";import"./hooks.esm-UVLztt_0.js";import"./CSSTransition-DBuKQJwM.js";import"./index.esm-CygY3Qsw.js";import"./index.esm-B5zYYMSp.js";import"./index.esm-hRnQzR_k.js";import"./index.esm-mvXJc0W-.js";import"./dropdown.esm-HqLoOpxI.js";import"./overlayservice.esm-B-BnP5c1.js";import"./index.esm-Ckth6fI3.js";const me=({categoriaAmcs:S})=>{const{errors:i}=q().props,s=a.useRef(null),{reset:A}=z(),[N,c]=a.useState(!1),[E,m]=a.useState(!1),[d,C]=a.useState({orden:"",titulo:""}),[o,x]=a.useState({id:null,orden:"",titulo:""}),[l,u]=a.useState(null),[U,W]=a.useState(1),D=t=>e.jsxs(e.Fragment,{children:[" ",e.jsx(r,{type:"button",icon:"pi pi-pencil",onClick:()=>T(t)})," ",e.jsx(r,{type:"button",icon:"pi pi-times",severity:"danger",onClick:()=>O(t.id)})," "]}),T=t=>{x(t),m(!0)},k=()=>{console.log(l),f.delete(route("categoria-amcs.destroy",l),{onSuccess:()=>{s.current.show({severity:"info",summary:"Categoria Eliminada",detail:"Se ha eliminado una categoria amc",life:3e3})}}),u(null)},I=()=>{s.current.show({severity:"warn",summary:"Cancelado",detail:"No se ha eliminado nada",life:3e3}),u(null)},j=t=>{const g=t.target.name,p=t.target.value;C(h=>({...h,[g]:p}))},v=t=>{const g=t.target.name,p=t.target.value;x(h=>({...h,[g]:p}))},B=t=>{t.preventDefault(),f.post(route("categoria-amcs.store"),d,{onSuccess:()=>{s.current.show({severity:"success",summary:"Exito",detail:"Categoria Amc Agregada",life:3e3}),C({orden:"",titulo:""}),c(!1)}})},L=t=>{t.preventDefault(),console.log(o),f.post(route("categoria-amcs.update",o.id),{...o,_method:"put",preserveState:!1},{onSuccess:()=>{s.current.show({severity:"success",summary:"Exito",detail:"Categoria Amc Actualizada",life:3e3}),A()}}),m(!1)},O=t=>{console.log(t),u(t)};return a.useEffect(()=>{l!=null&&F({message:"Esta seguro/a que desea eliminar una categoria amc?",header:"Eliminar Categoria Amc",icon:"pi pi-exclamation-triangle",defaultfocus:"accept",accept:k,reject:I})},[l]),e.jsxs(R,{children:[e.jsx(b,{header:"Agregar Categoria Amc",visible:N,style:{width:"50vw"},onHide:()=>c(!1),children:e.jsxs("form",{onSubmit:B,children:[e.jsx(n,{name:"orden",placeholder:"Orden",value:d.orden,className:"w-full mb-2",onChange:j}),i.orden&&e.jsx(w,{severity:"error",text:i.orden}),e.jsx(n,{name:"titulo",placeholder:"Titulo",value:d.titulo,className:"w-full mb-2",onChange:j}),i.titulo&&e.jsx(w,{severity:"error",text:i.titulo}),e.jsx(r,{type:"submit",className:"mt-5",style:{display:"block",margin:"auto"},children:"Agregar Categoria Amc"})]})}),e.jsx(b,{header:"Editar Categoria Amc",visible:E,style:{width:"50vw"},onHide:()=>m(!1),children:e.jsxs("form",{onSubmit:L,children:[e.jsx(n,{name:"orden",placeholder:"Orden",value:o.orden,className:"w-full mb-2",onChange:v}),e.jsx(n,{name:"titulo",placeholder:"Titulo",value:o.titulo,className:"w-full mb-2",onChange:v}),e.jsx(r,{type:"submit",className:"mt-5",style:{display:"block",margin:"auto"},children:"Actualizar Categoria Amc"})]})}),e.jsx(P,{}),e.jsx(H,{title:"Editar Categoria Amcs"}),e.jsx("div",{className:"grid",children:e.jsx("div",{className:"col-md-12",children:e.jsxs("div",{className:"card",children:[e.jsx("div",{className:"card-header",style:{marginLeft:"80%"},children:e.jsx(r,{onClick:()=>c(!0),className:"mb-2",children:"Agregar Categoria Amc"})}),e.jsx(M,{ref:s}),e.jsxs(V,{value:S,tableStyle:{minWidth:"50rem"},children:[e.jsx(y,{field:"orden",header:"Orden"}),e.jsx(y,{field:"titulo",header:"Titulo"}),e.jsx(y,{header:"Acciones",body:D})]})]})})})]})};export{me as default};
//# sourceMappingURL=CategoriaAmcs-CKoszr_4.js.map
