import{q as P,r as t,S as R,j as e,a as O,f as x}from"./app-BZJf8lgN.js";import{F as w}from"./fileupload.esm-CWt4e-Qk.js";import{I as S}from"./InputLabel-Dd3VnoK3.js";import{I as H}from"./image.esm-DhzuK4QZ.js";import{T as U}from"./toast.esm-CYGIlaDH.js";import{B as l}from"./button.esm-D_cwsnQR.js";import{L as V}from"./layout-DZ5xjWdd.js";import{D as W,C as c}from"./column.esm-BrHEUUD7.js";import{D as I}from"./dialog.esm-B_DzXfDY.js";import{I as d}from"./inputtext.esm-B1lZn37a.js";import{c as _,C as $}from"./confirmdialog.esm-DF1Ea2vk.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";import"./index.esm-mvXJc0W-.js";import"./dropdown.esm-HqLoOpxI.js";import"./overlayservice.esm-B-BnP5c1.js";const he=({categorias:N})=>{const{errors:o}=P().props,i=t.useRef(null),{reset:f}=R(),[E,u]=t.useState(!1),[F,g]=t.useState(!1),[y,j]=t.useState({orden:"",titulo:"",newImgFile:""}),[s,p]=t.useState({id:null,orden:"",titulo:"",imagenPreview:"",newImgFile:""}),[n,C]=t.useState(null),[G,J]=t.useState(1),D=a=>e.jsx("img",{src:`${a.imagen}`,alt:a.imagen,className:"w-6rem shadow-2 border-round"}),T=a=>e.jsxs(e.Fragment,{children:[" ",e.jsx(l,{type:"button",icon:"pi pi-pencil",onClick:()=>q(a)})," ",e.jsx(l,{type:"button",icon:"pi pi-times",severity:"danger",onClick:()=>B(a.id)})," "]}),q=a=>{const{imagen:m,...r}=a;p({...r,imagenPreview:a.imagen}),g(!0)},k=()=>{console.log(n),x.delete(route("categorias-equipos.destroy",n),{onSuccess:()=>{i.current.show({severity:"info",summary:"Categoria Eliminada",detail:"Se ha eliminado una categoria",life:3e3})}}),C(null)},A=()=>{i.current.show({severity:"warn",summary:"Cancelado",detail:"No se ha eliminado nada",life:3e3}),setDeleteDistributorId(null)},b=a=>{const m=a.target.name,r=a.target.value;j(h=>({...h,[m]:r}))},v=a=>{const m=a.target.name,r=a.target.value;p(h=>({...h,[m]:r}))},L=a=>{a.preventDefault(),x.post(route("categorias-equipos.store"),y,{onSuccess:()=>{i.current.show({severity:"success",summary:"Exito",detail:"Categoria Agregada",life:3e3}),f(),u(!1)}})},z=a=>{a.preventDefault(),console.log(s),x.post(route("categorias-equipos.update",s.id),{...s,_method:"put",preserveState:!1},{onSuccess:()=>{i.current.show({severity:"success",summary:"Exito",detail:"Categoria Actualizada",life:3e3}),f()}}),g(!1)},B=a=>{console.log(a),C(a)};return t.useEffect(()=>{n!=null&&_({message:"Esta seguro/a que desea eliminar una categoria?",header:"Eliminar Categoria",icon:"pi pi-exclamation-triangle",defaultfocus:"accept",accept:k,reject:A})},[n]),e.jsxs(V,{children:[e.jsx(I,{header:"Agregar Categoria",visible:E,style:{width:"50vw"},onHide:()=>u(!1),children:e.jsxs("form",{onSubmit:L,children:[e.jsx(d,{name:"orden",placeholder:"Orden",className:"w-full mb-2",onChange:b}),o.orden&&e.jsx("div",{style:{color:"red"},children:o.orden}),e.jsx(d,{name:"titulo",placeholder:"Titulo",className:"w-full mb-2",onChange:b}),o.titulo&&e.jsx("div",{style:{color:"red"},children:o.titulo}),e.jsx(w,{mode:"basic",name:"newImgFile",className:"mt-2",accept:"image/*",maxFileSize:1e6,chooseLabel:"Subir Imagen",onSelect:a=>j({...y,newImgFile:a.files[0]}),required:!0}),e.jsx(S,{children:"Resolucion recomendada 390px * 340px"}),o.newImgFile&&e.jsx("div",{style:{color:"red"},children:o.newImgFile}),e.jsx(l,{type:"submit",className:"mt-5",style:{display:"block",margin:"auto"},children:"Agregar Categoria"})]})}),e.jsx(I,{header:"Editar Categoria",visible:F,style:{width:"50vw"},onHide:()=>g(!1),children:e.jsxs("form",{onSubmit:z,children:[e.jsx(d,{name:"orden",placeholder:"Orden",value:s.orden,className:"w-full mb-2",onChange:v}),e.jsx(d,{name:"titulo",placeholder:"Titulo",value:s.titulo,className:"w-full mb-2",onChange:v}),e.jsx(w,{mode:"basic",name:"newImgFile",className:"mt-2",accept:"image/*",maxFileSize:1e6,chooseLabel:"Subir Imagen",onSelect:a=>p({...s,newImgFile:a.files[0]})}),e.jsx(H,{src:s.imagenPreview}),e.jsx(S,{children:"Resolucion recomendada 390px * 340px"}),e.jsx(l,{type:"submit",className:"mt-5",style:{display:"block",margin:"auto"},children:"Actualizar Categoria"})]})}),e.jsx($,{}),e.jsx(O,{title:"Editar Categorias Equipos"}),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(l,{onClick:()=>u(!0),className:"mb-2",children:"Agregar Categoria"})}),e.jsx(U,{ref:i}),e.jsxs(W,{value:N,tableStyle:{minWidth:"50rem"},children:[e.jsx(c,{field:"orden",header:"Orden"}),e.jsx(c,{field:"titulo",header:"Titulo"}),e.jsx(c,{field:"imagen",header:"Image",body:D}),e.jsx(c,{header:"Acciones",body:T})]})]})})})]})};export{he as default};
//# sourceMappingURL=CategoriasEquipos-RQqNKiXT.js.map
