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