import{i as e}from"./chunk-aKtaBQYM.js";import{Vt as t,wt as n}from"./mui-B6lh3XSP.js";import{d as r,l as i,t as a}from"./IconButton-BEBOUWhl.js";import{n as o}from"./MenuItem-HQNtf0LG.js";import{n as ee,r as s,t as c}from"./ReportFilter-DWQ_hjet.js";import{t as l}from"./TableHead-_KJlbpnj.js";import{At as u,Dt as d,F as f,O as p,Ot as m,ht as te,l as h,mt as g,s as _,w as v,wt as y,yt as b}from"./index-KVuxnkWj.js";import{t as x}from"./MapGeofence-Bl8PxdWQ.js";import{t as S}from"./MapPositions-DNSQ8WnZ.js";import{t as C}from"./MapScale-Bi_SBcLe.js";import{t as w}from"./SelectField-9K8NpSQG.js";import{t as T}from"./MapCamera-C0XDEMbg.js";import{t as E}from"./CollectionActions-CDxOJIb6.js";import{t as D}from"./MapRoutePath-CvdDI1fs.js";import{t as O}from"./MapRoutePoints-9xExrcqY.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";var I=e(t(),1),L=n(),R=()=>{let e=i(),{classes:t}=s(),n=b(),[R,z]=r(),B=h(n),V=p(`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=te(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 v(`/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=g(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=g(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)(f,{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)(u,{children:[(0,L.jsx)(l,{children:(0,L.jsxs)(y,{children:[(0,L.jsx)(d,{className:t.columnAction}),W.map(e=>(0,L.jsx)(d,{children:B[e]?.name||e},e)),(0,L.jsx)(d,{className:t.columnAction})]})}),(0,L.jsx)(m,{children:Y?(0,L.jsx)(j,{columns:W.length+1,startAction:!0}):K.slice(0,4e3).map(e=>(0,L.jsxs)(y,{children:[(0,L.jsx)(d,{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)(d,{children:(0,L.jsx)(_,{position:e,property:e.hasOwnProperty(t)?t:null,attribute:e.hasOwnProperty(t)?null:t})},t)),(0,L.jsx)(d,{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};