import{i as e}from"./chunk-aKtaBQYM.js";import{Ft as t,vt as n}from"./mui-BgU4WrXF.js";import{d as r,l as i,t as a}from"./IconButton-oialqkv3.js";import{n as o}from"./MenuItem-BNgF7Xqv.js";import{n as ee,r as s,t as c}from"./ReportFilter-CtusU-vs.js";import{t as l}from"./TableHead-DZPVxfXH.js";import{A as u,St as d,ct as f,l as p,lt as m,pt as te,s as h,vt as g,w as _,wt as v,xt as y}from"./index-bel1r0Sr.js";import{t as b}from"./MapView-Bhqzv-Oc.js";import{t as x}from"./MapGeofence-B_elFORD.js";import{t as S}from"./MapPositions-DtWkadAy.js";import{t as C}from"./MapScale-BXKn6Q3F.js";import{t as w}from"./SelectField-Bcp-L6wk.js";import{t as T}from"./MapCamera-iXfOxITp.js";import{t as E}from"./CollectionActions-Be6ZPRyC.js";import{t as D}from"./MapRoutePath-DaJlD9QK.js";import{t as O}from"./MapRoutePoints-CUx_dHeJ.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";var I=e(t(),1),L=n(),R=()=>{let e=i(),{classes:t}=s(),n=te(),[R,z]=r(),B=p(n),V=u(`readonly`),[H,U]=(0,I.useState)([]),[W,G]=(0,I.useState)([`fixTime`,`latitude`,`longitude`,`speed`,`address`]),[K,q]=(0,I.useState)([]),J=R.has(`geofenceId`)?parseInt(R.get(`geofenceId`)):null,[Y,X]=(0,I.useState)(!1),[Z,Q]=(0,I.useState)(null),$=(0,I.useRef)();(0,I.useEffect)(()=>{$.current&&$.current.scrollIntoView({block:`center`,behavior:`smooth`})},[Z]);let ne=(0,I.useCallback)(e=>{Q(K.find(t=>t.id===e))},[K,Q]),re=m(async({deviceIds:e,from:t,to:n})=>{let r=new URLSearchParams({from:t,to:n});J&&r.append(`geofenceId`,J),e.forEach(e=>r.append(`deviceId`,e)),X(!0);try{let e=await(await _(`/api/positions?${r.toString()}`,{headers:{Accept:`application/json`}})).json(),t=new Set,n=[];e.forEach(e=>{Object.keys(e).forEach(e=>t.add(e)),Object.keys(e.attributes).forEach(e=>t.add(e))}),[`id`,`deviceId`,`outdated`,`network`,`attributes`].forEach(e=>t.delete(e)),Object.keys(B).forEach(e=>{t.has(e)&&(n.push(e),t.delete(e))}),U([...n,...t].map(e=>[e,B[e]?.name||e])),q(e)}finally{X(!1)}},[J,B]),ie=f(async({deviceIds:e,from:t,to:n,format:r})=>{let i=new URLSearchParams({from:t,to:n});J&&i.append(`geofenceId`,J),e.forEach(e=>i.append(`deviceId`,e)),window.location.assign(`/api/positions/${r}?${i.toString()}`)}),ae=f(async(t,n,r)=>{r.type=`route`,await F(t,n,r),e(`/reports/scheduled`)});return(0,L.jsx)(o,{menu:(0,L.jsx)(k,{}),breadcrumbs:[`reportTitle`,`reportPositions`],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)(b,{children:[(0,L.jsx)(x,{}),[...new Set(K.map(e=>e.deviceId))].map(e=>{let t=K.filter(t=>t.deviceId===e);return(0,L.jsxs)(I.Fragment,{children:[(0,L.jsx)(D,{positions:t}),(0,L.jsx)(O,{positions:t,onClick:ne})]},e)}),(0,L.jsx)(S,{positions:[Z],titleField:`fixTime`})]}),(0,L.jsx)(C,{}),(0,L.jsx)(T,{positions:K})]}),(0,L.jsx)(M,{})]}),(0,L.jsxs)(`div`,{className:t.containerMain,children:[(0,L.jsx)(`div`,{className:t.header,children:(0,L.jsxs)(c,{onShow:re,onExport:ie,onSchedule:ae,deviceType:`single`,loading:Y,formats:[`csv`,`gpx`,`kml`,`kmz`],children:[(0,L.jsx)(`div`,{className:t.filterItem,children:(0,L.jsx)(w,{value:J,onChange:e=>{ee(R,z,`geofenceId`,e.target.value?[e.target.value]:[])},endpoint:`/api/geofences`,label:n(`sharedGeofence`),fullWidth:!0})}),(0,L.jsx)(A,{columns:W,setColumns:G,columnsArray:H,rawValues:!0,disabled:!K.length})]})}),(0,L.jsxs)(v,{children:[(0,L.jsx)(l,{children:(0,L.jsxs)(g,{children:[(0,L.jsx)(y,{className:t.columnAction}),W.map(e=>(0,L.jsx)(y,{children:B[e]?.name||e},e)),(0,L.jsx)(y,{className:t.columnAction})]})}),(0,L.jsx)(d,{children:Y?(0,L.jsx)(j,{columns:W.length+1,startAction:!0}):K.slice(0,4e3).map(e=>(0,L.jsxs)(g,{children:[(0,L.jsx)(y,{className:t.columnAction,padding:`none`,children:Z===e?(0,L.jsx)(a,{size:`small`,onClick:()=>Q(null),ref:$,children:(0,L.jsx)(N,{fontSize:`small`})}):(0,L.jsx)(a,{size:`small`,onClick:()=>Q(e),children:(0,L.jsx)(P,{fontSize:`small`})})}),W.map(t=>(0,L.jsx)(y,{children:(0,L.jsx)(h,{position:e,property:e.hasOwnProperty(t)?t:null,attribute:e.hasOwnProperty(t)?null:t})},t)),(0,L.jsx)(y,{className:t.actionCellPadding,children:(0,L.jsx)(E,{itemId:e.id,endpoint:`positions`,readonly:V,onReload:()=>{q(K.filter(t=>t.id!==e.id))}})})]},e.id))})]})]})]})})};export{R as default};