import{i as e}from"./chunk-aKtaBQYM.js";import{Vt as t,Y as n,wt as r,zt as i}from"./mui-B6lh3XSP.js";import{l as a,t as o}from"./IconButton-BEBOUWhl.js";import{n as s}from"./MenuItem-HQNtf0LG.js";import{r as ee,t as te}from"./ReportFilter-DWQ_hjet.js";import{t as c}from"./TableHead-_KJlbpnj.js";import{$ as l,At as u,Dt as d,F as f,K as p,Ot as m,Q as h,R as g,St as _,W as ne,Y as v,c as re,ht as ie,mt as y,w as b,wt as x,yt as S,z as C}from"./index-KVuxnkWj.js";import{t as w}from"./MapGeofence-Bl8PxdWQ.js";import{t as T}from"./MapPositions-DNSQ8WnZ.js";import{t as E}from"./MapScale-Bi_SBcLe.js";import{t as D}from"./deviceEquality-4aERFrOn.js";import{t as O}from"./MapCamera-C0XDEMbg.js";import{t as k}from"./ReportsMenu-XWwKkI0p.js";import{t as A}from"./ColumnSelect-BAx72xpb.js";import{t as j}from"./TableShimmer-f7Cf4NTV.js";import{t as M}from"./ResizeHandle-Be-cOoy0.js";import{n as N,t as P}from"./LocationSearching-YHal0jIA.js";import{t as F}from"./scheduleReport-DHCgjQvQ.js";import{t as ae}from"./exportExcel-D5CrW9S1.js";var I=e(t(),1),L=r(),R=[[`startTime`,`reportStartTime`],[`startOdometer`,`positionOdometer`],[`address`,`positionAddress`],[`endTime`,`reportEndTime`],[`duration`,`reportDuration`],[`engineHours`,`reportEngineHours`],[`spentFuel`,`reportSpentFuel`]],z=new Map(R),B=()=>{let e=a(),{classes:t}=ee(),r=S(),B=n(),V=i(e=>e.devices.items,D([`id`,`name`])),H=g(`distanceUnit`),U=g(`volumeUnit`),W=C(`coordinateFormat`),[G,K]=_(`stopColumns`,[`startTime`,`endTime`,`startOdometer`,`address`]),[q,J]=(0,I.useState)([]),[Y,X]=(0,I.useState)(!1),[Z,Q]=(0,I.useState)(null),oe=ie(async({deviceIds:e,groupIds:t,from:n,to:r})=>{let i=new URLSearchParams({from:n,to:r});e.forEach(e=>i.append(`deviceId`,e)),t.forEach(e=>i.append(`groupId`,e)),X(!0);try{J(await(await b(`/api/reports/stops?${i.toString()}`,{headers:{Accept:`application/json`}})).json())}finally{X(!1)}},[]),se=y(async()=>{let e=new Map;q.forEach(t=>{let n=V[t.deviceId].name;e.has(n)||e.set(n,[]);let i={};G.forEach(e=>{let n=r(z.get(e));e===`address`?i[n]=ne(t,W):i[n]=$(t,e)}),e.get(n).push(i)}),await ae(r(`reportStops`),`stops.xlsx`,e,B)}),ce=y(async(t,n,r)=>{r.type=`stops`,await F(t,n,r),e(`/reports/scheduled`)}),$=(e,t)=>{let n=e[t];switch(t){case`deviceId`:return V[n].name;case`startTime`:case`endTime`:return h(n,`minutes`);case`startOdometer`:return p(n,H,r);case`duration`:return v(n,r);case`engineHours`:return n>0?v(n,r):null;case`spentFuel`:return n>0?l(n,U,r):null;case`address`:return(0,L.jsx)(re,{latitude:e.latitude,longitude:e.longitude,originalAddress:n});default:return n}};return(0,L.jsx)(s,{menu:(0,L.jsx)(k,{}),breadcrumbs:[`reportTitle`,`reportStops`],children:(0,L.jsxs)(`div`,{className:t.container,children:[Z&&(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(`div`,{className:t.containerMap,children:[(0,L.jsxs)(f,{children:[(0,L.jsx)(w,{}),(0,L.jsx)(T,{positions:[{deviceId:Z.deviceId,fixTime:Z.startTime,latitude:Z.latitude,longitude:Z.longitude}],titleField:`fixTime`})]}),(0,L.jsx)(E,{}),(0,L.jsx)(O,{latitude:Z.latitude,longitude:Z.longitude})]}),(0,L.jsx)(M,{})]}),(0,L.jsxs)(`div`,{className:t.containerMain,children:[(0,L.jsx)(`div`,{className:t.header,children:(0,L.jsx)(te,{onShow:oe,onExport:se,onSchedule:ce,deviceType:`multiple`,loading:Y,formats:[`xlsx`],children:(0,L.jsx)(A,{columns:G,setColumns:K,columnsArray:R})})}),(0,L.jsxs)(u,{children:[(0,L.jsx)(c,{children:(0,L.jsxs)(x,{children:[(0,L.jsx)(d,{className:t.columnAction}),(0,L.jsx)(d,{children:r(`sharedDevice`)}),G.map(e=>(0,L.jsx)(d,{children:r(z.get(e))},e))]})}),(0,L.jsx)(m,{children:Y?(0,L.jsx)(j,{columns:G.length+2,startAction:!0}):q.map(e=>(0,L.jsxs)(x,{children:[(0,L.jsx)(d,{className:t.columnAction,padding:`none`,children:Z===e?(0,L.jsx)(o,{size:`small`,onClick:()=>Q(null),children:(0,L.jsx)(N,{fontSize:`small`})}):(0,L.jsx)(o,{size:`small`,onClick:()=>Q(e),children:(0,L.jsx)(P,{fontSize:`small`})})}),(0,L.jsx)(d,{children:V[e.deviceId].name}),G.map(t=>(0,L.jsx)(d,{children:$(e,t)},t))]},e.positionId))})]})]})]})})};export{B as default};