import{r as e}from"./chunk-QTnfLwEv.js";import{n as t,t as n}from"./jsx-runtime-BWRPWl8p.js";import{Da as r,Ei as i,G as a,Li as o,W as s,Yn as c,ai as l,ma as u}from"./index-DccLTdzK.js";import{t as d}from"./PageHeader-DNnlanBD.js";import{t as f}from"./DataTable-KLBE0uXO.js";import{t as p}from"./useTheme-ClV7RdEj.js";import{t as m}from"./useMediaQuery-Diq4jKog.js";import{t as h}from"./exportCSV-Dw_YB-vi.js";import{r as g}from"./movimientosMedicamentos-Bg3WWxJa.js";var _=e(t(),1),v=n();function y({props:e}){let[t,n]=(0,_.useState)(!0);(0,_.useEffect)(()=>{setTimeout(()=>{n(!1)},500)},[]);let[y,x]=(0,_.useState)(!0),[S,C]=(0,_.useState)([]),w=()=>{let e=setTimeout(()=>{C(z),x(!1)},0);return()=>clearTimeout(e)};(0,_.useEffect)(()=>{w()},[]);let T=[{name:`ID`,selector:e=>e.id,omit:!0},{name:`ID DEL ARTICULO`,selector:e=>e.idArticuloAMP,omit:!0},{name:`PRODUCTO`,selector:e=>e.producto,sortable:!0},{name:`TIPO`,selector:e=>e.tipo,sortable:!0},{name:`CANTIDAD MOVIMIENTO`,selector:e=>e.cantidadMovimiento,sortable:!0},{name:`UNIDAD DE MEDIDA`,selector:e=>e.unidadMedida,sortable:!0},{name:`DEPARTAMENTO`,selector:e=>e.departamento,sortable:!0}];m(p().breakpoints.down(`sm`));let[E,D]=(0,_.useState)(!1),[O,k]=(0,_.useState)(null),[A,j]=(0,_.useState)(null),M=()=>{let e=new Date;return`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,`0`)}-${String(e.getDate()).padStart(2,`0`)}`},[N,P]=(0,_.useState)(M()),[F,I]=(0,_.useState)(M()),L=e=>{P(e.target.value)},R=e=>{I(e.target.value)},[z,B]=(0,_.useState)([]),V=()=>{try{g(N,F).then(e=>{let{data:t}=e;B(b(t))}).catch(e=>{})}catch{}};return(0,_.useEffect)(()=>{V()},[N,F]),(0,v.jsxs)(v.Fragment,{children:[t&&(0,v.jsx)(s,{}),(0,v.jsx)(d,{title:`Movimientos Medicamentos`,icon:l,buttons:[(0,v.jsxs)(`div`,{className:`d-flex align-items-center flex-wrap gap-3 me-2`,children:[(0,v.jsxs)(o.Group,{className:`d-flex align-items-center gap-2 mb-0`,children:[(0,v.jsx)(o.Label,{className:`mb-0 text-nowrap text-secondary fw-semibold`,children:`Fecha Inicio:`}),(0,v.jsx)(o.Control,{type:`date`,name:`fechaInicio`,value:N,onChange:L,className:`glass-input`,style:{width:`auto`}})]}),(0,v.jsxs)(o.Group,{className:`d-flex align-items-center gap-2 mb-0`,children:[(0,v.jsx)(o.Label,{className:`mb-0 text-nowrap text-secondary fw-semibold`,children:`Fecha Fin:`}),(0,v.jsx)(o.Control,{type:`date`,name:`fechaFin`,value:F,onChange:R,className:`glass-input`,style:{width:`auto`}})]})]},`date-filters`),(0,v.jsxs)(u,{variant:`primary`,onClick:()=>{try{r.info(`Estamos empaquetando tu respaldo, espere por favor ....`);let e=setTimeout(()=>{h(z,`MOVIMIENTOS_MEDICAMENTOS_`+N+`-`+F)},5600);return()=>clearTimeout(e)}catch(e){console.log(e)}},className:`btn-premium d-flex align-items-center`,children:[(0,v.jsx)(i,{icon:c,className:`me-2`}),`CSV periodo`]},`btn-csv`)]}),(0,v.jsx)(`div`,{className:`divTabla`,children:(0,v.jsx)(f,{title:`Lista de movimientos del almacen`,datos:z,columnas:T})}),(0,v.jsxs)(a,{show:E,onClose:()=>D(!1),maxWidth:`xl`,children:[(0,v.jsx)(a.Header,{closeButton:!0,onClose:()=>D(!1),children:A}),(0,v.jsx)(a.Body,{children:O})]})]})}function b(e){let t=[];return e.forEach(e=>{t.push({id:e._id,idArticuloAMP:e.idArticuloAMP,tipo:e.tipo,producto:e.producto,cantidadMovimiento:e.cantidadMovimiento,unidadMedida:e.unidadMedida,departamento:e.departamento,fecha:e.createdAt})}),t}export{y as default};