import{i as e}from"./chunk-aKtaBQYM.js";import{Vt as t,Y as n,t as r,wt as i}from"./mui-B6lh3XSP.js";import{A as a,I as o,P as s,R as c,lt as l,st as u,yt as d}from"./index-KVuxnkWj.js";import{n as f,r as p}from"./MapRoutePath-CvdDI1fs.js";var m=e(t(),1),h=Array.from({length:10},(e,t)=>{let[n,r,i]=p(t/9);return`rgb(${n}, ${r}, ${i})`}).join(`, `),g=r()(()=>({colorBar:{background:`linear-gradient(to right, ${h})`,height:10}})),_=({positions:e})=>{let t=n(),r=d(),i=c(`speedUnit`),{classes:a}=g();return(0,m.useEffect)(()=>{if(!e.length)return;let n=e.reduce((e,t)=>Math.max(e,t.speed),-1/0),s=e.reduce((e,t)=>Math.min(e,t.speed),1/0);if(!n)return;let c,d={onAdd:()=>{c=document.createElement(`div`),c.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(u(s,i))} - ${Math.round(u(n,i))} ${l(i,r)}`,c.appendChild(e),c.appendChild(t),c},onRemove:()=>c?.remove()};return o.addControl(d,t.direction===`rtl`?`bottom-right`:`bottom-left`),()=>o.removeControl(d)},[e,i,r,t.direction,a.colorBar]),null},v=i(),y=({positions:e,onClick:t,showSpeedControl:n})=>{let r=(0,m.useId)(),i=()=>o.getCanvas().style.cursor=`pointer`,c=()=>o.getCanvas().style.cursor=``,l=(0,m.useCallback)(e=>{e.preventDefault();let n=e.features[0];t&&t(n.properties.id,n.properties.index)},[t]);return(0,m.useEffect)(()=>(o.addSource(r,{type:`geojson`,data:{type:`FeatureCollection`,features:[]}}),o.addLayer({id:r,type:`symbol`,source:r,paint:{"text-color":[`get`,`color`]},layout:{"text-font":a(o),"text-size":12,"text-field":`▲`,"text-allow-overlap":!0,"text-rotate":[`get`,`rotation`]}}),o.on(`mouseenter`,r,i),o.on(`mouseleave`,r,c),o.on(`click`,r,l),()=>{o.off(`mouseenter`,r,i),o.off(`mouseleave`,r,c),o.off(`click`,r,l),o.getLayer(r)&&o.removeLayer(r),o.getSource(r)&&o.removeSource(r)}),[l,r]),(0,m.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);o.getSource(r)?.setData({type:`FeatureCollection`,features:e.map((e,r)=>({type:`Feature`,geometry:{type:`Point`,coordinates:s(e.longitude,e.latitude)},properties:{index:r,id:e.id,rotation:e.course,color:f(e.speed,n,t)}}))})},[e,r]),n?(0,v.jsx)(_,{positions:e}):null};export{y as t};