import{a as e}from"./chunk-BNv3lrIs.js";import{n as t,t as n}from"./jsx-runtime-pmtNMKr4.js";import{t as r}from"./DropdownActions-DPd7qitt.js";import{t as i}from"./useMediaQuery-C_7KdS3g.js";import{t as a}from"./load-HIf6x4Qy.js";import{t as o}from"./dayjs.min-CvL7oEs_.js";import{t as s}from"./es-B8cbrmO0.js";import{t as c}from"./localizedFormat-CVLUt9Cf.js";import{A as l,Vi as u,Yt as d,b as f,li as p}from"./index-CBXvBSuP.js";import{t as m}from"./DataTable-BuE1Zp8A.js";import{t as h}from"./useTheme-D5mB3Mad.js";import{a as g,t as _}from"./CancelarVale-xzF4SSSB.js";import{t as v}from"./EntregarMaterialVale-B1Y4ODkV.js";var y=e(t(),1);s();var b=e(o(),1),x=e(c(),1),S=n(),C=()=>{i(h().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,o]=(0,y.useState)(!1),[s,c]=(0,y.useState)(null),[d,p]=(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=>{p(`Entregar material vale`),c(e),o(!0)},A=e=>{p(`Cancelar vale`),c(e),o(!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:f(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)(u,{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:o,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:o,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)(a,{}),(0,S.jsx)(m,{title:`Lista de vales de material registrados`,datos:E,columnas:j}),(0,S.jsxs)(l,{show:n,onClose:()=>o(!1),maxWidth:`xl`,children:[(0,S.jsx)(l.Header,{closeButton:!0,onClose:()=>o(!1),children:d}),(0,S.jsx)(l.Body,{children:s})]})]})};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,o]=(0,y.useState)(!1),[s,c]=(0,y.useState)(null),[u,f]=(0,y.useState)(null),[m,h]=(0,y.useState)(null),_=e=>{f(`Vales pendientes por atender`),c(e),o(!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:o})),style:{fontSize:`26px`},children:[(0,S.jsx)(`span`,{children:(0,S.jsx)(p,{icon:d})}),e&&(0,S.jsxs)(`div`,{style:{fontSize:`14px`},className:`notification-popup`,children:[n,` vales registrados requieren atención`]})]}),(0,S.jsxs)(l,{show:a,onClose:()=>o(!1),maxWidth:`xl`,children:[(0,S.jsx)(l.Header,{closeButton:!0,onClose:()=>o(!1),children:u}),(0,S.jsx)(l.Body,{children:s})]})]})};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};