import{a as e}from"./chunk-BNv3lrIs.js";import{n as t,t as n}from"./jsx-runtime-pmtNMKr4.js";import{n as r}from"./toast-hrvP3G3Q.js";import{t as i}from"./DropdownActions-DPd7qitt.js";import{t as a}from"./useMediaQuery-C_7KdS3g.js";import{t as o}from"./load-HIf6x4Qy.js";import{t as s}from"./dayjs.min-CvL7oEs_.js";import{t as c}from"./es-B8cbrmO0.js";import{t as l}from"./localizedFormat-CVLUt9Cf.js";import{A as u,Jt as d,Lt as f,Vi as p,bi as m}from"./index-CBXvBSuP.js";import{t as h}from"./withRouter-BfV3B9Vo.js";import{t as g}from"./PageHeader-C3X_ZaAc.js";import{t as _}from"./DataTable-BuE1Zp8A.js";import{t as v}from"./useTheme-D5mB3Mad.js";import{t as y}from"./query-string-B0XJl1mO.js";import{n as b,t as x}from"./saldosCliente-BvBFuay_.js";import{n as S,t as C}from"./resguardo-X2c6b52w.js";var w=e(s(),1);c();var T=e(l(),1),E=e(t(),1),D=n();function O({data:e,history:t,setShow:n}){let[i,a]=(0,E.useState)(k),[o,s]=(0,E.useState)(!1),[c,l]=(0,E.useState)([]),u=()=>{try{b(e[1]).then(e=>{let{data:t}=e;l(A(t))}).catch(e=>{})}catch{}};(0,E.useEffect)(()=>{u()},[]),console.log(c);let d=async()=>{try{let t={saldo:Number(c[0].saldo)+Number(e[2])};x(e[1],t).then(e=>{let{data:n}=e;f(`Se ha actualizado el saldo del cliente  `,t)}).catch(e=>{if(e.message===`Network Error`)r.error(`Conexión al servidor no disponible`),s(!1);else if(e.response&&e.response.status===401){let{mensaje:t}=e.response.data;r.error(t),s(!1)}})}catch{r.error(`Error al iniciar sesión`),s(!1)}};return console.log(i.monto),(0,D.jsx)(`div`,{className:`containerInicio`,children:(0,D.jsxs)(m,{onChange:e=>{a({...i,[e.target.name]:e.target.value})},onSubmit:async i=>{i.preventDefault(),s(!0);try{let i={estado:`false`};C(e[0],i).then(e=>{let{data:a}=e;console.log(a),d(),r.success(a.mensaje),t({search:y.stringify(``)}),f(`Se ha registrado el resguardo al cliente `+i.cliente,i),s(!1),n(!1)}).catch(e=>{if(e.message===`Network Error`)r.error(`Conexión al servidor no disponible`),s(!1);else if(e.response&&e.response.status===401){let{mensaje:t}=e.response.data;r.error(t),s(!1)}})}catch{r.error(`Error al iniciar sesión`),s(!1)}},children:[(0,D.jsxs)(m.Group,{className:`datosPersonalesReg`,children:[(0,D.jsxs)(m.Label,{children:[`Cliente: `,(0,D.jsx)(`code`,{children:`*`})]}),(0,D.jsx)(m.Control,{type:`text`,className:`nomNewUser`,placeholder:`Cliente`,name:`cliente`,value:e[1],disabled:!0})]}),(0,D.jsxs)(m.Group,{className:`datosAcceso`,children:[(0,D.jsxs)(m.Label,{children:[`Monto: `,(0,D.jsx)(`code`,{children:`*`})]}),(0,D.jsx)(m.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[r,s]=(0,E.useState)(!0);(0,E.useEffect)(()=>{setTimeout(()=>{s(!1)},500)},[]);let[c,l]=(0,E.useState)([]),f=()=>{try{S().then(e=>{let{data:t}=e;l(M(t))}).catch(e=>{})}catch{}};(0,E.useEffect)(()=>{f()},[t]);let[m,h]=(0,E.useState)(!0),[y,b]=(0,E.useState)([]),x=()=>{let e=setTimeout(()=>{b(c),h(!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 a(v().breakpoints.down(`sm`)),(0,D.jsxs)(D.Fragment,{children:[r&&(0,D.jsx)(o,{}),(0,D.jsx)(g,{title:`Resguardos`,icon:d}),(0,D.jsx)(`div`,{className:`divTabla`,children:(0,D.jsx)(_,{title:`Lista de resguardos registrados`,datos:c,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)(i,{buttonColor:`minimal`,icon:`fas fa-ellipsis-v`,children:(0,D.jsx)(i.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)(u,{show:C,onClose:()=>k(!1),maxWidth:`xl`,children:[(0,D.jsx)(u.Header,{closeButton:!0,onClose:()=>k(!1),children:N}),(0,D.jsx)(u.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=h(j);export{N as default};