import{a as e}from"./chunk-BNv3lrIs.js";import{n as t,t as n}from"./jsx-runtime-pmtNMKr4.js";import{a as r,t as i}from"./auth-BMqSpi21.js";import{i as a}from"./usuarios-uLfQbCp9.js";import{n as o}from"./toast-hrvP3G3Q.js";import{t as s}from"./useMediaQuery-C_7KdS3g.js";import{t as c}from"./load-HIf6x4Qy.js";import{t as l}from"./dayjs.min-CvL7oEs_.js";import{t as u}from"./es-B8cbrmO0.js";import{t as d}from"./localizedFormat-CVLUt9Cf.js";import{A as f,Ar as p,Ci as m,Jr as h,Jt as g,Sr as _,Tr as v,Ui as y,Vi as b,Zr as x,li as S}from"./index-CBXvBSuP.js";import{t as C}from"./withRouter-BfV3B9Vo.js";import{t as w}from"./PageHeader-C3X_ZaAc.js";import{t as T}from"./DataTable-BuE1Zp8A.js";import{t as E}from"./useTheme-D5mB3Mad.js";import{i as D,r as O}from"./entregas-DWTBAUcv.js";import{n as k,t as A}from"./EliminarEntregas-B8Xk3ag8.js";import{t as j}from"./PagosOrdenesM-CFGt5gfS.js";import{t as M}from"./scanner_qr-DImHxhH9.js";var N=e(t(),1);y();var P=n();u();var F=e(l(),1),I=e(d(),1);function L(e){let{location:t,history:n}=e;F.default.locale(`es`),F.default.extend(I.default);let[l,u]=(0,N.useState)(!0),[d,y]=(0,N.useState)(``),[C,L]=(0,N.useState)(``),z=()=>{try{a(r(i())).then(e=>{let{data:t}=e;y(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(()=>{u(!1)},500)},[]);let[B,V]=(0,N.useState)([]),H=()=>{try{d==`administrador`?O().then(e=>{let{data:t}=e;V(R(t))}).catch(e=>{}):d==`mensajero`&&D(C).then(e=>{let{data:t}=e;V(R(t))}).catch(e=>{})}catch{}};(0,N.useEffect)(()=>{H()},[t,C]);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(d==`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 s(E().breakpoints.down(`sm`)),(0,P.jsxs)(P.Fragment,{children:[l&&(0,P.jsx)(c,{}),(0,P.jsx)(w,{title:`Entregas`,icon:p,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)(T,{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)(b,{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)(m,{children:[(0,P.jsx)(m.Toggle,{className:`botonDropdown`,id:`dropdown-basic`,children:(0,P.jsx)(S,{icon:g})}),(0,P.jsxs)(m.Menu,{children:[d==`administrador`&&(0,P.jsxs)(P.Fragment,{children:[(0,P.jsxs)(m.Item,{onClick:()=>Q((0,P.jsx)(k,{history:n,setShow:q,data:t})),children:[(0,P.jsx)(S,{icon:v,style:{color:`#ffc107`}}),`\xA0 Modificar`]}),(0,P.jsxs)(m.Item,{onClick:()=>$((0,P.jsx)(A,{history:n,setShow:q,data:t})),children:[(0,P.jsx)(S,{icon:h,style:{color:`#dc3545`}}),`\xA0 Eliminar`]})]}),d==`mensajero`&&(0,P.jsxs)(m.Item,{onClick:()=>Q((0,P.jsx)(k,{history:n,setShow:q,data:t})),children:[(0,P.jsx)(S,{icon:x,style:{color:`#ffc107`}}),`\xA0 Entregar`]})]})]}):(0,P.jsx)(P.Fragment,{children:d==`mensajero`?(0,P.jsxs)(m,{children:[(0,P.jsx)(m.Toggle,{className:`botonDropdown`,id:`dropdown-basic`,children:(0,P.jsx)(S,{icon:g})}),(0,P.jsx)(m.Menu,{children:(0,P.jsxs)(m.Item,{onClick:()=>ne((0,P.jsx)(j,{history:n,setShow:q,data:t,origen:`tablaEntregas`})),children:[(0,P.jsx)(S,{icon:_,style:{color:`#28a745`}}),`\xA0Recibir pago`]})})]}):`No disponibles`})}}]})}),(0,P.jsxs)(f,{show:K,onClose:()=>q(!1),maxWidth:`xl`,children:[(0,P.jsx)(f.Header,{closeButton:!0,onClose:()=>q(!1),children:X}),(0,P.jsx)(f.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=C(L);export{z as default};