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