import{i as e}from"./chunk-aKtaBQYM.js";import{Ft as t,G as n,Nt as r,vt as i}from"./mui-BgU4WrXF.js";import{l as a,t as o}from"./IconButton-oialqkv3.js";import{n as s}from"./MenuItem-BNgF7Xqv.js";import{r as c,t as ee}from"./ReportFilter-CtusU-vs.js";import{t as l}from"./TableHead-DZPVxfXH.js";import{B as u,E as d,K as f,R as p,St as m,T as h,U as g,c as _,ct as v,gt as te,lt as ne,pt as re,q as ie,vt as y,w as b,wt as x,xt as S}from"./index-bel1r0Sr.js";import{t as C}from"./MapView-Bhqzv-Oc.js";import{t as w}from"./MapGeofence-B_elFORD.js";import{t as T}from"./MapPositions-DtWkadAy.js";import{t as E}from"./MapScale-BXKn6Q3F.js";import{t as D}from"./deviceEquality-4aERFrOn.js";import{t as O}from"./MapCamera-iXfOxITp.js";import{t as k}from"./ReportsMenu-CwjT__h7.js";import{t as A}from"./ColumnSelect-CwYQdTe9.js";import{t as j}from"./TableShimmer-CBuxG-nx.js";import{t as M}from"./ResizeHandle-Bls_OI9_.js";import{n as N,t as P}from"./LocationSearching-BHZqls-X.js";import{t as F}from"./scheduleReport-DKXQL3XB.js";import{t as ae}from"./exportExcel-DStci2wm.js";var I=e(t(),1),L=i(),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}=c(),i=re(),B=n(),V=r(e=>e.devices.items,D([`id`,`name`])),H=h(`distanceUnit`),U=h(`volumeUnit`),W=d(`coordinateFormat`),[G,K]=te(`stopColumns`,[`startTime`,`endTime`,`startOdometer`,`address`]),[q,J]=(0,I.useState)([]),[Y,X]=(0,I.useState)(!1),[Z,Q]=(0,I.useState)(null),oe=ne(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=v(async()=>{let e=new Map;q.forEach(t=>{let n=V[t.deviceId].name;e.has(n)||e.set(n,[]);let r={};G.forEach(e=>{let n=i(z.get(e));e===`address`?r[n]=p(t,W):r[n]=$(t,e)}),e.get(n).push(r)}),await ae(i(`reportStops`),`stops.xlsx`,e,B)}),ce=v(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 f(n,`minutes`);case`startOdometer`:return u(n,H,i);case`duration`:return g(n,i);case`engineHours`:return n>0?g(n,i):null;case`spentFuel`:return n>0?ie(n,U,i):null;case`address`:return(0,L.jsx)(_,{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)(C,{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)(ee,{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)(x,{children:[(0,L.jsx)(l,{children:(0,L.jsxs)(y,{children:[(0,L.jsx)(S,{className:t.columnAction}),(0,L.jsx)(S,{children:i(`sharedDevice`)}),G.map(e=>(0,L.jsx)(S,{children:i(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)(y,{children:[(0,L.jsx)(S,{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)(S,{children:V[e.deviceId].name}),G.map(t=>(0,L.jsx)(S,{children:$(e,t)},t))]},e.positionId))})]})]})]})})};export{B as default};