import{i as e}from"./chunk-aKtaBQYM.js";import{Ft as t,G as n,t as r,vt as i}from"./mui-BgU4WrXF.js";import{N as a,T as o,pt as s,rt as c,tt as l}from"./index-bel1r0Sr.js";import{n as u}from"./MapView-Bhqzv-Oc.js";import{n as d,r as f}from"./MapRoutePath-DaJlD9QK.js";var p=e(t(),1),m=Array.from({length:10},(e,t)=>{let[n,r,i]=f(t/9);return`rgb(${n}, ${r}, ${i})`}).join(`, `),h=r()(()=>({colorBar:{background:`linear-gradient(to right, ${m})`,height:10}})),g=({positions:e})=>{let t=n(),r=s(),i=o(`speedUnit`),{classes:a}=h();return(0,p.useEffect)(()=>{if(!e.length)return;let n=e.reduce((e,t)=>Math.max(e,t.speed),-1/0),o=e.reduce((e,t)=>Math.min(e,t.speed),1/0);if(!n)return;let s,d={onAdd:()=>{s=document.createElement(`div`),s.className=`maplibregl-ctrl maplibregl-ctrl-scale`;let e=document.createElement(`div`);e.className=a.colorBar;let t=document.createElement(`span`);return t.textContent=`${Math.round(l(o,i))} - ${Math.round(l(n,i))} ${c(i,r)}`,s.appendChild(e),s.appendChild(t),s},onRemove:()=>s?.remove()};return u.addControl(d,t.direction===`rtl`?`bottom-right`:`bottom-left`),()=>u.removeControl(d)},[e,i,r,t.direction,a.colorBar]),null},_=i(),v=({positions:e,onClick:t,showSpeedControl:n})=>{let r=(0,p.useId)(),i=()=>u.getCanvas().style.cursor=`pointer`,o=()=>u.getCanvas().style.cursor=``,s=(0,p.useCallback)(e=>{e.preventDefault();let n=e.features[0];t&&t(n.properties.id,n.properties.index)},[t]);return(0,p.useEffect)(()=>(u.addSource(r,{type:`geojson`,data:{type:`FeatureCollection`,features:[]}}),u.addLayer({id:r,type:`symbol`,source:r,paint:{"text-color":[`get`,`color`]},layout:{"text-font":a(u),"text-size":12,"text-field":`▲`,"text-allow-overlap":!0,"text-rotate":[`get`,`rotation`]}}),u.on(`mouseenter`,r,i),u.on(`mouseleave`,r,o),u.on(`click`,r,s),()=>{u.off(`mouseenter`,r,i),u.off(`mouseleave`,r,o),u.off(`click`,r,s),u.getLayer(r)&&u.removeLayer(r),u.getSource(r)&&u.removeSource(r)}),[s,r]),(0,p.useEffect)(()=>{let t=e.reduce((e,t)=>Math.max(e,t.speed),-1/0),n=e.reduce((e,t)=>Math.min(e,t.speed),1/0);u.getSource(r)?.setData({type:`FeatureCollection`,features:e.map((e,r)=>({type:`Feature`,geometry:{type:`Point`,coordinates:[e.longitude,e.latitude]},properties:{index:r,id:e.id,rotation:e.course,color:d(e.speed,n,t)}}))})},[e,r]),n?(0,_.jsx)(g,{positions:e}):null};export{v as t};