import{r as e}from"./chunk-QTnfLwEv.js";import{n as t,t as n}from"./jsx-runtime-BWRPWl8p.js";import{t as r}from"./DropdownActions-zmC64Ml1.js";import{t as i}from"./dayjs.min-aszMaMjE.js";import{C as a,Da as o,G as s,Li as c,Qt as l,S as u,W as d,dn as f,ha as p}from"./index-DccLTdzK.js";import{t as m}from"./withRouter-CRkgdzqj.js";import{t as h}from"./PageHeader-DNnlanBD.js";import{t as g}from"./DataTable-KLBE0uXO.js";import{t as _}from"./useTheme-ClV7RdEj.js";import{t as v}from"./useMediaQuery-Diq4jKog.js";import{t as y}from"./query-string-D4ReIoyH.js";import{n as b,t as x}from"./saldosCliente-BcsMXWtS.js";import{n as S,t as C}from"./resguardo-BJh9x934.js";var w=e(i(),1);a();var T=e(u(),1),E=e(t(),1),D=n();function O({data:e,history:t,setShow:n}){let[r,i]=(0,E.useState)(k),[a,s]=(0,E.useState)(!1),[u,d]=(0,E.useState)([]),f=()=>{try{b(e[1]).then(e=>{let{data:t}=e;d(A(t))}).catch(e=>{})}catch{}};(0,E.useEffect)(()=>{f()},[]),console.log(u);let p=async()=>{try{let t={saldo:Number(u[0].saldo)+Number(e[2])};x(e[1],t).then(e=>{let{data:n}=e;l(`Se ha actualizado el saldo del cliente  `,t)}).catch(e=>{if(e.message===`Network Error`)o.error(`Conexión al servidor no disponible`),s(!1);else if(e.response&&e.response.status===401){let{mensaje:t}=e.response.data;o.error(t),s(!1)}})}catch{o.error(`Error al iniciar sesión`),s(!1)}};return console.log(r.monto),(0,D.jsx)(`div`,{className:`containerInicio`,children:(0,D.jsxs)(c,{onChange:e=>{i({...r,[e.target.name]:e.target.value})},onSubmit:async r=>{r.preventDefault(),s(!0);try{let r={estado:`false`};C(e[0],r).then(e=>{let{data:i}=e;console.log(i),p(),o.success(i.mensaje),t({search:y.stringify(``)}),l(`Se ha registrado el resguardo al cliente `+r.cliente,r),s(!1),n(!1)}).catch(e=>{if(e.message===`Network Error`)o.error(`Conexión al servidor no disponible`),s(!1);else if(e.response&&e.response.status===401){let{mensaje:t}=e.response.data;o.error(t),s(!1)}})}catch{o.error(`Error al iniciar sesión`),s(!1)}},children:[(0,D.jsxs)(c.Group,{className:`datosPersonalesReg`,children:[(0,D.jsxs)(c.Label,{children:[`Cliente: `,(0,D.jsx)(`code`,{children:`*`})]}),(0,D.jsx)(c.Control,{type:`text`,className:`nomNewUser`,placeholder:`Cliente`,name:`cliente`,value:e[1],disabled:!0})]}),(0,D.jsxs)(c.Group,{className:`datosAcceso`,children:[(0,D.jsxs)(c.Label,{children:[`Monto: `,(0,D.jsx)(`code`,{children:`*`})]}),(0,D.jsx)(c.Control,{type:`number`,className:`descripcion`,placeholder:`Ingrese el monto`,name:`monto`,defaultValue:e[2],disabled:!0})]}),(0,D.jsx)(`br`,{}),(0,D.jsx)(`label`,{}),(0,D.jsx)(`div`,{className:`divSubmit`,children:(0,D.jsx)(`input`,{className:`submit`,value:`Enviar`,type:`submit`})})]})})}function k(){return{monto:``}}function A(e){let t=[];return e.forEach(e=>{t.push({id:e._id,nombreCliente:e.nombreCliente,correoCliente:e.correoCliente,saldo:e.saldo})}),t}function j(e){let{location:t,history:n}=e;w.default.locale(`es`),w.default.extend(T.default);let[i,a]=(0,E.useState)(!0);(0,E.useEffect)(()=>{setTimeout(()=>{a(!1)},500)},[]);let[o,c]=(0,E.useState)([]),l=()=>{try{S().then(e=>{let{data:t}=e;c(M(t))}).catch(e=>{})}catch{}};(0,E.useEffect)(()=>{l()},[t]);let[u,m]=(0,E.useState)(!0),[y,b]=(0,E.useState)([]),x=()=>{let e=setTimeout(()=>{b(o),m(!1)},0);return()=>clearTimeout(e)};(0,E.useEffect)(()=>{x()},[]);let[C,k]=(0,E.useState)(!1),[A,j]=(0,E.useState)(null),[N,P]=(0,E.useState)(null),F=e=>{P(`Aprobar resguardo`),j(e),k(!0)};return v(_().breakpoints.down(`sm`)),(0,D.jsxs)(D.Fragment,{children:[i&&(0,D.jsx)(d,{}),(0,D.jsx)(h,{title:`Resguardos`,icon:f}),(0,D.jsx)(`div`,{className:`divTabla`,children:(0,D.jsx)(g,{title:`Lista de resguardos registrados`,datos:o,columnas:[{name:`ID`,selector:e=>e.id,omit:!0},{name:`CLIENTE`,selector:e=>e.cliente,sortable:!0},{name:`MONTO`,selector:e=>e.monto,sortable:!0},{name:`STATUS`,selector:e=>e.estado,sortable:!0,cell:e=>(0,D.jsx)(p,{bg:e.estado==`true`?`success`:`warning`,children:e.estado==`true`?`pendiente`:`Aplicado`})},{name:`ACCIONES`,cell:e=>{let t=[e.id,e.cliente,e.monto,e.estado];return(0,D.jsx)(r,{buttonColor:`minimal`,icon:`fas fa-ellipsis-v`,children:(0,D.jsx)(r.Button,{onClick:()=>F((0,D.jsx)(O,{data:t,history:n,setShow:k})),icon:`fas fa-check`,color:`text-blue-600`,children:`Aprobar resguardo`})})}}]})}),(0,D.jsxs)(s,{show:C,onClose:()=>k(!1),maxWidth:`xl`,children:[(0,D.jsx)(s.Header,{closeButton:!0,onClose:()=>k(!1),children:N}),(0,D.jsx)(s.Body,{children:A})]})]})}function M(e){let t=[];return e.forEach(e=>{t.push({id:e._id,cliente:e.cliente,monto:e.monto,estado:e.estado})}),t}var N=m(j);export{N as default};