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,Ei as o,G as s,S as c,W as l,b as u,fn as d,ha as f}from"./index-DccLTdzK.js";import{t as p}from"./DataTable-KLBE0uXO.js";import{t as m}from"./useTheme-ClV7RdEj.js";import{t as h}from"./useMediaQuery-Diq4jKog.js";import{a as g,t as _}from"./CancelarVale-g2_MBMS3.js";import{t as v}from"./EntregarMaterialVale-BSnIUfzN.js";var y=e(t(),1);a();var b=e(i(),1),x=e(c(),1),S=n(),C=()=>{h(m().breakpoints.down(`sm`));let[e,t]=(0,y.useState)(!0);b.default.locale(`es`),b.default.extend(x.default),(0,y.useEffect)(()=>{setTimeout(()=>{t(!1)},500)},[]);let[n,i]=(0,y.useState)(!1),[a,o]=(0,y.useState)(null),[c,d]=(0,y.useState)(null),[C,T]=(0,y.useState)(null),[E,D]=(0,y.useState)([]),O=()=>{try{g().then(e=>{let{data:t}=e;D(w(t))}).catch(e=>{})}catch{}};(0,y.useEffect)(()=>{n||O()},[n]);let k=e=>{d(`Entregar material vale`),o(e),i(!0)},A=e=>{d(`Cancelar vale`),o(e),i(!0),T(`lg`)},j=[{name:`ID`,selector:e=>e.id,omit:!0},{name:`FECHA`,selector:e=>e.fecha,sortable:!0,cell:e=>(0,S.jsx)(S.Fragment,{children:u(e.fecha)})},{name:`FOLIO`,selector:e=>e.folio,sortable:!0},{name:`MATERIAL SOLICITADO`,selector:e=>e.material,sortable:!0},{name:`AREA QUE SOLICITA`,selector:e=>e.area,sortable:!0},{name:`RECIBIÓ`,selector:e=>e.recibio,sortable:!0},{name:`AUTORIZÓ`,selector:e=>e.autorizo,sortable:!0},{name:`ENTREGÓ`,selector:e=>e.entrego,sortable:!0},{name:`STATUS`,selector:e=>e.estado,sortable:!0,cell:e=>{let t=e.estado;return(0,S.jsx)(f,{bg:t==`0`?`danger`:t==`1`?`warning`:`success`,children:t==`0`?`CANCELADO`:t==`1`?`PENDIENTE`:`ENTREGADO`})}},{name:`ACCIONES`,cell:e=>{let t=[e.id,e.fecha,e.folio,e.material,e.area,e.recibio,e.autorizo,e.entrego,e.estado];return e.estado==`1`?(0,S.jsxs)(r,{buttonColor:`minimal`,icon:`fas fa-ellipsis-v`,children:[(0,S.jsx)(r.Button,{onClick:()=>k((0,S.jsx)(v,{setShow:i,data:t})),icon:`fas fa-hand-holding`,color:`text-yellow-500`,children:`Entregar Material`}),(0,S.jsx)(r.Button,{onClick:()=>A((0,S.jsx)(_,{setShow:i,data:t})),icon:`fas fa-triangle-exclamation`,color:`text-yellow-500`,children:`Cancelar`})]}):`No disponibles`}}],[M,N]=(0,y.useState)(!1);return(0,S.jsxs)(S.Fragment,{children:[e&&(0,S.jsx)(l,{}),(0,S.jsx)(p,{title:`Lista de vales de material registrados`,datos:E,columnas:j}),(0,S.jsxs)(s,{show:n,onClose:()=>i(!1),maxWidth:`xl`,children:[(0,S.jsx)(s.Header,{closeButton:!0,onClose:()=>i(!1),children:c}),(0,S.jsx)(s.Body,{children:a})]})]})};function w(e){let t=[];return e.forEach(e=>{let n=e.material.map((e,t)=>`${e.cantidad}-${e.producto}`).join(`  ➡️  `);t.push({id:e._id,folio:e.folio,fecha:e.fecha,material:n,area:e.area,recibio:e.recibio,autorizo:e.autorizo,entrego:e.entrego,estado:e.estado})}),t}var T=`/assets/delay-D1PG5tM-.mp3`,E=()=>{let[e,t]=(0,y.useState)(!0),[n,r]=(0,y.useState)(),i=()=>{try{g().then(e=>{let{data:t}=e;r(D(t).length)}).catch(e=>{})}catch{}};(0,y.useEffect)(()=>{i()},[]);let[a,c]=(0,y.useState)(!1),[l,u]=(0,y.useState)(null),[f,p]=(0,y.useState)(null),[m,h]=(0,y.useState)(null),_=e=>{p(`Vales pendientes por atender`),u(e),c(!0)};return(0,y.useEffect)(()=>{let e=()=>{n>0&&new Audio(T).play()},t=setTimeout(()=>{e();let t=setInterval(e,900*1e3);return()=>clearInterval(t)},10*3e3);return()=>clearTimeout(t)},[n]),(0,S.jsxs)(`div`,{className:`floating-notification-container`,children:[(0,S.jsxs)(`button`,{className:`floating-notification-button `+(n===0?`btn-success`:`btn-danger`)+(n>0?` icon-move`:``),onClick:()=>_((0,S.jsx)(C,{setShow:c})),style:{fontSize:`26px`},children:[(0,S.jsx)(`span`,{children:(0,S.jsx)(o,{icon:d})}),e&&(0,S.jsxs)(`div`,{style:{fontSize:`14px`},className:`notification-popup`,children:[n,` vales registrados requieren atención`]})]}),(0,S.jsxs)(s,{show:a,onClose:()=>c(!1),maxWidth:`xl`,children:[(0,S.jsx)(s.Header,{closeButton:!0,onClose:()=>c(!1),children:f}),(0,S.jsx)(s.Body,{children:l})]})]})};function D(e){let t=[];return e.forEach(e=>{let n=e.material.map((e,t)=>`${e.cantidad}-${e.producto}`).join(`  ➡️  `);t.push({id:e._id,folio:e.folio,fecha:e.fecha,material:n,area:e.area,recibio:e.recibio,autorizo:e.autorizo,entrego:e.entrego,estado:e.estado})}),t}export{E as default};