import{q,r as a,S as z,j as e,a as H,f as p}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 h}from"./column.esm-BrHEUUD7.js";import{D as v}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 b}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 de=({categorias:w})=>{const{errors:i}=q().props,s=a.useRef(null),{reset:f}=z(),[S,c]=a.useState(!1),[N,d]=a.useState(!1),[E,D]=a.useState({orden:"",titulo:""}),[o,y]=a.useState({id:null,orden:"",titulo:""}),[l,C]=a.useState(null),[U,W]=a.useState(1),T=t=>e.jsxs(e.Fragment,{children:[" ",e.jsx(r,{type:"button",icon:"pi pi-pencil",onClick:()=>k(t)})," ",e.jsx(r,{type:"button",icon:"pi pi-times",severity:"danger",onClick:()=>O(t.id)})," "]}),k=t=>{y(t),d(!0)},A=()=>{console.log(l),p.delete(route("categorias.destroy",l),{onSuccess:()=>{s.current.show({severity:"info",summary:"Categoria Eliminada",detail:"Se ha eliminado una categoria",life:3e3})}}),C(null)},I=()=>{s.current.show({severity:"warn",summary:"Cancelado",detail:"No se ha eliminado nada",life:3e3}),setDeleteDistributorId(null)},x=t=>{const m=t.target.name,u=t.target.value;D(g=>({...g,[m]:u}))},j=t=>{const m=t.target.name,u=t.target.value;y(g=>({...g,[m]:u}))},B=t=>{t.preventDefault(),p.post(route("categorias.store"),E,{onSuccess:()=>{s.current.show({severity:"success",summary:"Exito",detail:"Categoria Agregada",life:3e3}),f(),c(!1)}})},L=t=>{t.preventDefault(),console.log(o),p.post(route("categorias.update",o.id),{...o,_method:"put",preserveState:!1},{onSuccess:()=>{s.current.show({severity:"success",summary:"Exito",detail:"Categoria Actualizada",life:3e3}),f()}}),d(!1)},O=t=>{console.log(t),C(t)};return a.useEffect(()=>{l!=null&&F({message:"Esta seguro/a que desea eliminar una categoria?",header:"Eliminar Categoria",icon:"pi pi-exclamation-triangle",defaultfocus:"accept",accept:A,reject:I})},[l]),e.jsxs(R,{children:[e.jsx(v,{header:"Agregar Categoria",visible:S,style:{width:"50vw"},onHide:()=>c(!1),children:e.jsxs("form",{onSubmit:B,children:[e.jsx(n,{name:"orden",placeholder:"Orden",className:"w-full mb-2",onChange:x}),i.orden&&e.jsx(b,{severity:"error",text:i.orden}),e.jsx(n,{name:"titulo",placeholder:"Titulo",className:"w-full mb-2",onChange:x}),i.titulo&&e.jsx(b,{severity:"error",text:i.titulo}),e.jsx(r,{type:"submit",className:"mt-5",style:{display:"block",margin:"auto"},children:"Agregar Categoria"})]})}),e.jsx(v,{header:"Editar Categoria",visible:N,style:{width:"50vw"},onHide:()=>d(!1),children:e.jsxs("form",{onSubmit:L,children:[e.jsx(n,{name:"orden",placeholder:"Orden",value:o.orden,className:"w-full mb-2",onChange:j}),e.jsx(n,{name:"titulo",placeholder:"Titulo",value:o.titulo,className:"w-full mb-2",onChange:j}),e.jsx(r,{type:"submit",className:"mt-5",style:{display:"block",margin:"auto"},children:"Actualizar Categoria"})]})}),e.jsx(P,{}),e.jsx(H,{title:"Editar Categorias"}),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"})}),e.jsx(M,{ref:s}),e.jsxs(V,{value:w,tableStyle:{minWidth:"50rem"},children:[e.jsx(h,{field:"orden",header:"Orden"}),e.jsx(h,{field:"titulo",header:"Titulo"}),e.jsx(h,{header:"Acciones",body:T})]})]})})})]})};export{de as default};
//# sourceMappingURL=Categorias-DPYYWemc.js.map
