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"./dayjs.min-aszMaMjE.js";import{Bi as i,C as a,Da as o,Ei as s,G as c,Hr as l,Ia as u,La as d,Ma as f,Ra as p,S as m,W as h,di as g,dn as _,ha as v,mi as y,qr as b,zr as x}from"./index-DccLTdzK.js";import{t as S}from"./withRouter-CRkgdzqj.js";import{t as C}from"./PageHeader-DNnlanBD.js";import{t as w}from"./DataTable-KLBE0uXO.js";import{t as T}from"./useTheme-ClV7RdEj.js";import{t as E}from"./useMediaQuery-Diq4jKog.js";import{i as D,r as O}from"./entregas-0yKv1ffW.js";import{n as k,t as A}from"./EliminarEntregas-BvTA0zxf.js";import{t as j}from"./PagosOrdenesM-xkUWKFcp.js";import{t as M}from"./scanner_qr-BeJWa-Ds.js";var N=e(t(),1);p();var P=n();a();var F=e(r(),1),I=e(m(),1);function L(e){let{location:t,history:n}=e;F.default.locale(`es`),F.default.extend(I.default);let[r,a]=(0,N.useState)(!0),[p,m]=(0,N.useState)(``),[S,L]=(0,N.useState)(``),z=()=>{try{f(d(u())).then(e=>{let{data:t}=e;m(t.tipo),L(t.email)}).catch(e=>{e.message===`Network Error`&&o.error(`Conexión al servidor no disponible`)})}catch(e){console.log(e)}};(0,N.useEffect)(()=>{z()},[]),(0,N.useEffect)(()=>{setTimeout(()=>{a(!1)},500)},[]);let[B,V]=(0,N.useState)([]),H=()=>{try{p==`administrador`?O().then(e=>{let{data:t}=e;V(R(t))}).catch(e=>{}):p==`mensajero`&&D(S).then(e=>{let{data:t}=e;V(R(t))}).catch(e=>{})}catch{}};(0,N.useEffect)(()=>{H()},[t,S]);let[ee,U]=(0,N.useState)(!0),[te,W]=(0,N.useState)([]),G=()=>{let e=setTimeout(()=>{W(B),U(!1)},0);return()=>clearTimeout(e)};(0,N.useEffect)(()=>{G()},[]);let[K,q]=(0,N.useState)(!1),[J,Y]=(0,N.useState)(null),[X,Z]=(0,N.useState)(null),Q=e=>{Z(p==`mensajero`?`Realizar entrega`:`Modificar entrega`),Y(e),q(!0)},$=e=>{Z(`Eliminar entrega`),Y(e),q(!0)},ne=e=>{Z(`Pago de orden de cliente`),Y(e),q(!0)},re=e=>{Z(`Escanear QR`),Y(e),q(!0)};return E(T().breakpoints.down(`sm`)),(0,P.jsxs)(P.Fragment,{children:[r&&(0,P.jsx)(h,{}),(0,P.jsx)(C,{title:`Entregas`,icon:b,onAddClick:()=>re((0,P.jsx)(M,{history:n,setShow:q})),addText:`Escanear QR`}),(0,P.jsx)(`div`,{className:`divTabla`,style:{textTransform:`capitalize`},children:(0,P.jsx)(w,{title:`Lista de entregas registradas`,datos:B,columnas:[{name:`ID`,selector:e=>e.id,omit:!0},{name:`FOLIO`,selector:e=>e.folio,sortable:!0},{name:`MENSAJERO`,selector:e=>e.mensajero,sortable:!0},{name:`ORDEN DE TRABAJO`,selector:e=>e.ordenTrabajo,sortable:!0},{name:`FECHA DE ENTREGA`,selector:e=>e.fechaEntrega,sortable:!0},{name:`UBICACIÓN DE ENTREGA`,selector:e=>e.ubicacion,sortable:!0},{name:`MOTIVO DE ENTREGA`,selector:e=>e.motivoEntrega,sortable:!0},{name:`COMENTARIOS`,selector:e=>e.comentarios,sortable:!0},{name:`STATUS`,selector:e=>e.estado,sortable:!0,cell:e=>{let t=e.estado;return(0,P.jsx)(v,{bg:t==`0`?`warning`:t==`1`?`success`:`danger`,children:t==`0`?`Listo para entrega`:`Entregado`})}},{name:`TIPO`,selector:e=>e.tipo,sortable:!0},{name:`ACCIONES`,cell:e=>{let t=[e.id,e.folio,e.mensajero,e.ordenTrabajo,e.fechaEntrega,e.ubicacion,e.motivoEntrega,e.comentarios,e.estado,e.tipo];return e.estado==`0`?(0,P.jsxs)(i,{children:[(0,P.jsx)(i.Toggle,{className:`botonDropdown`,id:`dropdown-basic`,children:(0,P.jsx)(s,{icon:_})}),(0,P.jsxs)(i.Menu,{children:[p==`administrador`&&(0,P.jsxs)(P.Fragment,{children:[(0,P.jsxs)(i.Item,{onClick:()=>Q((0,P.jsx)(k,{history:n,setShow:q,data:t})),children:[(0,P.jsx)(s,{icon:l,style:{color:`#ffc107`}}),`\xA0 Modificar`]}),(0,P.jsxs)(i.Item,{onClick:()=>$((0,P.jsx)(A,{history:n,setShow:q,data:t})),children:[(0,P.jsx)(s,{icon:g,style:{color:`#dc3545`}}),`\xA0 Eliminar`]})]}),p==`mensajero`&&(0,P.jsxs)(i.Item,{onClick:()=>Q((0,P.jsx)(k,{history:n,setShow:q,data:t})),children:[(0,P.jsx)(s,{icon:y,style:{color:`#ffc107`}}),`\xA0 Entregar`]})]})]}):(0,P.jsx)(P.Fragment,{children:p==`mensajero`?(0,P.jsxs)(i,{children:[(0,P.jsx)(i.Toggle,{className:`botonDropdown`,id:`dropdown-basic`,children:(0,P.jsx)(s,{icon:_})}),(0,P.jsx)(i.Menu,{children:(0,P.jsxs)(i.Item,{onClick:()=>ne((0,P.jsx)(j,{history:n,setShow:q,data:t,origen:`tablaEntregas`})),children:[(0,P.jsx)(s,{icon:x,style:{color:`#28a745`}}),`\xA0Recibir pago`]})})]}):`No disponibles`})}}]})}),(0,P.jsxs)(c,{show:K,onClose:()=>q(!1),maxWidth:`xl`,children:[(0,P.jsx)(c.Header,{closeButton:!0,onClose:()=>q(!1),children:X}),(0,P.jsx)(c.Body,{children:J})]})]})}function R(e){let t=[];return e.forEach(e=>{t.push({id:e._id,folio:e.folio,mensajero:e.mensajero,fechaEntrega:e.fechayHoraEntrega,ubicacion:e.ubicacion,ordenTrabajo:e.ordenTrabajo,motivoEntrega:e.motivoEntrega,comentarios:e.comentarios,tipo:e.tipo?e.tipo:`No disponible`,estado:e.estado})}),t}var z=S(L);export{z as default};