agvmap-react 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agvmap-react.js +138 -140
- package/dist/agvmap-react.umd.cjs +1 -1
- package/package.json +1 -1
|
@@ -1016,6 +1016,6 @@ function evaluatePixel(samples) {
|
|
|
1016
1016
|
// Return color values with full opacity
|
|
1017
1017
|
return imgVals.concat([1]); // RGBA: fully opaque
|
|
1018
1018
|
}
|
|
1019
|
-
}`,$S={},GS={};async function bEe(e,{weeksBefore:t=0,accessToken:r,dateRange:n}){if(console.log("downloading cropped ndvi",n),!r)return console.error("No access token provided"),null;let i=new Date(n.start.setHours(0,0,1)).toISOString(),s=new Date(n.end.setHours(23,59,59)).toISOString();const c=`${e.properties.id}-${i}`;if(console.log("crop cacheKey",c),$S[c])return console.log("NDVI data found in cache"),$S[c];if(console.log("access Token",r),!mK(Mf(e)))throw new Error("Invalid BBOX");const d="https://services.sentinel-hub.com/api/v1/process",p={input:{bounds:{geometry:{type:"Polygon",coordinates:e.geometry.coordinates},properties:{crs:"http://www.opengis.net/def/crs/EPSG/0/4326"}},data:[{type:"sentinel-2-l2a",dataFilter:{timeRange:{from:i,to:s}}}]},output:{width:512,height:512,responses:[{identifier:"default",format:{type:"image/png"}}]},evalscript:vEe};try{const y=await fetch(d,{method:"POST",headers:{Authorization:`Bearer ${r}`,"Content-Type":"application/json"},body:JSON.stringify(p)});if(!y.ok)throw new Error("Failed to fetch NDVI data");const g=await y.blob();if(!g)return null;const v=URL.createObjectURL(g);return $S[c]=v,v}catch(y){return console.error("Error fetching NDVI data:",y),null}}async function xEe(e,t){console.log("downloading cropped et",t);let r,n;r=t.start.toISOString().split("T")[0],n=t.end.toISOString().split("T")[0];const i=`${r}/${n}`,s=Mf(e);if(!s)throw new Error("Invalid BBOX");const c=`${e.properties.id}-${r}`;if(console.log("crop cacheKey",c),GS[c])return console.log("ET data found in cache"),GS[c];const a=s.join(","),d="https://d27s6pvwcjpmsu.cloudfront.net/geoserver/ne/wms?"+new URLSearchParams({service:"WMS",version:"1.1.0",request:"GetMap",layers:"ne:et_data",styles:"",bbox:a,width:512,height:512,srs:"EPSG:4326",format:"image/png",transparent:"true",TIME:i});try{const p=await fetch(d);if(!p.ok)throw new Error("Failed to fetch cropped NDVI from GeoServer");const y=await p.blob();if(!y)return null;const g=URL.createObjectURL(y);return GS[c]=g,g}catch(p){return console.error("Error fetching cropped NDVI:",p),null}}async function _Ee(e,t){return new Promise(r=>{const n=new Image;n.onload=function(){const i=document.createElement("canvas"),s=i.getContext("2d");i.width=n.width,i.height=n.height,s.drawImage(n,0,0,n.width,n.height);const c=t.geometry.coordinates[0].map(([a,d])=>wEe(a,d,Mf(t),n.width,n.height));s.globalCompositeOperation="destination-in",s.beginPath(),c.forEach(([a,d],p)=>{p===0?s.moveTo(a,d):s.lineTo(a,d)}),s.closePath(),s.fill(),r(i.toDataURL("image/png"))},n.src=e})}function wEe(e,t,r,n,i){const[s,c,a,d]=r,p=(e-s)/(a-s)*n,y=i-(t-c)/(d-c)*i;return[p,y]}async function SEe(e,{rasterLayer:t,dateRange:r,accessToken:n,map:i}){if(console.log("getCroppedRaster rasterLayer",t,r),!(r!=null&&r.start)instanceof Date||!(r!=null&&r.end)instanceof Date){console.error("DateRange is not of type Date");return}if(t==="ET"||(t==null?void 0:t.value)==="ET"){const s=await xEe(e,r);if(!s)return null;const c=await _Ee(s,e);return console.log("croppedImageURl",c),c?(console.log("crop getCroppedRaster crop image URL",s),c):null}else if(t==="3_NDVI"||(t==null?void 0:t.value)==="3_NDVI")return await bEe(e,{accessToken:n,dateRange:r})}function qR({mapRef:e,dateRange:t}){var K;const{plots:r,showPlots:n,clickedPlot:i,setClickedPlot:s}=U.useContext($o),c=$t(Q=>Q.showCroppedImages),a=$t(Q=>Q.datesLoading),d=$t(Q=>Q.mapMode),p=$t(Q=>Q.rasterLayer),{isVisible:y,setIsVisible:g}=U.useContext(Hf),{settings:v}=U.useContext(of),w=$t(Q=>Q.setCursor),S=$t(Q=>Q.resetCursor),{drawRef:C}=U.useContext(zi),M=U.useContext(Ry),I=(K=e==null?void 0:e.current)==null?void 0:K.getMap(),E=$t(Q=>Q.viewMode),O=$t(Q=>Q.addLoadingNDVIImage),N=$t(Q=>Q.removeLoadingNDVIImage),D=$t(Q=>Q.isNDVIImageLoading);$t(Q=>Q.setShowCroppedImages);const L=U.useCallback((Q,ae,{map:J})=>{if(console.log("eeeeee croppp adding image to map",Q,ae,J),!J)throw new Error("map is not defined");if(!c||!y)return console.log("showCroppedImages is off",c),null;if(console.log("plotss",ae),!ae||!ae.geometry||ae.geometry.type!=="Polygon")return null;const[pe,xe,se,ge]=Mf(ae.geometry),Se=[[pe,ge],[se,ge],[se,xe],[pe,xe]],Ee=`croppedImageSource-${ae.properties.id}`,$e=`croppedImageLayer-${ae.properties.id}`;J.getLayer($e)&&J.removeLayer($e),J.getSource(Ee)&&J.removeSource(Ee),console.log("adding the cropped raster to map"),console.log("adding source"),J.addSource(Ee,{type:"image",url:Q,coordinates:Se});let le=J.getLayer("plots-line-layer")?"plots-line-layer":void 0;console.log("cropped beforeId",le),console.log("adding layer"),J.addLayer({id:$e,type:"raster",source:Ee,paint:{"raster-opacity":1}},le);const ne=J.getPitch();J.setPitch(ne+.01),console.log("croppp layer order",J.getLayersOrder())},[c]),R=U.useCallback(async(Q,{accessToken:ae,map:J,timeTravel:pe,dateRange:xe,isVisible:se,showCroppedImages:ge})=>{if(console.log("handleCroppedImageDownload started"),console.log("crop download plot",Q),!J)throw new Error("map is not defined");const Se=`croppedImageLayer-${Q.properties.id}`;if(console.log("crop visible, showCropped",se,ge),!se||!ge){console.log("crop either isVisible or not plot mode selected, deleting layer and returning"),J.getLayer(Se)&&J.removeLayer(Se);return}if(J.getLayer(Se))if(pe)console.log("only time travel"),J.removeLayer(Se);else{console.log("NDVI layer already added for this plot",Se);return}try{if(D(Q.properties.id))return;O(Q.properties.id);const Ee=await SEe(Q,{rasterLayer:p,dateRange:xe,accessToken:ae});if(console.log("ndvi URL",Ee),!Q)throw new Error("plot is not defined");console.log("mapp",J),Ee&&(console.log(),L(Ee,Q,{map:J}))}catch(Ee){console.log("error in loading ndvi layer",Ee)}finally{N(Q.properties.id)}},[p,M,D,O,L,N]),Y={id:"plots-line-layer",type:"line",paint:{"line-color":"#e31717","line-width":2}},ie={id:"plots-layer",type:"fill",paint:{"fill-color":"#e31717","fill-opacity":0}},re=U.useCallback(()=>{var J;const Q=(J=C==null?void 0:C.current)==null?void 0:J.getAll();return((Q==null?void 0:Q.features)||[]).length>0},[C]),V=U.useCallback(Q=>{if(re()){console.log("no popup info"),s(null);return}const ae=I.queryRenderedFeatures(Q.point,{layers:["plots-layer"]});if(ae.length>0){const J=ae[0];console.log("clickedPlot",J),s({lngLat:Q.lngLat,plot:J})}else s(null)},[re,I,s]),Z=U.useCallback(()=>{w("pointer")},[w,I]),W=U.useCallback(()=>{S()},[w,I]),B=U.useCallback((Q,ae)=>{const[J,pe,xe,se]=Q,[[ge,Se],[Ee,$e]]=ae.toArray();return!(J>Ee||xe<ge||pe>$e||se<Se)},[]),F=U.useCallback(({timeTravel:Q=!1})=>{if(console.log("handleLoadingCroppedRasterLayerToMap start"),!I||a){console.log("ddd either map or dates are loading");return}if(I.getZoom()<10)return;const J=I.getBounds();r.forEach(pe=>{if(RO(pe.options))return;const xe=Mf(pe.options);B(xe,J)&&R(pe.options,{dateRange:t,accessToken:M,map:I,timeTravel:Q,isVisible:y,showCroppedImages:c})}),console.log("handleLoadingCroppedRasterLayerToMap end")},[I,r,M,t,B,E,y,c,p]),q=U.useMemo(()=>Wf(F,500),[F]);return U.useEffect(()=>{y&&(console.log("loading cropped images"),F({timeTravel:!0}))},[t,y,c,r,p]),U.useEffect(()=>{y&&(console.log("settings changed resetting cropped layer"),F({timeTravel:!0}))},[v]),U.useEffect(()=>(I&&n&&E!=="PICKER"&&I.on("click","plots-layer",V),()=>{I&&I.off("click","plots-layer",V)}),[V,E,n,I]),U.useEffect(()=>{if(console.log("running useEffect inside plots"),!(!I||E!=="NORMAL"||!n||!c))return console.log("adding viewport change event to map"),I.on("moveend",q),I.on("zoomend",q),I.on("style.load",q),()=>{console.log("removing viewport change event from map"),q.cancel(),I.off("style.load",q),I.off("moveend",q),I.off("zoomend",q)}},[I,n,E,q,c]),U.useEffect(()=>(I&&E!=="PICKER"&&(I.on("mouseenter","plots-layer",Z),I.on("mouseleave","plots-layer",W)),()=>{I&&E!=="PICKER"&&(I.off("mouseenter","plots-layer",Z),I.off("mouseleave","plots-layer",W))}),[I,Z,W,E]),n?X.jsxs(X.Fragment,{children:[X.jsxs(hE,{id:"plots",type:"geojson",data:{type:"FeatureCollection",features:r.map(Q=>Q==null?void 0:Q.options)},children:[X.jsx(gx,{...ie},"12kmsn"),X.jsx(gx,{...Y},"12kkd")]}),i&&d!==La.COMPARISION_VIEW&&E==Ur.NORMAL&&X.jsx(yEe,{popupInfo:i,onClose:()=>s(null)})]}):null}const VS=function(e,t){const r={drag:[],click:[],mousemove:[],mousedown:[],mouseup:[],mouseout:[],keydown:[],keyup:[],touchstart:[],touchmove:[],touchend:[],tap:[]},n={on(s,c,a){if(r[s]===void 0)throw new Error(`Invalid event type: ${s}`);r[s].push({selector:c,fn:a})},render(s){t.store.featureChanged(s)}},i=function(s,c){const a=r[s];let d=a.length;for(;d--;){const p=a[d];if(p.selector(c)){p.fn.call(n,c)||t.store.render(),t.ui.updateMapClasses();break}}};return e.start.call(n),{render:e.render,stop(){e.stop&&e.stop()},trash(){e.trash&&(e.trash(),t.store.render())},combineFeatures(){e.combineFeatures&&e.combineFeatures()},uncombineFeatures(){e.uncombineFeatures&&e.uncombineFeatures()},drag(s){i("drag",s)},click(s){i("click",s)},mousemove(s){i("mousemove",s)},mousedown(s){i("mousedown",s)},mouseup(s){i("mouseup",s)},mouseout(s){i("mouseout",s)},keydown(s){i("keydown",s)},keyup(s){i("keyup",s)},touchstart(s){i("touchstart",s)},touchmove(s){i("touchmove",s)},touchend(s){i("touchend",s)},tap(s){i("tap",s)}}};var WS={},I0={};I0.RADIUS=6378137,I0.FLATTENING=1/298.257223563,I0.POLAR_RADIUS=63567523142e-4;var JR=I0;WS.geometry=KR,WS.ring=HS;function KR(e){var t=0,r;switch(e.type){case"Polygon":return QR(e.coordinates);case"MultiPolygon":for(r=0;r<e.coordinates.length;r++)t+=QR(e.coordinates[r]);return t;case"Point":case"MultiPoint":case"LineString":case"MultiLineString":return 0;case"GeometryCollection":for(r=0;r<e.geometries.length;r++)t+=KR(e.geometries[r]);return t}}function QR(e){var t=0;if(e&&e.length>0){t+=Math.abs(HS(e[0]));for(var r=1;r<e.length;r++)t-=Math.abs(HS(e[r]))}return t}function HS(e){var t,r,n,i,s,c,a,d=0,p=e.length;if(p>2){for(a=0;a<p;a++)a===p-2?(i=p-2,s=p-1,c=0):a===p-1?(i=p-1,s=0,c=1):(i=a,s=a+1,c=a+2),t=e[i],r=e[s],n=e[c],d+=(US(n[0])-US(t[0]))*Math.sin(US(r[1]));d=d*JR.RADIUS*JR.RADIUS/2}return d}function US(e){return e*Math.PI/180}const Ta={CANVAS:"mapboxgl-canvas",CONTROL_BASE:"mapboxgl-ctrl",CONTROL_PREFIX:"mapboxgl-ctrl-",CONTROL_BUTTON:"mapbox-gl-draw_ctrl-draw-btn",CONTROL_BUTTON_LINE:"mapbox-gl-draw_line",CONTROL_BUTTON_POLYGON:"mapbox-gl-draw_polygon",CONTROL_BUTTON_POINT:"mapbox-gl-draw_point",CONTROL_BUTTON_TRASH:"mapbox-gl-draw_trash",CONTROL_BUTTON_COMBINE_FEATURES:"mapbox-gl-draw_combine",CONTROL_BUTTON_UNCOMBINE_FEATURES:"mapbox-gl-draw_uncombine",CONTROL_GROUP:"mapboxgl-ctrl-group",ATTRIBUTION:"mapboxgl-ctrl-attrib",ACTIVE_BUTTON:"active",BOX_SELECT:"mapbox-gl-draw_boxselect"},ys={HOT:"mapbox-gl-draw-hot",COLD:"mapbox-gl-draw-cold"},Vn={ADD:"add",MOVE:"move",DRAG:"drag",POINTER:"pointer",NONE:"none"},Ia={POLYGON:"polygon",LINE:"line_string",POINT:"point"},yr={FEATURE:"Feature",POLYGON:"Polygon",LINE_STRING:"LineString",POINT:"Point",FEATURE_COLLECTION:"FeatureCollection",MULTI_PREFIX:"Multi",MULTI_POINT:"MultiPoint",MULTI_LINE_STRING:"MultiLineString",MULTI_POLYGON:"MultiPolygon"},Vr={DRAW_LINE_STRING:"draw_line_string",DRAW_POLYGON:"draw_polygon",DRAW_POINT:"draw_point",SIMPLE_SELECT:"simple_select",DIRECT_SELECT:"direct_select"},la={CREATE:"draw.create",DELETE:"draw.delete",UPDATE:"draw.update",SELECTION_CHANGE:"draw.selectionchange",MODE_CHANGE:"draw.modechange",ACTIONABLE:"draw.actionable",RENDER:"draw.render",COMBINE_FEATURES:"draw.combine",UNCOMBINE_FEATURES:"draw.uncombine"},am={MOVE:"move",CHANGE_PROPERTIES:"change_properties",CHANGE_COORDINATES:"change_coordinates"},Hi={FEATURE:"feature",MIDPOINT:"midpoint",VERTEX:"vertex"},vi={ACTIVE:"true",INACTIVE:"false"},eB=["scrollZoom","boxZoom","dragRotate","dragPan","keyboard","doubleClickZoom","touchZoomRotate"],CEe=-90,XS=-85,MEe=90,ZS=85,tB=Object.freeze(Object.defineProperty({__proto__:null,LAT_MAX:MEe,LAT_MIN:CEe,LAT_RENDERED_MAX:ZS,LAT_RENDERED_MIN:XS,LNG_MAX:270,LNG_MIN:-270,activeStates:vi,classes:Ta,cursors:Vn,events:la,geojsonTypes:yr,interactions:eB,meta:Hi,modes:Vr,sources:ys,types:Ia,updateActions:am},Symbol.toStringTag,{value:"Module"})),rB={Point:0,LineString:1,MultiLineString:1,Polygon:2};function EEe(e,t){const r=rB[e.geometry.type]-rB[t.geometry.type];return r===0&&e.geometry.type===yr.POLYGON?e.area-t.area:r}function nB(e){return e.map(t=>(t.geometry.type===yr.POLYGON&&(t.area=WS.geometry({type:yr.FEATURE,property:{},geometry:t.geometry})),t)).sort(EEe).map(t=>(delete t.area,t))}function iB(e,t=0){return[[e.point.x-t,e.point.y-t],[e.point.x+t,e.point.y+t]]}function vs(e){if(this._items={},this._nums={},this._length=e?e.length:0,!!e)for(let t=0,r=e.length;t<r;t++)this.add(e[t]),e[t]!==void 0&&(typeof e[t]=="string"?this._items[e[t]]=t:this._nums[e[t]]=t)}vs.prototype.add=function(e){return this.has(e)?this:(this._length++,typeof e=="string"?this._items[e]=this._length:this._nums[e]=this._length,this)},vs.prototype.delete=function(e){return this.has(e)===!1?this:(this._length--,delete this._items[e],delete this._nums[e],this)},vs.prototype.has=function(e){return typeof e!="string"&&typeof e!="number"?!1:this._items[e]!==void 0||this._nums[e]!==void 0},vs.prototype.values=function(){const e=[];return Object.keys(this._items).forEach(t=>{e.push({k:t,v:this._items[t]})}),Object.keys(this._nums).forEach(t=>{e.push({k:JSON.parse(t),v:this._nums[t]})}),e.sort((t,r)=>t.v-r.v).map(t=>t.k)},vs.prototype.clear=function(){return this._length=0,this._items={},this._nums={},this};const AEe=[Hi.FEATURE,Hi.MIDPOINT,Hi.VERTEX],dd={click:TEe,touch:IEe};function TEe(e,t,r){return aB(e,t,r,r.options.clickBuffer)}function IEe(e,t,r){return aB(e,t,r,r.options.touchBuffer)}function aB(e,t,r,n){if(r.map===null)return[];const i=e?iB(e,n):t,s={};r.options.styles&&(s.layers=r.options.styles.map(p=>p.id).filter(p=>r.map.getLayer(p)!=null));const c=r.map.queryRenderedFeatures(i,s).filter(p=>AEe.indexOf(p.properties.meta)!==-1),a=new vs,d=[];return c.forEach(p=>{const y=p.properties.id;a.has(y)||(a.add(y),d.push(p))}),nB(d)}function P0(e,t){const r=dd.click(e,null,t),n={mouse:Vn.NONE};return r[0]&&(n.mouse=r[0].properties.active===vi.ACTIVE?Vn.MOVE:Vn.POINTER,n.feature=r[0].properties.meta),t.events.currentModeName().indexOf("draw")!==-1&&(n.mouse=Vn.ADD),t.ui.queueMapClasses(n),t.ui.updateMapClasses(),r[0]}function YS(e,t){const r=e.x-t.x,n=e.y-t.y;return Math.sqrt(r*r+n*n)}const PEe=4,OEe=12,kEe=500;function qS(e,t,r={}){const n=r.fineTolerance!=null?r.fineTolerance:PEe,i=r.grossTolerance!=null?r.grossTolerance:OEe,s=r.interval!=null?r.interval:kEe;e.point=e.point||t.point,e.time=e.time||t.time;const c=YS(e.point,t.point);return c<n||c<i&&t.time-e.time<s}const DEe=25,LEe=250;function JS(e,t,r={}){const n=r.tolerance!=null?r.tolerance:DEe,i=r.interval!=null?r.interval:LEe;return e.point=e.point||t.point,e.time=e.time||t.time,YS(e.point,t.point)<n&&t.time-e.time<i}const NEe=((e,t=21)=>(r=t)=>{let n="",i=r|0;for(;i--;)n+=e[Math.random()*e.length|0];return n})("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",32);function KS(){return NEe()}const ca=function(e,t){this.ctx=e,this.properties=t.properties||{},this.coordinates=t.geometry.coordinates,this.id=t.id||KS(),this.type=t.geometry.type};ca.prototype.changed=function(){this.ctx.store.featureChanged(this.id)},ca.prototype.incomingCoords=function(e){this.setCoordinates(e)},ca.prototype.setCoordinates=function(e){this.coordinates=e,this.changed()},ca.prototype.getCoordinates=function(){return JSON.parse(JSON.stringify(this.coordinates))},ca.prototype.setProperty=function(e,t){this.properties[e]=t},ca.prototype.toGeoJSON=function(){return JSON.parse(JSON.stringify({id:this.id,type:yr.FEATURE,properties:this.properties,geometry:{coordinates:this.getCoordinates(),type:this.type}}))},ca.prototype.internal=function(e){const t={id:this.id,meta:Hi.FEATURE,"meta:type":this.type,active:vi.INACTIVE,mode:e};if(this.ctx.options.userProperties)for(const r in this.properties)t[`user_${r}`]=this.properties[r];return{type:yr.FEATURE,properties:t,geometry:{coordinates:this.getCoordinates(),type:this.type}}};const Jl=function(e,t){ca.call(this,e,t)};Jl.prototype=Object.create(ca.prototype),Jl.prototype.isValid=function(){return typeof this.coordinates[0]=="number"&&typeof this.coordinates[1]=="number"},Jl.prototype.updateCoordinate=function(e,t,r){arguments.length===3?this.coordinates=[t,r]:this.coordinates=[e,t],this.changed()},Jl.prototype.getCoordinate=function(){return this.getCoordinates()};const yo=function(e,t){ca.call(this,e,t)};yo.prototype=Object.create(ca.prototype),yo.prototype.isValid=function(){return this.coordinates.length>1},yo.prototype.addCoordinate=function(e,t,r){this.changed();const n=parseInt(e,10);this.coordinates.splice(n,0,[t,r])},yo.prototype.getCoordinate=function(e){const t=parseInt(e,10);return JSON.parse(JSON.stringify(this.coordinates[t]))},yo.prototype.removeCoordinate=function(e){this.changed(),this.coordinates.splice(parseInt(e,10),1)},yo.prototype.updateCoordinate=function(e,t,r){const n=parseInt(e,10);this.coordinates[n]=[t,r],this.changed()};const Wa=function(e,t){ca.call(this,e,t),this.coordinates=this.coordinates.map(r=>r.slice(0,-1))};Wa.prototype=Object.create(ca.prototype),Wa.prototype.isValid=function(){return this.coordinates.length===0?!1:this.coordinates.every(e=>e.length>2)},Wa.prototype.incomingCoords=function(e){this.coordinates=e.map(t=>t.slice(0,-1)),this.changed()},Wa.prototype.setCoordinates=function(e){this.coordinates=e,this.changed()},Wa.prototype.addCoordinate=function(e,t,r){this.changed();const n=e.split(".").map(s=>parseInt(s,10));this.coordinates[n[0]].splice(n[1],0,[t,r])},Wa.prototype.removeCoordinate=function(e){this.changed();const t=e.split(".").map(n=>parseInt(n,10)),r=this.coordinates[t[0]];r&&(r.splice(t[1],1),r.length<3&&this.coordinates.splice(t[0],1))},Wa.prototype.getCoordinate=function(e){const t=e.split(".").map(n=>parseInt(n,10)),r=this.coordinates[t[0]];return JSON.parse(JSON.stringify(r[t[1]]))},Wa.prototype.getCoordinates=function(){return this.coordinates.map(e=>e.concat([e[0]]))},Wa.prototype.updateCoordinate=function(e,t,r){this.changed();const n=e.split("."),i=parseInt(n[0],10),s=parseInt(n[1],10);this.coordinates[i]===void 0&&(this.coordinates[i]=[]),this.coordinates[i][s]=[t,r]};const REe={MultiPoint:Jl,MultiLineString:yo,MultiPolygon:Wa},O0=(e,t,r,n,i)=>{const s=r.split("."),c=parseInt(s[0],10),a=s[1]?s.slice(1).join("."):null;return e[c][t](a,n,i)},ua=function(e,t){if(ca.call(this,e,t),delete this.coordinates,this.model=REe[t.geometry.type],this.model===void 0)throw new TypeError(`${t.geometry.type} is not a valid type`);this.features=this._coordinatesToFeatures(t.geometry.coordinates)};ua.prototype=Object.create(ca.prototype),ua.prototype._coordinatesToFeatures=function(e){const t=this.model.bind(this);return e.map(r=>new t(this.ctx,{id:KS(),type:yr.FEATURE,properties:{},geometry:{coordinates:r,type:this.type.replace("Multi","")}}))},ua.prototype.isValid=function(){return this.features.every(e=>e.isValid())},ua.prototype.setCoordinates=function(e){this.features=this._coordinatesToFeatures(e),this.changed()},ua.prototype.getCoordinate=function(e){return O0(this.features,"getCoordinate",e)},ua.prototype.getCoordinates=function(){return JSON.parse(JSON.stringify(this.features.map(e=>e.type===yr.POLYGON?e.getCoordinates():e.coordinates)))},ua.prototype.updateCoordinate=function(e,t,r){O0(this.features,"updateCoordinate",e,t,r),this.changed()},ua.prototype.addCoordinate=function(e,t,r){O0(this.features,"addCoordinate",e,t,r),this.changed()},ua.prototype.removeCoordinate=function(e){O0(this.features,"removeCoordinate",e),this.changed()},ua.prototype.getFeatures=function(){return this.features};function $r(e){this.map=e.map,this.drawConfig=JSON.parse(JSON.stringify(e.options||{})),this._ctx=e}$r.prototype.setSelected=function(e){return this._ctx.store.setSelected(e)},$r.prototype.setSelectedCoordinates=function(e){this._ctx.store.setSelectedCoordinates(e),e.reduce((t,r)=>(t[r.feature_id]===void 0&&(t[r.feature_id]=!0,this._ctx.store.get(r.feature_id).changed()),t),{})},$r.prototype.getSelected=function(){return this._ctx.store.getSelected()},$r.prototype.getSelectedIds=function(){return this._ctx.store.getSelectedIds()},$r.prototype.isSelected=function(e){return this._ctx.store.isSelected(e)},$r.prototype.getFeature=function(e){return this._ctx.store.get(e)},$r.prototype.select=function(e){return this._ctx.store.select(e)},$r.prototype.deselect=function(e){return this._ctx.store.deselect(e)},$r.prototype.deleteFeature=function(e,t={}){return this._ctx.store.delete(e,t)},$r.prototype.addFeature=function(e,t={}){return this._ctx.store.add(e,t)},$r.prototype.clearSelectedFeatures=function(){return this._ctx.store.clearSelected()},$r.prototype.clearSelectedCoordinates=function(){return this._ctx.store.clearSelectedCoordinates()},$r.prototype.setActionableState=function(e={}){const t={trash:e.trash||!1,combineFeatures:e.combineFeatures||!1,uncombineFeatures:e.uncombineFeatures||!1};return this._ctx.events.actionable(t)},$r.prototype.changeMode=function(e,t={},r={}){return this._ctx.events.changeMode(e,t,r)},$r.prototype.fire=function(e,t){return this._ctx.events.fire(e,t)},$r.prototype.updateUIClasses=function(e){return this._ctx.ui.queueMapClasses(e)},$r.prototype.activateUIButton=function(e){return this._ctx.ui.setActiveButton(e)},$r.prototype.featuresAt=function(e,t,r="click"){if(r!=="click"&&r!=="touch")throw new Error("invalid buffer type");return dd[r](e,t,this._ctx)},$r.prototype.newFeature=function(e){const t=e.geometry.type;return t===yr.POINT?new Jl(this._ctx,e):t===yr.LINE_STRING?new yo(this._ctx,e):t===yr.POLYGON?new Wa(this._ctx,e):new ua(this._ctx,e)},$r.prototype.isInstanceOf=function(e,t){if(e===yr.POINT)return t instanceof Jl;if(e===yr.LINE_STRING)return t instanceof yo;if(e===yr.POLYGON)return t instanceof Wa;if(e==="MultiFeature")return t instanceof ua;throw new Error(`Unknown feature class: ${e}`)},$r.prototype.doRender=function(e){return this._ctx.store.featureChanged(e)},$r.prototype.onSetup=function(){},$r.prototype.onDrag=function(){},$r.prototype.onClick=function(){},$r.prototype.onMouseMove=function(){},$r.prototype.onMouseDown=function(){},$r.prototype.onMouseUp=function(){},$r.prototype.onMouseOut=function(){},$r.prototype.onKeyUp=function(){},$r.prototype.onKeyDown=function(){},$r.prototype.onTouchStart=function(){},$r.prototype.onTouchMove=function(){},$r.prototype.onTouchEnd=function(){},$r.prototype.onTap=function(){},$r.prototype.onStop=function(){},$r.prototype.onTrash=function(){},$r.prototype.onCombineFeature=function(){},$r.prototype.onUncombineFeature=function(){},$r.prototype.toDisplayFeatures=function(){throw new Error("You must overwrite toDisplayFeatures")};const sB={drag:"onDrag",click:"onClick",mousemove:"onMouseMove",mousedown:"onMouseDown",mouseup:"onMouseUp",mouseout:"onMouseOut",keyup:"onKeyUp",keydown:"onKeyDown",touchstart:"onTouchStart",touchmove:"onTouchMove",touchend:"onTouchEnd",tap:"onTap"},BEe=Object.keys(sB);function jEe(e){const t=Object.keys(e);return function(r,n={}){let i={};const s=t.reduce((a,d)=>(a[d]=e[d],a),new $r(r));function c(a){return d=>s[a](i,d)}return{start(){i=s.onSetup(n),BEe.forEach(a=>{const d=sB[a];let p=()=>!1;e[d]&&(p=()=>!0),this.on(a,p,c(d))})},stop(){s.onStop(i)},trash(){s.onTrash(i)},combineFeatures(){s.onCombineFeatures(i)},uncombineFeatures(){s.onUncombineFeatures(i)},render(a,d){s.toDisplayFeatures(i,a,d)}}}}function FEe(e){const t=Object.keys(e.options.modes).reduce((v,w)=>(v[w]=jEe(e.options.modes[w]),v),{});let r={},n={};const i={};let s=null,c=null;i.drag=function(v,w){w({point:v.point,time:new Date().getTime()})?(e.ui.queueMapClasses({mouse:Vn.DRAG}),c.drag(v)):v.originalEvent.stopPropagation()},i.mousedrag=function(v){i.drag(v,w=>!qS(r,w))},i.touchdrag=function(v){i.drag(v,w=>!JS(n,w))},i.mousemove=function(v){if((v.originalEvent.buttons!==void 0?v.originalEvent.buttons:v.originalEvent.which)===1)return i.mousedrag(v);const S=P0(v,e);v.featureTarget=S,c.mousemove(v)},i.mousedown=function(v){r={time:new Date().getTime(),point:v.point};const w=P0(v,e);v.featureTarget=w,c.mousedown(v)},i.mouseup=function(v){const w=P0(v,e);v.featureTarget=w,qS(r,{point:v.point,time:new Date().getTime()})?c.click(v):c.mouseup(v)},i.mouseout=function(v){c.mouseout(v)},i.touchstart=function(v){if(!e.options.touchEnabled)return;n={time:new Date().getTime(),point:v.point};const w=dd.touch(v,null,e)[0];v.featureTarget=w,c.touchstart(v)},i.touchmove=function(v){if(e.options.touchEnabled)return c.touchmove(v),i.touchdrag(v)},i.touchend=function(v){if(v.originalEvent.preventDefault(),!e.options.touchEnabled)return;const w=dd.touch(v,null,e)[0];v.featureTarget=w,JS(n,{time:new Date().getTime(),point:v.point})?c.tap(v):c.touchend(v)};const a=v=>!(v===8||v===46||v>=48&&v<=57);i.keydown=function(v){(v.srcElement||v.target).classList.contains(Ta.CANVAS)&&((v.keyCode===8||v.keyCode===46)&&e.options.controls.trash?(v.preventDefault(),c.trash()):a(v.keyCode)?c.keydown(v):v.keyCode===49&&e.options.controls.point?d(Vr.DRAW_POINT):v.keyCode===50&&e.options.controls.line_string?d(Vr.DRAW_LINE_STRING):v.keyCode===51&&e.options.controls.polygon&&d(Vr.DRAW_POLYGON))},i.keyup=function(v){a(v.keyCode)&&c.keyup(v)},i.zoomend=function(){e.store.changeZoom()},i.data=function(v){if(v.dataType==="style"){const{setup:w,map:S,options:C,store:M}=e;C.styles.some(E=>S.getLayer(E.id))||(w.addLayers(),M.setDirty(),M.render())}};function d(v,w,S={}){c.stop();const C=t[v];if(C===void 0)throw new Error(`${v} is not valid`);s=v;const M=C(e,w);c=VS(M,e),S.silent||e.map.fire(la.MODE_CHANGE,{mode:v}),e.store.setDirty(),e.store.render()}const p={trash:!1,combineFeatures:!1,uncombineFeatures:!1};function y(v){let w=!1;Object.keys(v).forEach(S=>{if(p[S]===void 0)throw new Error("Invalid action type");p[S]!==v[S]&&(w=!0),p[S]=v[S]}),w&&e.map.fire(la.ACTIONABLE,{actions:p})}return{start(){s=e.options.defaultMode,c=VS(t[s](e),e)},changeMode:d,actionable:y,currentModeName(){return s},currentModeRender(v,w){return c.render(v,w)},fire(v,w){e.map&&e.map.fire(v,w)},addEventListeners(){e.map.on("mousemove",i.mousemove),e.map.on("mousedown",i.mousedown),e.map.on("mouseup",i.mouseup),e.map.on("data",i.data),e.map.on("touchmove",i.touchmove),e.map.on("touchstart",i.touchstart),e.map.on("touchend",i.touchend),e.container.addEventListener("mouseout",i.mouseout),e.options.keybindings&&(e.container.addEventListener("keydown",i.keydown),e.container.addEventListener("keyup",i.keyup))},removeEventListeners(){e.map.off("mousemove",i.mousemove),e.map.off("mousedown",i.mousedown),e.map.off("mouseup",i.mouseup),e.map.off("data",i.data),e.map.off("touchmove",i.touchmove),e.map.off("touchstart",i.touchstart),e.map.off("touchend",i.touchend),e.container.removeEventListener("mouseout",i.mouseout),e.options.keybindings&&(e.container.removeEventListener("keydown",i.keydown),e.container.removeEventListener("keyup",i.keyup))},trash(v){c.trash(v)},combineFeatures(){c.combineFeatures()},uncombineFeatures(){c.uncombineFeatures()},getMode(){return s}}}function sm(e){return[].concat(e).filter(t=>t!==void 0)}function zEe(){const e=this;if(!(e.ctx.map&&e.ctx.map.getSource(ys.HOT)!==void 0))return d();const r=e.ctx.events.currentModeName();e.ctx.ui.queueMapClasses({mode:r});let n=[],i=[];e.isDirty?i=e.getAllIds():(n=e.getChangedIds().filter(p=>e.get(p)!==void 0),i=e.sources.hot.filter(p=>p.properties.id&&n.indexOf(p.properties.id)===-1&&e.get(p.properties.id)!==void 0).map(p=>p.properties.id)),e.sources.hot=[];const s=e.sources.cold.length;e.sources.cold=e.isDirty?[]:e.sources.cold.filter(p=>{const y=p.properties.id||p.properties.parent;return n.indexOf(y)===-1});const c=s!==e.sources.cold.length||i.length>0;n.forEach(p=>a(p,"hot")),i.forEach(p=>a(p,"cold"));function a(p,y){const v=e.get(p).internal(r);e.ctx.events.currentModeRender(v,w=>{w.properties.mode=r,e.sources[y].push(w)})}c&&e.ctx.map.getSource(ys.COLD).setData({type:yr.FEATURE_COLLECTION,features:e.sources.cold}),e.ctx.map.getSource(ys.HOT).setData({type:yr.FEATURE_COLLECTION,features:e.sources.hot}),d();function d(){e.isDirty=!1,e.clearChangedIds()}}function Nn(e){this._features={},this._featureIds=new vs,this._selectedFeatureIds=new vs,this._selectedCoordinates=[],this._changedFeatureIds=new vs,this._emitSelectionChange=!1,this._mapInitialConfig={},this.ctx=e,this.sources={hot:[],cold:[]};let t;this.render=()=>{t||(t=requestAnimationFrame(()=>{t=null,zEe.call(this),this._emitSelectionChange&&(this.ctx.events.fire(la.SELECTION_CHANGE,{features:this.getSelected().map(r=>r.toGeoJSON()),points:this.getSelectedCoordinates().map(r=>({type:yr.FEATURE,properties:{},geometry:{type:yr.POINT,coordinates:r.coordinates}}))}),this._emitSelectionChange=!1),this.ctx.events.fire(la.RENDER,{})}))},this.isDirty=!1}Nn.prototype.createRenderBatch=function(){const e=this.render;let t=0;return this.render=function(){t++},()=>{this.render=e,t>0&&this.render()}},Nn.prototype.setDirty=function(){return this.isDirty=!0,this},Nn.prototype.featureCreated=function(e,t={}){if(this._changedFeatureIds.add(e),(t.silent!=null?t.silent:this.ctx.options.suppressAPIEvents)!==!0){const n=this.get(e);this.ctx.events.fire(la.CREATE,{features:[n.toGeoJSON()]})}return this},Nn.prototype.featureChanged=function(e,t={}){return this._changedFeatureIds.add(e),(t.silent!=null?t.silent:this.ctx.options.suppressAPIEvents)!==!0&&this.ctx.events.fire(la.UPDATE,{action:t.action?t.action:am.CHANGE_COORDINATES,features:[this.get(e).toGeoJSON()]}),this},Nn.prototype.getChangedIds=function(){return this._changedFeatureIds.values()},Nn.prototype.clearChangedIds=function(){return this._changedFeatureIds.clear(),this},Nn.prototype.getAllIds=function(){return this._featureIds.values()},Nn.prototype.add=function(e,t={}){return this._features[e.id]=e,this._featureIds.add(e.id),this.featureCreated(e.id,{silent:t.silent}),this},Nn.prototype.delete=function(e,t={}){const r=[];return sm(e).forEach(n=>{this._featureIds.has(n)&&(this._featureIds.delete(n),this._selectedFeatureIds.delete(n),t.silent||r.indexOf(this._features[n])===-1&&r.push(this._features[n].toGeoJSON()),delete this._features[n],this.isDirty=!0)}),r.length&&this.ctx.events.fire(la.DELETE,{features:r}),oB(this,t),this},Nn.prototype.get=function(e){return this._features[e]},Nn.prototype.getAll=function(){return Object.keys(this._features).map(e=>this._features[e])},Nn.prototype.select=function(e,t={}){return sm(e).forEach(r=>{this._selectedFeatureIds.has(r)||(this._selectedFeatureIds.add(r),this._changedFeatureIds.add(r),t.silent||(this._emitSelectionChange=!0))}),this},Nn.prototype.deselect=function(e,t={}){return sm(e).forEach(r=>{this._selectedFeatureIds.has(r)&&(this._selectedFeatureIds.delete(r),this._changedFeatureIds.add(r),t.silent||(this._emitSelectionChange=!0))}),oB(this,t),this},Nn.prototype.clearSelected=function(e={}){return this.deselect(this._selectedFeatureIds.values(),{silent:e.silent}),this},Nn.prototype.setSelected=function(e,t={}){return e=sm(e),this.deselect(this._selectedFeatureIds.values().filter(r=>e.indexOf(r)===-1),{silent:t.silent}),this.select(e.filter(r=>!this._selectedFeatureIds.has(r)),{silent:t.silent}),this},Nn.prototype.setSelectedCoordinates=function(e){return this._selectedCoordinates=e,this._emitSelectionChange=!0,this},Nn.prototype.clearSelectedCoordinates=function(){return this._selectedCoordinates=[],this._emitSelectionChange=!0,this},Nn.prototype.getSelectedIds=function(){return this._selectedFeatureIds.values()},Nn.prototype.getSelected=function(){return this.getSelectedIds().map(e=>this.get(e))},Nn.prototype.getSelectedCoordinates=function(){return this._selectedCoordinates.map(t=>({coordinates:this.get(t.feature_id).getCoordinate(t.coord_path)}))},Nn.prototype.isSelected=function(e){return this._selectedFeatureIds.has(e)},Nn.prototype.setFeatureProperty=function(e,t,r,n={}){this.get(e).setProperty(t,r),this.featureChanged(e,{silent:n.silent,action:am.CHANGE_PROPERTIES})};function oB(e,t={}){const r=e._selectedCoordinates.filter(n=>e._selectedFeatureIds.has(n.feature_id));e._selectedCoordinates.length!==r.length&&!t.silent&&(e._emitSelectionChange=!0),e._selectedCoordinates=r}Nn.prototype.storeMapConfig=function(){eB.forEach(e=>{this.ctx.map[e]&&(this._mapInitialConfig[e]=this.ctx.map[e].isEnabled())})},Nn.prototype.restoreMapConfig=function(){Object.keys(this._mapInitialConfig).forEach(e=>{this._mapInitialConfig[e]?this.ctx.map[e].enable():this.ctx.map[e].disable()})},Nn.prototype.getInitialConfigValue=function(e){return this._mapInitialConfig[e]!==void 0?this._mapInitialConfig[e]:!0};const $Ee=["mode","feature","mouse"];function GEe(e){const t={};let r=null,n={mode:null,feature:null,mouse:null},i={mode:null,feature:null,mouse:null};function s(){c({mode:null,feature:null,mouse:null}),a()}function c(w){i=Object.assign(i,w)}function a(){if(!e.container)return;const w=[],S=[];$Ee.forEach(C=>{i[C]!==n[C]&&(w.push(`${C}-${n[C]}`),i[C]!==null&&S.push(`${C}-${i[C]}`))}),w.length>0&&e.container.classList.remove(...w),S.length>0&&e.container.classList.add(...S),n=Object.assign(n,i)}function d(w,S={}){const C=document.createElement("button");return C.className=`${Ta.CONTROL_BUTTON} ${S.className}`,C.setAttribute("title",S.title),S.container.appendChild(C),C.addEventListener("click",M=>{if(M.preventDefault(),M.stopPropagation(),M.target===r){p(),S.onDeactivate();return}y(w),S.onActivate()},!0),C}function p(){r&&(r.classList.remove(Ta.ACTIVE_BUTTON),r=null)}function y(w){p();const S=t[w];S&&S&&w!=="trash"&&(S.classList.add(Ta.ACTIVE_BUTTON),r=S)}function g(){const w=e.options.controls,S=document.createElement("div");return S.className=`${Ta.CONTROL_GROUP} ${Ta.CONTROL_BASE}`,w&&(w[Ia.LINE]&&(t[Ia.LINE]=d(Ia.LINE,{container:S,className:Ta.CONTROL_BUTTON_LINE,title:`LineString tool ${e.options.keybindings?"(l)":""}`,onActivate:()=>e.events.changeMode(Vr.DRAW_LINE_STRING),onDeactivate:()=>e.events.trash()})),w[Ia.POLYGON]&&(t[Ia.POLYGON]=d(Ia.POLYGON,{container:S,className:Ta.CONTROL_BUTTON_POLYGON,title:`Polygon tool ${e.options.keybindings?"(p)":""}`,onActivate:()=>e.events.changeMode(Vr.DRAW_POLYGON),onDeactivate:()=>e.events.trash()})),w[Ia.POINT]&&(t[Ia.POINT]=d(Ia.POINT,{container:S,className:Ta.CONTROL_BUTTON_POINT,title:`Marker tool ${e.options.keybindings?"(m)":""}`,onActivate:()=>e.events.changeMode(Vr.DRAW_POINT),onDeactivate:()=>e.events.trash()})),w.trash&&(t.trash=d("trash",{container:S,className:Ta.CONTROL_BUTTON_TRASH,title:"Delete",onActivate:()=>{e.events.trash()}})),w.combine_features&&(t.combine_features=d("combineFeatures",{container:S,className:Ta.CONTROL_BUTTON_COMBINE_FEATURES,title:"Combine",onActivate:()=>{e.events.combineFeatures()}})),w.uncombine_features&&(t.uncombine_features=d("uncombineFeatures",{container:S,className:Ta.CONTROL_BUTTON_UNCOMBINE_FEATURES,title:"Uncombine",onActivate:()=>{e.events.uncombineFeatures()}}))),S}function v(){Object.keys(t).forEach(w=>{const S=t[w];S.parentNode&&S.parentNode.removeChild(S),delete t[w]})}return{setActiveButton:y,queueMapClasses:c,updateMapClasses:a,clearMapClasses:s,addButtons:g,removeButtons:v}}function VEe(e){let t=null,r=null;const n={onRemove(){return e.map.off("load",n.connect),clearInterval(r),n.removeLayers(),e.store.restoreMapConfig(),e.ui.removeButtons(),e.events.removeEventListeners(),e.ui.clearMapClasses(),e.boxZoomInitial&&e.map.boxZoom.enable(),e.map=null,e.container=null,e.store=null,t&&t.parentNode&&t.parentNode.removeChild(t),t=null,this},connect(){e.map.off("load",n.connect),clearInterval(r),n.addLayers(),e.store.storeMapConfig(),e.events.addEventListeners()},onAdd(i){if(e.map=i,e.events=FEe(e),e.ui=GEe(e),e.container=i.getContainer(),e.store=new Nn(e),t=e.ui.addButtons(),e.options.boxSelect){e.boxZoomInitial=i.boxZoom.isEnabled(),i.boxZoom.disable();const s=i.dragPan.isEnabled();i.dragPan.disable(),i.dragPan.enable(),s||i.dragPan.disable()}return i.loaded()?n.connect():(i.on("load",n.connect),r=setInterval(()=>{i.loaded()&&n.connect()},16)),e.events.start(),t},addLayers(){e.map.addSource(ys.COLD,{data:{type:yr.FEATURE_COLLECTION,features:[]},type:"geojson"}),e.map.addSource(ys.HOT,{data:{type:yr.FEATURE_COLLECTION,features:[]},type:"geojson"}),e.options.styles.forEach(i=>{e.map.addLayer(i)}),e.store.setDirty(!0),e.store.render()},removeLayers(){e.options.styles.forEach(i=>{e.map.getLayer(i.id)&&e.map.removeLayer(i.id)}),e.map.getSource(ys.COLD)&&e.map.removeSource(ys.COLD),e.map.getSource(ys.HOT)&&e.map.removeSource(ys.HOT)}};return e.setup=n,n}const QS="#3bb2d0",om="#fbb03b",lB="#fff",cB=[{id:"gl-draw-polygon-fill",type:"fill",filter:["all",["==","$type","Polygon"]],paint:{"fill-color":["case",["==",["get","active"],"true"],om,QS],"fill-opacity":.1}},{id:"gl-draw-lines",type:"line",filter:["any",["==","$type","LineString"],["==","$type","Polygon"]],layout:{"line-cap":"round","line-join":"round"},paint:{"line-color":["case",["==",["get","active"],"true"],om,QS],"line-dasharray":["case",["==",["get","active"],"true"],[.2,2],[2,0]],"line-width":2}},{id:"gl-draw-point-outer",type:"circle",filter:["all",["==","$type","Point"],["==","meta","feature"]],paint:{"circle-radius":["case",["==",["get","active"],"true"],7,5],"circle-color":lB}},{id:"gl-draw-point-inner",type:"circle",filter:["all",["==","$type","Point"],["==","meta","feature"]],paint:{"circle-radius":["case",["==",["get","active"],"true"],5,3],"circle-color":["case",["==",["get","active"],"true"],om,QS]}},{id:"gl-draw-vertex-outer",type:"circle",filter:["all",["==","$type","Point"],["==","meta","vertex"],["!=","mode","simple_select"]],paint:{"circle-radius":["case",["==",["get","active"],"true"],7,5],"circle-color":lB}},{id:"gl-draw-vertex-inner",type:"circle",filter:["all",["==","$type","Point"],["==","meta","vertex"],["!=","mode","simple_select"]],paint:{"circle-radius":["case",["==",["get","active"],"true"],5,3],"circle-color":om}},{id:"gl-draw-midpoint",type:"circle",filter:["all",["==","meta","midpoint"]],paint:{"circle-radius":3,"circle-color":om}}];function k0(e){return function(t){const r=t.featureTarget;return!r||!r.properties?!1:r.properties.meta===e}}function uB(e){return!e.originalEvent||!e.originalEvent.shiftKey?!1:e.originalEvent.button===0}function lu(e){return!e.featureTarget||!e.featureTarget.properties?!1:e.featureTarget.properties.active===vi.ACTIVE&&e.featureTarget.properties.meta===Hi.FEATURE}function eC(e){return!e.featureTarget||!e.featureTarget.properties?!1:e.featureTarget.properties.active===vi.INACTIVE&&e.featureTarget.properties.meta===Hi.FEATURE}function D0(e){return e.featureTarget===void 0}function tC(e){return!e.featureTarget||!e.featureTarget.properties?!1:e.featureTarget.properties.meta===Hi.FEATURE}function lm(e){const t=e.featureTarget;return!t||!t.properties?!1:t.properties.meta===Hi.VERTEX}function L0(e){return e.originalEvent?e.originalEvent.shiftKey===!0:!1}function N0(e){return e.keyCode===27}function R0(e){return e.keyCode===13}function WEe(){return!0}const HEe=Object.freeze(Object.defineProperty({__proto__:null,isActiveFeature:lu,isEnterKey:R0,isEscapeKey:N0,isFeature:tC,isInactiveFeature:eC,isOfMetaType:k0,isShiftDown:L0,isShiftMousedown:uB,isTrue:WEe,isVertex:lm,noTarget:D0},Symbol.toStringTag,{value:"Module"}));function Kl(e,t){this.x=e,this.y=t}Kl.prototype={clone(){return new Kl(this.x,this.y)},add(e){return this.clone()._add(e)},sub(e){return this.clone()._sub(e)},multByPoint(e){return this.clone()._multByPoint(e)},divByPoint(e){return this.clone()._divByPoint(e)},mult(e){return this.clone()._mult(e)},div(e){return this.clone()._div(e)},rotate(e){return this.clone()._rotate(e)},rotateAround(e,t){return this.clone()._rotateAround(e,t)},matMult(e){return this.clone()._matMult(e)},unit(){return this.clone()._unit()},perp(){return this.clone()._perp()},round(){return this.clone()._round()},mag(){return Math.sqrt(this.x*this.x+this.y*this.y)},equals(e){return this.x===e.x&&this.y===e.y},dist(e){return Math.sqrt(this.distSqr(e))},distSqr(e){const t=e.x-this.x,r=e.y-this.y;return t*t+r*r},angle(){return Math.atan2(this.y,this.x)},angleTo(e){return Math.atan2(this.y-e.y,this.x-e.x)},angleWith(e){return this.angleWithSep(e.x,e.y)},angleWithSep(e,t){return Math.atan2(this.x*t-this.y*e,this.x*e+this.y*t)},_matMult(e){const t=e[0]*this.x+e[1]*this.y,r=e[2]*this.x+e[3]*this.y;return this.x=t,this.y=r,this},_add(e){return this.x+=e.x,this.y+=e.y,this},_sub(e){return this.x-=e.x,this.y-=e.y,this},_mult(e){return this.x*=e,this.y*=e,this},_div(e){return this.x/=e,this.y/=e,this},_multByPoint(e){return this.x*=e.x,this.y*=e.y,this},_divByPoint(e){return this.x/=e.x,this.y/=e.y,this},_unit(){return this._div(this.mag()),this},_perp(){const e=this.y;return this.y=this.x,this.x=-e,this},_rotate(e){const t=Math.cos(e),r=Math.sin(e),n=t*this.x-r*this.y,i=r*this.x+t*this.y;return this.x=n,this.y=i,this},_rotateAround(e,t){const r=Math.cos(e),n=Math.sin(e),i=t.x+r*(this.x-t.x)-n*(this.y-t.y),s=t.y+n*(this.x-t.x)+r*(this.y-t.y);return this.x=i,this.y=s,this},_round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this},constructor:Kl},Kl.convert=function(e){if(e instanceof Kl)return e;if(Array.isArray(e))return new Kl(+e[0],+e[1]);if(e.x!==void 0&&e.y!==void 0)return new Kl(+e.x,+e.y);throw new Error("Expected [x, y] or {x, y} point format")};function rC(e,t){const r=t.getBoundingClientRect();return new Kl(e.clientX-r.left-(t.clientLeft||0),e.clientY-r.top-(t.clientTop||0))}function fd(e,t,r,n){return{type:yr.FEATURE,properties:{meta:Hi.VERTEX,parent:e,coord_path:r,active:n?vi.ACTIVE:vi.INACTIVE},geometry:{type:yr.POINT,coordinates:t}}}function hB(e,t,r){const n=t.geometry.coordinates,i=r.geometry.coordinates;if(n[1]>ZS||n[1]<XS||i[1]>ZS||i[1]<XS)return null;const s={lng:(n[0]+i[0])/2,lat:(n[1]+i[1])/2};return{type:yr.FEATURE,properties:{meta:Hi.MIDPOINT,parent:e,lng:s.lng,lat:s.lat,coord_path:r.properties.coord_path},geometry:{type:yr.POINT,coordinates:[s.lng,s.lat]}}}function B0(e,t={},r=null){const{type:n,coordinates:i}=e.geometry,s=e.properties&&e.properties.id;let c=[];n===yr.POINT?c.push(fd(s,i,r,d(r))):n===yr.POLYGON?i.forEach((y,g)=>{a(y,r!==null?`${r}.${g}`:String(g))}):n===yr.LINE_STRING?a(i,r):n.indexOf(yr.MULTI_PREFIX)===0&&p();function a(y,g){let v="",w=null;y.forEach((S,C)=>{const M=g!=null?`${g}.${C}`:String(C),I=fd(s,S,M,d(M));if(t.midpoints&&w){const O=hB(s,w,I);O&&c.push(O)}w=I;const E=JSON.stringify(S);v!==E&&c.push(I),C===0&&(v=E)})}function d(y){return t.selectedPaths?t.selectedPaths.indexOf(y)!==-1:!1}function p(){const y=n.replace(yr.MULTI_PREFIX,"");i.forEach((g,v)=>{const w={type:yr.FEATURE,properties:e.properties,geometry:{type:y,coordinates:g}};c=c.concat(B0(w,t,v))})}return c}const Bs={enable(e){setTimeout(()=>{!e.map||!e.map.doubleClickZoom||!e._ctx||!e._ctx.store||!e._ctx.store.getInitialConfigValue||e._ctx.store.getInitialConfigValue("doubleClickZoom")&&e.map.doubleClickZoom.enable()},0)},disable(e){setTimeout(()=>{!e.map||!e.map.doubleClickZoom||e.map.doubleClickZoom.disable()},0)}},{LAT_MIN:j0,LAT_MAX:F0,LAT_RENDERED_MIN:dB,LAT_RENDERED_MAX:fB,LNG_MIN:pB,LNG_MAX:mB}=tB;function UEe(e){const t={Point:0,LineString:1,Polygon:2,MultiPoint:1,MultiLineString:2,MultiPolygon:3}[e.geometry.type],r=[e.geometry.coordinates].flat(t),n=r.map(a=>a[0]),i=r.map(a=>a[1]),s=a=>Math.min.apply(null,a),c=a=>Math.max.apply(null,a);return[s(n),s(i),c(n),c(i)]}function nC(e,t){let r=j0,n=F0,i=j0,s=F0,c=mB,a=pB;e.forEach(p=>{const y=UEe(p),g=y[1],v=y[3],w=y[0],S=y[2];g>r&&(r=g),v<n&&(n=v),v>i&&(i=v),g<s&&(s=g),w<c&&(c=w),S>a&&(a=S)});const d=t;return r+d.lat>fB&&(d.lat=fB-r),i+d.lat>F0&&(d.lat=F0-i),n+d.lat<dB&&(d.lat=dB-n),s+d.lat<j0&&(d.lat=j0-s),c+d.lng<=pB&&(d.lng+=Math.ceil(Math.abs(d.lng)/360)*360),a+d.lng>=mB&&(d.lng-=Math.ceil(Math.abs(d.lng)/360)*360),d}function iC(e,t){const r=nC(e.map(n=>n.toGeoJSON()),t);e.forEach(n=>{const i=n.getCoordinates(),s=p=>{const y={lng:p[0]+r.lng,lat:p[1]+r.lat};return[y.lng,y.lat]},c=p=>p.map(y=>s(y)),a=p=>p.map(y=>c(y));let d;n.type===yr.POINT?d=s(i):n.type===yr.LINE_STRING||n.type===yr.MULTI_POINT?d=i.map(s):n.type===yr.POLYGON||n.type===yr.MULTI_LINE_STRING?d=i.map(c):n.type===yr.MULTI_POLYGON&&(d=i.map(a)),n.incomingCoords(d)})}const An={};An.onSetup=function(e){const t={dragMoveLocation:null,boxSelectStartLocation:null,boxSelectElement:void 0,boxSelecting:!1,canBoxSelect:!1,dragMoving:!1,canDragMove:!1,initialDragPanState:this.map.dragPan.isEnabled(),initiallySelectedFeatureIds:e.featureIds||[]};return this.setSelected(t.initiallySelectedFeatureIds.filter(r=>this.getFeature(r)!==void 0)),this.fireActionable(),this.setActionableState({combineFeatures:!0,uncombineFeatures:!0,trash:!0}),t},An.fireUpdate=function(){this.fire(la.UPDATE,{action:am.MOVE,features:this.getSelected().map(e=>e.toGeoJSON())})},An.fireActionable=function(){const e=this.getSelected(),t=e.filter(s=>this.isInstanceOf("MultiFeature",s));let r=!1;if(e.length>1){r=!0;const s=e[0].type.replace("Multi","");e.forEach(c=>{c.type.replace("Multi","")!==s&&(r=!1)})}const n=t.length>0,i=e.length>0;this.setActionableState({combineFeatures:r,uncombineFeatures:n,trash:i})},An.getUniqueIds=function(e){return e.length?e.map(r=>r.properties.id).filter(r=>r!==void 0).reduce((r,n)=>(r.add(n),r),new vs).values():[]},An.stopExtendedInteractions=function(e){e.boxSelectElement&&(e.boxSelectElement.parentNode&&e.boxSelectElement.parentNode.removeChild(e.boxSelectElement),e.boxSelectElement=null),(e.canDragMove||e.canBoxSelect)&&e.initialDragPanState===!0&&this.map.dragPan.enable(),e.boxSelecting=!1,e.canBoxSelect=!1,e.dragMoving=!1,e.canDragMove=!1},An.onStop=function(){Bs.enable(this)},An.onMouseMove=function(e,t){return tC(t)&&e.dragMoving&&this.fireUpdate(),this.stopExtendedInteractions(e),!0},An.onMouseOut=function(e){return e.dragMoving?this.fireUpdate():!0},An.onTap=An.onClick=function(e,t){if(D0(t))return this.clickAnywhere(e,t);if(k0(Hi.VERTEX)(t))return this.clickOnVertex(e,t);if(tC(t))return this.clickOnFeature(e,t)},An.clickAnywhere=function(e){const t=this.getSelectedIds();t.length&&(this.clearSelectedFeatures(),t.forEach(r=>this.doRender(r))),Bs.enable(this),this.stopExtendedInteractions(e)},An.clickOnVertex=function(e,t){this.changeMode(Vr.DIRECT_SELECT,{featureId:t.featureTarget.properties.parent,coordPath:t.featureTarget.properties.coord_path,startPos:t.lngLat}),this.updateUIClasses({mouse:Vn.MOVE})},An.startOnActiveFeature=function(e,t){this.stopExtendedInteractions(e),this.map.dragPan.disable(),this.doRender(t.featureTarget.properties.id),e.canDragMove=!0,e.dragMoveLocation=t.lngLat},An.clickOnFeature=function(e,t){Bs.disable(this),this.stopExtendedInteractions(e);const r=L0(t),n=this.getSelectedIds(),i=t.featureTarget.properties.id,s=this.isSelected(i);if(!r&&s&&this.getFeature(i).type!==yr.POINT)return this.changeMode(Vr.DIRECT_SELECT,{featureId:i});s&&r?(this.deselect(i),this.updateUIClasses({mouse:Vn.POINTER}),n.length===1&&Bs.enable(this)):!s&&r?(this.select(i),this.updateUIClasses({mouse:Vn.MOVE})):!s&&!r&&(n.forEach(c=>this.doRender(c)),this.setSelected(i),this.updateUIClasses({mouse:Vn.MOVE})),this.doRender(i)},An.onMouseDown=function(e,t){if(e.initialDragPanState=this.map.dragPan.isEnabled(),lu(t))return this.startOnActiveFeature(e,t);if(this.drawConfig.boxSelect&&uB(t))return this.startBoxSelect(e,t)},An.startBoxSelect=function(e,t){this.stopExtendedInteractions(e),this.map.dragPan.disable(),e.boxSelectStartLocation=rC(t.originalEvent,this.map.getContainer()),e.canBoxSelect=!0},An.onTouchStart=function(e,t){if(lu(t))return this.startOnActiveFeature(e,t)},An.onDrag=function(e,t){if(e.canDragMove)return this.dragMove(e,t);if(this.drawConfig.boxSelect&&e.canBoxSelect)return this.whileBoxSelect(e,t)},An.whileBoxSelect=function(e,t){e.boxSelecting=!0,this.updateUIClasses({mouse:Vn.ADD}),e.boxSelectElement||(e.boxSelectElement=document.createElement("div"),e.boxSelectElement.classList.add(Ta.BOX_SELECT),this.map.getContainer().appendChild(e.boxSelectElement));const r=rC(t.originalEvent,this.map.getContainer()),n=Math.min(e.boxSelectStartLocation.x,r.x),i=Math.max(e.boxSelectStartLocation.x,r.x),s=Math.min(e.boxSelectStartLocation.y,r.y),c=Math.max(e.boxSelectStartLocation.y,r.y),a=`translate(${n}px, ${s}px)`;e.boxSelectElement.style.transform=a,e.boxSelectElement.style.WebkitTransform=a,e.boxSelectElement.style.width=`${i-n}px`,e.boxSelectElement.style.height=`${c-s}px`},An.dragMove=function(e,t){e.dragMoving=!0,t.originalEvent.stopPropagation();const r={lng:t.lngLat.lng-e.dragMoveLocation.lng,lat:t.lngLat.lat-e.dragMoveLocation.lat};iC(this.getSelected(),r),e.dragMoveLocation=t.lngLat},An.onTouchEnd=An.onMouseUp=function(e,t){if(e.dragMoving)this.fireUpdate();else if(e.boxSelecting){const r=[e.boxSelectStartLocation,rC(t.originalEvent,this.map.getContainer())],n=this.featuresAt(null,r,"click"),i=this.getUniqueIds(n).filter(s=>!this.isSelected(s));i.length&&(this.select(i),i.forEach(s=>this.doRender(s)),this.updateUIClasses({mouse:Vn.MOVE}))}this.stopExtendedInteractions(e)},An.toDisplayFeatures=function(e,t,r){t.properties.active=this.isSelected(t.properties.id)?vi.ACTIVE:vi.INACTIVE,r(t),this.fireActionable(),!(t.properties.active!==vi.ACTIVE||t.geometry.type===yr.POINT)&&B0(t).forEach(r)},An.onTrash=function(){this.deleteFeature(this.getSelectedIds()),this.fireActionable()},An.onCombineFeatures=function(){const e=this.getSelected();if(e.length===0||e.length<2)return;const t=[],r=[],n=e[0].type.replace("Multi","");for(let i=0;i<e.length;i++){const s=e[i];if(s.type.replace("Multi","")!==n)return;s.type.includes("Multi")?s.getCoordinates().forEach(c=>{t.push(c)}):t.push(s.getCoordinates()),r.push(s.toGeoJSON())}if(r.length>1){const i=this.newFeature({type:yr.FEATURE,properties:r[0].properties,geometry:{type:`Multi${n}`,coordinates:t}});this.addFeature(i),this.deleteFeature(this.getSelectedIds(),{silent:!0}),this.setSelected([i.id]),this.fire(la.COMBINE_FEATURES,{createdFeatures:[i.toGeoJSON()],deletedFeatures:r})}this.fireActionable()},An.onUncombineFeatures=function(){const e=this.getSelected();if(e.length===0)return;const t=[],r=[];for(let n=0;n<e.length;n++){const i=e[n];this.isInstanceOf("MultiFeature",i)&&(i.getFeatures().forEach(s=>{this.addFeature(s),s.properties=i.properties,t.push(s.toGeoJSON()),this.select([s.id])}),this.deleteFeature(i.id,{silent:!0}),r.push(i.toGeoJSON()))}t.length>1&&this.fire(la.UNCOMBINE_FEATURES,{createdFeatures:t,deletedFeatures:r}),this.fireActionable()};const gB=k0(Hi.VERTEX),yB=k0(Hi.MIDPOINT),Tn={};Tn.fireUpdate=function(){this.fire(la.UPDATE,{action:am.CHANGE_COORDINATES,features:this.getSelected().map(e=>e.toGeoJSON())})},Tn.fireActionable=function(e){this.setActionableState({combineFeatures:!1,uncombineFeatures:!1,trash:e.selectedCoordPaths.length>0})},Tn.startDragging=function(e,t){e.initialDragPanState=this.map.dragPan.isEnabled(),this.map.dragPan.disable(),e.canDragMove=!0,e.dragMoveLocation=t.lngLat},Tn.stopDragging=function(e){e.canDragMove&&e.initialDragPanState===!0&&this.map.dragPan.enable(),e.dragMoving=!1,e.canDragMove=!1,e.dragMoveLocation=null},Tn.onVertex=function(e,t){this.startDragging(e,t);const r=t.featureTarget.properties,n=e.selectedCoordPaths.indexOf(r.coord_path);!L0(t)&&n===-1?e.selectedCoordPaths=[r.coord_path]:L0(t)&&n===-1&&e.selectedCoordPaths.push(r.coord_path);const i=this.pathsToCoordinates(e.featureId,e.selectedCoordPaths);this.setSelectedCoordinates(i)},Tn.onMidpoint=function(e,t){this.startDragging(e,t);const r=t.featureTarget.properties;e.feature.addCoordinate(r.coord_path,r.lng,r.lat),this.fireUpdate(),e.selectedCoordPaths=[r.coord_path]},Tn.pathsToCoordinates=function(e,t){return t.map(r=>({feature_id:e,coord_path:r}))},Tn.onFeature=function(e,t){e.selectedCoordPaths.length===0?this.startDragging(e,t):this.stopDragging(e)},Tn.dragFeature=function(e,t,r){iC(this.getSelected(),r),e.dragMoveLocation=t.lngLat},Tn.dragVertex=function(e,t,r){const n=e.selectedCoordPaths.map(c=>e.feature.getCoordinate(c)),i=n.map(c=>({type:yr.FEATURE,properties:{},geometry:{type:yr.POINT,coordinates:c}})),s=nC(i,r);for(let c=0;c<n.length;c++){const a=n[c];e.feature.updateCoordinate(e.selectedCoordPaths[c],a[0]+s.lng,a[1]+s.lat)}},Tn.clickNoTarget=function(){this.changeMode(Vr.SIMPLE_SELECT)},Tn.clickInactive=function(){this.changeMode(Vr.SIMPLE_SELECT)},Tn.clickActiveFeature=function(e){e.selectedCoordPaths=[],this.clearSelectedCoordinates(),e.feature.changed()},Tn.onSetup=function(e){const t=e.featureId,r=this.getFeature(t);if(!r)throw new Error("You must provide a featureId to enter direct_select mode");if(r.type===yr.POINT)throw new TypeError("direct_select mode doesn't handle point features");const n={featureId:t,feature:r,dragMoveLocation:e.startPos||null,dragMoving:!1,canDragMove:!1,selectedCoordPaths:e.coordPath?[e.coordPath]:[]};return this.setSelectedCoordinates(this.pathsToCoordinates(t,n.selectedCoordPaths)),this.setSelected(t),Bs.disable(this),this.setActionableState({trash:!0}),n},Tn.onStop=function(){Bs.enable(this),this.clearSelectedCoordinates()},Tn.toDisplayFeatures=function(e,t,r){e.featureId===t.properties.id?(t.properties.active=vi.ACTIVE,r(t),B0(t,{map:this.map,midpoints:!0,selectedPaths:e.selectedCoordPaths}).forEach(r)):(t.properties.active=vi.INACTIVE,r(t)),this.fireActionable(e)},Tn.onTrash=function(e){e.selectedCoordPaths.sort((t,r)=>r.localeCompare(t,"en",{numeric:!0})).forEach(t=>e.feature.removeCoordinate(t)),this.fireUpdate(),e.selectedCoordPaths=[],this.clearSelectedCoordinates(),this.fireActionable(e),e.feature.isValid()===!1&&(this.deleteFeature([e.featureId]),this.changeMode(Vr.SIMPLE_SELECT,{}))},Tn.onMouseMove=function(e,t){const r=lu(t),n=gB(t),i=yB(t),s=e.selectedCoordPaths.length===0;return r&&s?this.updateUIClasses({mouse:Vn.MOVE}):n&&!s?this.updateUIClasses({mouse:Vn.MOVE}):this.updateUIClasses({mouse:Vn.NONE}),(n||r||i)&&e.dragMoving&&this.fireUpdate(),this.stopDragging(e),!0},Tn.onMouseOut=function(e){return e.dragMoving&&this.fireUpdate(),!0},Tn.onTouchStart=Tn.onMouseDown=function(e,t){if(gB(t))return this.onVertex(e,t);if(lu(t))return this.onFeature(e,t);if(yB(t))return this.onMidpoint(e,t)},Tn.onDrag=function(e,t){if(e.canDragMove!==!0)return;e.dragMoving=!0,t.originalEvent.stopPropagation();const r={lng:t.lngLat.lng-e.dragMoveLocation.lng,lat:t.lngLat.lat-e.dragMoveLocation.lat};e.selectedCoordPaths.length>0?this.dragVertex(e,t,r):this.dragFeature(e,t,r),e.dragMoveLocation=t.lngLat},Tn.onClick=function(e,t){if(D0(t))return this.clickNoTarget(e,t);if(lu(t))return this.clickActiveFeature(e,t);if(eC(t))return this.clickInactive(e,t);this.stopDragging(e)},Tn.onTap=function(e,t){if(D0(t))return this.clickNoTarget(e,t);if(lu(t))return this.clickActiveFeature(e,t);if(eC(t))return this.clickInactive(e,t)},Tn.onTouchEnd=Tn.onMouseUp=function(e){e.dragMoving&&this.fireUpdate(),this.stopDragging(e)};const vo={};vo.onSetup=function(){const e=this.newFeature({type:yr.FEATURE,properties:{},geometry:{type:yr.POINT,coordinates:[]}});return this.addFeature(e),this.clearSelectedFeatures(),this.updateUIClasses({mouse:Vn.ADD}),this.activateUIButton(Ia.POINT),this.setActionableState({trash:!0}),{point:e}},vo.stopDrawingAndRemove=function(e){this.deleteFeature([e.point.id],{silent:!0}),this.changeMode(Vr.SIMPLE_SELECT)},vo.onTap=vo.onClick=function(e,t){this.updateUIClasses({mouse:Vn.MOVE}),e.point.updateCoordinate("",t.lngLat.lng,t.lngLat.lat),this.fire(la.CREATE,{features:[e.point.toGeoJSON()]}),this.changeMode(Vr.SIMPLE_SELECT,{featureIds:[e.point.id]})},vo.onStop=function(e){this.activateUIButton(),e.point.getCoordinate().length||this.deleteFeature([e.point.id],{silent:!0})},vo.toDisplayFeatures=function(e,t,r){const n=t.properties.id===e.point.id;if(t.properties.active=n?vi.ACTIVE:vi.INACTIVE,!n)return r(t)},vo.onTrash=vo.stopDrawingAndRemove,vo.onKeyUp=function(e,t){if(N0(t)||R0(t))return this.stopDrawingAndRemove(e,t)};function z0(e,t){return e.lngLat?e.lngLat.lng===t[0]&&e.lngLat.lat===t[1]:!1}const js={};js.onSetup=function(){const e=this.newFeature({type:yr.FEATURE,properties:{},geometry:{type:yr.POLYGON,coordinates:[[]]}});return this.addFeature(e),this.clearSelectedFeatures(),Bs.disable(this),this.updateUIClasses({mouse:Vn.ADD}),this.activateUIButton(Ia.POLYGON),this.setActionableState({trash:!0}),{polygon:e,currentVertexPosition:0}},js.clickAnywhere=function(e,t){if(e.currentVertexPosition>0&&z0(t,e.polygon.coordinates[0][e.currentVertexPosition-1]))return this.changeMode(Vr.SIMPLE_SELECT,{featureIds:[e.polygon.id]});this.updateUIClasses({mouse:Vn.ADD}),e.polygon.updateCoordinate(`0.${e.currentVertexPosition}`,t.lngLat.lng,t.lngLat.lat),e.currentVertexPosition++,e.polygon.updateCoordinate(`0.${e.currentVertexPosition}`,t.lngLat.lng,t.lngLat.lat)},js.clickOnVertex=function(e){return this.changeMode(Vr.SIMPLE_SELECT,{featureIds:[e.polygon.id]})},js.onMouseMove=function(e,t){e.polygon.updateCoordinate(`0.${e.currentVertexPosition}`,t.lngLat.lng,t.lngLat.lat),lm(t)&&this.updateUIClasses({mouse:Vn.POINTER})},js.onTap=js.onClick=function(e,t){return lm(t)?this.clickOnVertex(e,t):this.clickAnywhere(e,t)},js.onKeyUp=function(e,t){N0(t)?(this.deleteFeature([e.polygon.id],{silent:!0}),this.changeMode(Vr.SIMPLE_SELECT)):R0(t)&&this.changeMode(Vr.SIMPLE_SELECT,{featureIds:[e.polygon.id]})},js.onStop=function(e){this.updateUIClasses({mouse:Vn.NONE}),Bs.enable(this),this.activateUIButton(),this.getFeature(e.polygon.id)!==void 0&&(e.polygon.removeCoordinate(`0.${e.currentVertexPosition}`),e.polygon.isValid()?this.fire(la.CREATE,{features:[e.polygon.toGeoJSON()]}):(this.deleteFeature([e.polygon.id],{silent:!0}),this.changeMode(Vr.SIMPLE_SELECT,{},{silent:!0})))},js.toDisplayFeatures=function(e,t,r){const n=t.properties.id===e.polygon.id;if(t.properties.active=n?vi.ACTIVE:vi.INACTIVE,!n)return r(t);if(t.geometry.coordinates.length===0)return;const i=t.geometry.coordinates[0].length;if(!(i<3)){if(t.properties.meta=Hi.FEATURE,r(fd(e.polygon.id,t.geometry.coordinates[0][0],"0.0",!1)),i>3){const s=t.geometry.coordinates[0].length-3;r(fd(e.polygon.id,t.geometry.coordinates[0][s],`0.${s}`,!1))}if(i<=4){const s=[[t.geometry.coordinates[0][0][0],t.geometry.coordinates[0][0][1]],[t.geometry.coordinates[0][1][0],t.geometry.coordinates[0][1][1]]];if(r({type:yr.FEATURE,properties:t.properties,geometry:{coordinates:s,type:yr.LINE_STRING}}),i===3)return}return r(t)}},js.onTrash=function(e){this.deleteFeature([e.polygon.id],{silent:!0}),this.changeMode(Vr.SIMPLE_SELECT)};const Fs={};Fs.onSetup=function(e){e=e||{};const t=e.featureId;let r,n,i="forward";if(t){if(r=this.getFeature(t),!r)throw new Error("Could not find a feature with the provided featureId");let s=e.from;if(s&&s.type==="Feature"&&s.geometry&&s.geometry.type==="Point"&&(s=s.geometry),s&&s.type==="Point"&&s.coordinates&&s.coordinates.length===2&&(s=s.coordinates),!s||!Array.isArray(s))throw new Error("Please use the `from` property to indicate which point to continue the line from");const c=r.coordinates.length-1;if(r.coordinates[c][0]===s[0]&&r.coordinates[c][1]===s[1])n=c+1,r.addCoordinate(n,...r.coordinates[c]);else if(r.coordinates[0][0]===s[0]&&r.coordinates[0][1]===s[1])i="backwards",n=0,r.addCoordinate(n,...r.coordinates[0]);else throw new Error("`from` should match the point at either the start or the end of the provided LineString")}else r=this.newFeature({type:yr.FEATURE,properties:{},geometry:{type:yr.LINE_STRING,coordinates:[]}}),n=0,this.addFeature(r);return this.clearSelectedFeatures(),Bs.disable(this),this.updateUIClasses({mouse:Vn.ADD}),this.activateUIButton(Ia.LINE),this.setActionableState({trash:!0}),{line:r,currentVertexPosition:n,direction:i}},Fs.clickAnywhere=function(e,t){if(e.currentVertexPosition>0&&z0(t,e.line.coordinates[e.currentVertexPosition-1])||e.direction==="backwards"&&z0(t,e.line.coordinates[e.currentVertexPosition+1]))return this.changeMode(Vr.SIMPLE_SELECT,{featureIds:[e.line.id]});this.updateUIClasses({mouse:Vn.ADD}),e.line.updateCoordinate(e.currentVertexPosition,t.lngLat.lng,t.lngLat.lat),e.direction==="forward"?(e.currentVertexPosition++,e.line.updateCoordinate(e.currentVertexPosition,t.lngLat.lng,t.lngLat.lat)):e.line.addCoordinate(0,t.lngLat.lng,t.lngLat.lat)},Fs.clickOnVertex=function(e){return this.changeMode(Vr.SIMPLE_SELECT,{featureIds:[e.line.id]})},Fs.onMouseMove=function(e,t){e.line.updateCoordinate(e.currentVertexPosition,t.lngLat.lng,t.lngLat.lat),lm(t)&&this.updateUIClasses({mouse:Vn.POINTER})},Fs.onTap=Fs.onClick=function(e,t){if(lm(t))return this.clickOnVertex(e,t);this.clickAnywhere(e,t)},Fs.onKeyUp=function(e,t){R0(t)?this.changeMode(Vr.SIMPLE_SELECT,{featureIds:[e.line.id]}):N0(t)&&(this.deleteFeature([e.line.id],{silent:!0}),this.changeMode(Vr.SIMPLE_SELECT))},Fs.onStop=function(e){Bs.enable(this),this.activateUIButton(),this.getFeature(e.line.id)!==void 0&&(e.line.removeCoordinate(`${e.currentVertexPosition}`),e.line.isValid()?this.fire(la.CREATE,{features:[e.line.toGeoJSON()]}):(this.deleteFeature([e.line.id],{silent:!0}),this.changeMode(Vr.SIMPLE_SELECT,{},{silent:!0})))},Fs.onTrash=function(e){this.deleteFeature([e.line.id],{silent:!0}),this.changeMode(Vr.SIMPLE_SELECT)},Fs.toDisplayFeatures=function(e,t,r){const n=t.properties.id===e.line.id;if(t.properties.active=n?vi.ACTIVE:vi.INACTIVE,!n)return r(t);t.geometry.coordinates.length<2||(t.properties.meta=Hi.FEATURE,r(fd(e.line.id,t.geometry.coordinates[e.direction==="forward"?t.geometry.coordinates.length-2:1],`${e.direction==="forward"?t.geometry.coordinates.length-2:1}`,!1)),r(t))};const vB={simple_select:An,direct_select:Tn,draw_point:vo,draw_polygon:js,draw_line_string:Fs},XEe={defaultMode:Vr.SIMPLE_SELECT,keybindings:!0,touchEnabled:!0,clickBuffer:2,touchBuffer:25,boxSelect:!0,displayControlsDefault:!0,styles:cB,modes:vB,controls:{},userProperties:!1,suppressAPIEvents:!0},ZEe={point:!0,line_string:!0,polygon:!0,trash:!0,combine_features:!0,uncombine_features:!0},YEe={point:!1,line_string:!1,polygon:!1,trash:!1,combine_features:!1,uncombine_features:!1};function bB(e,t){return e.map(r=>r.source?r:Object.assign({},r,{id:`${r.id}.${t}`,source:t==="hot"?ys.HOT:ys.COLD}))}function qEe(e={}){let t=Object.assign({},e);return e.controls||(t.controls={}),e.displayControlsDefault===!1?t.controls=Object.assign({},YEe,e.controls):t.controls=Object.assign({},ZEe,e.controls),t=Object.assign({},XEe,t),t.styles=bB(t.styles,"cold").concat(bB(t.styles,"hot")),t}var JEe=QEe,KEe={Point:"geometry",MultiPoint:"geometry",LineString:"geometry",MultiLineString:"geometry",Polygon:"geometry",MultiPolygon:"geometry",GeometryCollection:"geometry",Feature:"feature",FeatureCollection:"featurecollection"};function QEe(e){if(!e||!e.type)return null;var t=KEe[e.type];if(!t)return null;if(t==="geometry")return{type:"FeatureCollection",features:[{type:"Feature",properties:{},geometry:e}]};if(t==="feature")return{type:"FeatureCollection",features:[e]};if(t==="featurecollection")return e}const eAe=Qr(JEe);function xB(e,t){return e.length!==t.length?!1:JSON.stringify(e.map(r=>r).sort())===JSON.stringify(t.map(r=>r).sort())}const tAe={Polygon:Wa,LineString:yo,Point:Jl,MultiPolygon:ua,MultiLineString:ua,MultiPoint:ua};function rAe(e,t){t.modes=Vr;const r=e.options.suppressAPIEvents!==void 0?!!e.options.suppressAPIEvents:!0;return t.getFeatureIdsAt=function(n){return dd.click({point:n},null,e).map(s=>s.properties.id)},t.getSelectedIds=function(){return e.store.getSelectedIds()},t.getSelected=function(){return{type:yr.FEATURE_COLLECTION,features:e.store.getSelectedIds().map(n=>e.store.get(n)).map(n=>n.toGeoJSON())}},t.getSelectedPoints=function(){return{type:yr.FEATURE_COLLECTION,features:e.store.getSelectedCoordinates().map(n=>({type:yr.FEATURE,properties:{},geometry:{type:yr.POINT,coordinates:n.coordinates}}))}},t.set=function(n){if(n.type===void 0||n.type!==yr.FEATURE_COLLECTION||!Array.isArray(n.features))throw new Error("Invalid FeatureCollection");const i=e.store.createRenderBatch();let s=e.store.getAllIds().slice();const c=t.add(n),a=new vs(c);return s=s.filter(d=>!a.has(d)),s.length&&t.delete(s),i(),c},t.add=function(n){const s=JSON.parse(JSON.stringify(eAe(n))).features.map(c=>{if(c.id=c.id||KS(),c.geometry===null)throw new Error("Invalid geometry: null");if(e.store.get(c.id)===void 0||e.store.get(c.id).type!==c.geometry.type){const a=tAe[c.geometry.type];if(a===void 0)throw new Error(`Invalid geometry type: ${c.geometry.type}.`);const d=new a(e,c);e.store.add(d,{silent:r})}else{const a=e.store.get(c.id),d=a.properties;a.properties=c.properties,YP(d,c.properties)||e.store.featureChanged(a.id,{silent:r}),YP(a.getCoordinates(),c.geometry.coordinates)||a.incomingCoords(c.geometry.coordinates)}return c.id});return e.store.render(),s},t.get=function(n){const i=e.store.get(n);if(i)return i.toGeoJSON()},t.getAll=function(){return{type:yr.FEATURE_COLLECTION,features:e.store.getAll().map(n=>n.toGeoJSON())}},t.delete=function(n){return e.store.delete(n,{silent:r}),t.getMode()===Vr.DIRECT_SELECT&&!e.store.getSelectedIds().length?e.events.changeMode(Vr.SIMPLE_SELECT,void 0,{silent:r}):e.store.render(),t},t.deleteAll=function(){return e.store.delete(e.store.getAllIds(),{silent:r}),t.getMode()===Vr.DIRECT_SELECT?e.events.changeMode(Vr.SIMPLE_SELECT,void 0,{silent:r}):e.store.render(),t},t.changeMode=function(n,i={}){return n===Vr.SIMPLE_SELECT&&t.getMode()===Vr.SIMPLE_SELECT?(xB(i.featureIds||[],e.store.getSelectedIds())||(e.store.setSelected(i.featureIds,{silent:r}),e.store.render()),t):(n===Vr.DIRECT_SELECT&&t.getMode()===Vr.DIRECT_SELECT&&i.featureId===e.store.getSelectedIds()[0]||e.events.changeMode(n,i,{silent:r}),t)},t.getMode=function(){return e.events.getMode()},t.trash=function(){return e.events.trash({silent:r}),t},t.combineFeatures=function(){return e.events.combineFeatures({silent:r}),t},t.uncombineFeatures=function(){return e.events.uncombineFeatures({silent:r}),t},t.setFeatureProperty=function(n,i,s){return e.store.setFeatureProperty(n,i,s,{silent:r}),t},t}const nAe=Object.freeze(Object.defineProperty({__proto__:null,CommonSelectors:HEe,ModeHandler:VS,StringSet:vs,constrainFeatureMovement:nC,createMidPoint:hB,createSupplementaryPoints:B0,createVertex:fd,doubleClickZoom:Bs,euclideanDistance:YS,featuresAt:dd,getFeatureAtAndSetCursors:P0,isClick:qS,isEventAtCoordinates:z0,isTap:JS,mapEventToBoundingBox:iB,moveFeatures:iC,sortFeatures:nB,stringSetsAreEqual:xB,theme:cB,toDenseArray:sm},Symbol.toStringTag,{value:"Module"})),iAe=function(e,t){e=qEe(e);const r={options:e};t=rAe(r,t),r.api=t;const n=VEe(r);return t.onAdd=n.onAdd,t.onRemove=n.onRemove,t.types=Ia,t.options=e,t};function pd(e){iAe(e,this)}pd.modes=vB,pd.constants=tB,pd.lib=nAe;function aAe(){const{drawRef:e}=U.useContext(zi),t=pd.constants;t.classes.CONTROL_BASE="maplibregl-ctrl",t.classes.CONTROL_PREFIX="maplibregl-ctrl-",t.classes.CONTROL_GROUP="maplibregl-ctrl-group";const r=U.useCallback(i=>{console.log("onCreate")},[]),n=r;return Wu(()=>{const i=new pd({displayControlsDefault:!1,styles:[{id:"gl-draw-polygon-fill",type:"fill",filter:["all",["==","$type","Polygon"],["!=","mode","static"]],paint:{"fill-color":"#FF0000","fill-opacity":.5}},{id:"gl-draw-line-active",type:"line",filter:["all",["==","$type","LineString"],["==","active","true"]],layout:{"line-cap":"round","line-join":"round"},paint:{"line-color":"#FF0000","line-width":3,"line-dasharray":[2,2]}},{id:"gl-draw-polygon-stroke-active",type:"line",filter:["all",["==","$type","Polygon"],["!=","mode","static"]],layout:{"line-cap":"round","line-join":"round"},paint:{"line-color":"#0000FF","line-width":2}},{id:"gl-draw-polygon-midpoint",type:"circle",filter:["all",["==","meta","midpoint"]],paint:{"circle-radius":5,"circle-color":"#00FF00"}},{id:"gl-draw-polygon-vertex",type:"circle",filter:["all",["==","meta","vertex"],["==","$type","Point"]],paint:{"circle-radius":7,"circle-color":"#FFA500"}},{id:"gl-draw-polygon-point-active",type:"circle",filter:["all",["==","active","true"],["==","$type","Point"]],paint:{"circle-radius":10,"circle-color":"red"}}]});return e.current=i,i},({map:i})=>{i.on("draw.create",r),i.on("draw.update",n)},({map:i})=>{i.off("draw.create",r),i.off("draw.update",n)},{position:"top-right"}),null}const sAe=()=>{const e=$t(n=>n.viewMode),t=$t(n=>n.cursorCords),r=$t(n=>n.hoveredValue);return X.jsxs("div",{className:"absolute bottom-0 left-0 w-full bg-black bg-opacity-50 p-1 text-xs text-white flex justify-between",children:[X.jsxs("span",{children:["mode: ",e]}),X.jsxs("span",{children:[r&&X.jsxs("span",{children:[X.jsxs("span",{children:[r.label,":",(r==null?void 0:r.value)&&r.value]}),X.jsx("div",{style:{width:10,height:10,backgroundColor:r.color,display:"inline-block"}})]})," ",X.jsx("span",{children:`${t[0].toFixed(6)}, ${t[1].toFixed(6)}`})]})]})};var aC="Tabs",[oAe,qPe]=ko(aC,[Ng]),_B=Ng(),[lAe,sC]=oAe(aC),wB=Ae.forwardRef((e,t)=>{const{__scopeTabs:r,value:n,onValueChange:i,defaultValue:s,orientation:c="horizontal",dir:a,activationMode:d="automatic",...p}=e,y=Xx(a),[g,v]=Ju({prop:n,onChange:i,defaultProp:s});return X.jsx(lAe,{scope:r,baseId:Ic(),value:g,onValueChange:v,orientation:c,dir:y,activationMode:d,children:X.jsx(In.div,{dir:y,"data-orientation":c,...p,ref:t})})});wB.displayName=aC;var SB="TabsList",CB=Ae.forwardRef((e,t)=>{const{__scopeTabs:r,loop:n=!0,...i}=e,s=sC(SB,r),c=_B(r);return X.jsx(kA,{asChild:!0,...c,orientation:s.orientation,dir:s.dir,loop:n,children:X.jsx(In.div,{role:"tablist","aria-orientation":s.orientation,...i,ref:t})})});CB.displayName=SB;var MB="TabsTrigger",EB=Ae.forwardRef((e,t)=>{const{__scopeTabs:r,value:n,disabled:i=!1,...s}=e,c=sC(MB,r),a=_B(r),d=IB(c.baseId,n),p=PB(c.baseId,n),y=n===c.value;return X.jsx(DA,{asChild:!0,...a,focusable:!i,active:y,children:X.jsx(In.button,{type:"button",role:"tab","aria-selected":y,"aria-controls":p,"data-state":y?"active":"inactive","data-disabled":i?"":void 0,disabled:i,id:d,...s,ref:t,onMouseDown:an(e.onMouseDown,g=>{!i&&g.button===0&&g.ctrlKey===!1?c.onValueChange(n):g.preventDefault()}),onKeyDown:an(e.onKeyDown,g=>{[" ","Enter"].includes(g.key)&&c.onValueChange(n)}),onFocus:an(e.onFocus,()=>{const g=c.activationMode!=="manual";!y&&!i&&g&&c.onValueChange(n)})})})});EB.displayName=MB;var AB="TabsContent",TB=Ae.forwardRef((e,t)=>{const{__scopeTabs:r,value:n,forceMount:i,children:s,...c}=e,a=sC(AB,r),d=IB(a.baseId,n),p=PB(a.baseId,n),y=n===a.value,g=Ae.useRef(y);return Ae.useEffect(()=>{const v=requestAnimationFrame(()=>g.current=!1);return()=>cancelAnimationFrame(v)},[]),X.jsx(qs,{present:i||y,children:({present:v})=>X.jsx(In.div,{"data-state":y?"active":"inactive","data-orientation":a.orientation,role:"tabpanel","aria-labelledby":d,hidden:!v,id:p,tabIndex:0,...c,ref:t,style:{...e.style,animationDuration:g.current?"0s":void 0},children:v&&s})})});TB.displayName=AB;function IB(e,t){return`${e}-trigger-${t}`}function PB(e,t){return`${e}-content-${t}`}var cAe=wB,OB=CB,kB=EB,DB=TB;const uAe=cAe,LB=Ae.forwardRef(({className:e,...t},r)=>X.jsx(OB,{ref:r,className:Nr("inline-flex h-10 items-center justify-center rounded-md bg-muted p-1 text-muted-foreground",e),...t}));LB.displayName=OB.displayName;const oC=Ae.forwardRef(({className:e,...t},r)=>X.jsx(kB,{ref:r,className:Nr("inline-flex items-center justify-center whitespace-nowrap rounded-sm px-3 py-1.5 text-sm font-medium ring-offset-background transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:bg-background data-[state=active]:text-foreground data-[state=active]:shadow-sm",e),...t}));oC.displayName=kB.displayName;const NB=Ae.forwardRef(({className:e,...t},r)=>X.jsx(DB,{ref:r,className:Nr("mt-2 ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",e),...t}));NB.displayName=DB.displayName;function RB({value:e,children:t}){return X.jsx(NB,{value:e,children:t})}rr.arrayOf(rr.shape({id:rr.string.isRequired,title:rr.string.isRequired,icon:rr.node,content:rr.node.isRequired,tooltipText:rr.string})).isRequired,rr.string.isRequired,rr.func,rr.func;function hAe(e){return kc({tag:"svg",attr:{viewBox:"0 0 576 512"},child:[{tag:"path",attr:{d:"M565.6 36.2C572.1 40.7 576 48.1 576 56l0 336c0 10-6.2 18.9-15.5 22.4l-168 64c-5.2 2-10.9 2.1-16.1 .3L192.5 417.5l-160 61c-7.4 2.8-15.7 1.8-22.2-2.7S0 463.9 0 456L0 120c0-10 6.1-18.9 15.5-22.4l168-64c5.2-2 10.9-2.1 16.1-.3L383.5 94.5l160-61c7.4-2.8 15.7-1.8 22.2 2.7zM48 136.5l0 284.6 120-45.7 0-284.6L48 136.5zM360 422.7l0-285.4-144-48 0 285.4 144 48zm48-1.5l120-45.7 0-284.6L408 136.5l0 284.6z"},child:[]}]})(e)}function dAe(e){return kc({tag:"svg",attr:{fill:"none",viewBox:"0 0 24 24",strokeWidth:"1.5",stroke:"currentColor","aria-hidden":"true"},child:[{tag:"path",attr:{strokeLinecap:"round",strokeLinejoin:"round",d:"M15 10.5a3 3 0 1 1-6 0 3 3 0 0 1 6 0Z"},child:[]},{tag:"path",attr:{strokeLinecap:"round",strokeLinejoin:"round",d:"M19.5 10.5c0 7.142-7.5 11.25-7.5 11.25S4.5 17.642 4.5 10.5a7.5 7.5 0 1 1 15 0Z"},child:[]}]})(e)}function fAe(){const e=$t(g=>g.pickerData),t=$t(g=>g.setPickerData),r=$t(g=>g.rasterLayer),[n,i]=U.useState(null),[s,c]=U.useState(!1),[a,d]=U.useState(null),p=e==null?void 0:e.dateRange;console.log("inside area details picker",p);function y(g){console.log("getting value"),c(!0),i(null),d(null);const v=g.coordinates;console.log("coordinates are",v);const w=1e-6,S=[v.lng-w,v.lat-w,v.lng+w,v.lat+w].join(","),C="https://d27s6pvwcjpmsu.cloudfront.net/geoserver/ne/wms",M=new URLSearchParams({service:"WMS",version:"1.1.1",request:"GetFeatureInfo",layers:"ne:et_data",query_layers:"ne:et_data",bbox:S,width:1,height:1,srs:"EPSG:4326",time:(p==null?void 0:p.start.toISOString().split("T")[0])||void 0,info_format:"application/json",x:0,y:0}),I=`${C}?${M.toString()}`;return fetch(I).then(E=>(console.log("response is",E),E.json())).then(E=>{var O,N,D,L,R;console.log("Received coverage data for point:",E),console.log("Data:",E,typeof E),((O=E==null?void 0:E.features)==null?void 0:O.length)>0&&(console.log("Value is",(D=(N=E==null?void 0:E.features[0])==null?void 0:N.properties)==null?void 0:D.GRAY_INDEX),i((R=(L=E==null?void 0:E.features[0])==null?void 0:L.properties)==null?void 0:R.GRAY_INDEX))}).catch(E=>(console.error("There was a problem with the fetch operation:",E.message),i(void 0),d("could not load ET value at point"),null)).finally(()=>{c(!1)})}return U.useEffect(()=>{console.log("pickerData",e),e&&r.value==="ET"&&y(e)},[e,r]),U.useEffect(()=>{e&&r.value==="ET"&&y(e)},[p]),e?X.jsx(X.Fragment,{children:X.jsx(Fo,{open:!0,setOpen:()=>t(null),title:"Area Details",headerClassName:"m-4",children:X.jsxs(uAe,{className:"flex flex-col w-full h-full overflow-y-hidden",defaultValue:"point",children:[X.jsxs(LB,{className:"grid w-full grid-cols-2","aria-label":"Manage your account",children:[X.jsxs(oC,{value:"point",children:[X.jsx(dAe,{className:"cursor-pointer"})," ",X.jsx("span",{children:"Point"})]}),(e==null?void 0:e.plot)&&X.jsxs(oC,{value:"plot",tooltipText:"Plot",children:[X.jsx(hAe,{className:"cursor-pointer"})," ",X.jsx("span",{children:"Plot"})]})]}),X.jsx("br",{}),X.jsxs(RB,{value:"point",children:[r.value==="3_NDVI"&&X.jsx(zS,{point:e.coordinates}),s?X.jsx(Ra,{}):a?X.jsx("div",{className:"text-red ",children:"Could not load ET value"}):n&&X.jsxs("div",{className:"flex items-center justify-between w-full gap-2 rounded-md bg-zinc-100 dark:bg-zinc-800 p-2 ",children:[X.jsxs("h4",{className:"scroll-m-20 text-xs font-medium tracking-tight",children:["ET value at this point (",e.dateRange.start.toISOString().split("T")[0],")"]}),X.jsx("div",{className:"flex items-center space-x-2",children:X.jsx("span",{className:"text-xs text-gray-700 dark:text-gray-200 font-bold",children:n.toFixed(3)})})]})]}),(e==null?void 0:e.plot)&&X.jsx(RB,{value:"plot",children:X.jsx(zS,{plot:e.plot})})]})})}):null}(lj=$t.getState().configs)==null||lj.VITE_SENTINAL_HUB_WMTS_ID;function BB({layer:e,dateRange:t}){var a;const n=`https://services.sentinel-hub.com/ogc/wmts/${(a=$t.getState().configs)==null?void 0:a.VITE_SENTINAL_HUB_WMTS_ID}?TILEMATRIXSET=PopularWebMercator256&Service=WMTS&Request=GetTile&RESOLUTION=10&MAXCC=20&TileMatrix={z}&TileCol={x}&TileRow={y}&FORMAT=image/png`;if(console.log("dateRange",t),!e||!t||!(t!=null&&t.start))return null;t.start instanceof Date&&(t.start=t.start.toISOString().split("T")[0]),t.end instanceof Date&&(t.end=t.end.toISOString().split("T")[0]);const i=`${t.start}/${t.end}`,s=pg.find(d=>d.value===e);return s&&(s!=null&&s.url)?`${s.url}&TIME=${i}`:`${n}&LAYER=${e}&TIME=${i}`}const jB=({mapRef:e,dateRange:t})=>{var w;const{isVisible:r}=U.useContext(Hf),n=$t(S=>S.showCroppedImages);console.log("uuu daterange inside NDVI layre",t);const i=$t(S=>S.rasterLayer),[s,c]=U.useState(BB({layer:i.value,dateRange:{...t}})),[a,d]=U.useState(null),p=$t(S=>S.rasterOpacity),y=e==null?void 0:e.current,g=(w=e==null?void 0:e.current)==null?void 0:w.getMap();U.useEffect(()=>{console.log("uuu dateRange in useEffect layerUrl",t);const S=BB({layer:i.value,dateRange:{...t}});console.log("uuu url has changed",S),c(S)},[i,t]),U.useEffect(()=>{console.log("uuu dateRnage has changeed",t)},[t]),U.useEffect(()=>{y&&(y!=null&&y.loaded())&&y.getLayer("plots-line-layer")?(console.log("order setting before id to plots-line-layer"),d("plots-line-layer")):(console.log("order setting before id to plots-line-layer"),d(null))},[y]);const v=U.useCallback(S=>{console.log("croppp handleLayerOrder");const C=g.getLayersOrder();console.log("layers",C),g.getLayer("plots-line-layer")&&g.getLayer("raster-layer")&&C.indexOf("plots-line-layer")<C.indexOf("raster-layer")&&(console.log("reordering layers"),g.moveLayer("raster-layer","plots-line-layer"))},[y]);return U.useEffect(()=>(g&&g.on("style.load",v),()=>{g&&g.off("style.load",v)}),[y]),s?X.jsx(X.Fragment,{children:r&&!n&&X.jsx(hE,{id:"raster-source",type:"raster",tiles:[s],tileSize:256,minzoom:10,maxzoom:21,children:X.jsx(gx,{id:"raster-layer",type:"raster",source:"raster-source",paint:{"raster-opacity":p/100},beforeId:a||void 0})})}):null},pAe=[{color:"#ffffcc",label:"Bare Soil"},{color:"#c7e9b4",label:"Low Vegetation"},{color:"#7fcdbb",label:"Moderate Vegetation"},{color:"#41b6c4",label:"Healthy Vegetation"},{color:"#1d91c0",label:"Very Healthy Vegetation"},{color:"#225ea8",label:"Dense Vegetation"},{color:"#0c2c84",label:"Water Bodies"}],mAe=[{color:"#f8d5cc",label:"Bare Soil"},{color:"#d73027",label:"Low Vegetation"},{color:"#f46d43",label:"Sparse Vegetation"},{color:"#66bd63",label:"Moderate Vegetation"},{color:"#1a9850",label:"Healthy Vegetation"},{color:"#542788",label:"Water"}],gAe=[{color:"#a50026",label:"Very Dry"},{color:"#d73027",label:"Dry"},{color:"#f46d43",label:"Moderate Moisture"},{color:"#fdae61",label:"High Moisture"},{color:"#fee08b",label:"Very High Moisture"},{color:"#d9ef8b",label:"Saturated"},{color:"#66bd63",label:"Water Body"}],FB=()=>{const e=$t(a=>a.rasterLayer),t=$t(a=>a.pixelColor),r=Zn(),n=[{color:"#004400",label:` (${r.formatNumber(.5)} to ${r.formatNumber(1)})`},{color:"#0f540a",label:` (${r.formatNumber(.4)} to ${r.formatNumber(.5)})`},{color:"#3f7c23",label:` (${r.formatNumber(.25)} to ${r.formatNumber(.3)})`},{color:"#bcb76b",label:` (${r.formatNumber(-.1)} to ${r.formatNumber(0)})`},{color:"#fff9cc",label:` (${r.formatNumber(-.35)} to ${r.formatNumber(-.3)})`},{color:"#c0c0c0",label:` (${r.formatNumber(-.7)} to ${r.formatNumber(-.6)})`},{color:"#0c0c0c",label:` (${r.formatNumber(-1)} to ${r.formatNumber(-.7)})`}],i=[{color:"#00008B",label:`Very Low (${r.formatNumber(.001)})`},{color:"#0000FF",label:`Low (${r.formatNumber(3)})`},{color:"#00FF00",label:`Moderate (${r.formatNumber(6)})`},{color:"#FFA500",label:`High (${r.formatNumber(9)})`},{color:"#FF0000",label:`Very High (${r.formatNumber(12)})`}];console.log("colorLegend rasterLayer",e);let s;switch(e==null?void 0:e.value){case"3_NDVI":s=n;break;case"AGRICULTURE":s=pAe;break;case"2_FALSE_COLOR":s=mAe;break;case"5-MOISTURE-INDEX1":s=gAe;break;case"ET":s=i}if(!s)return null;const c=s.find(a=>a.color==t);return console.log("item",c),X.jsxs("div",{className:"legend",children:[X.jsx("h4",{className:"mb-2",children:e==null?void 0:e.label}),s.map((a,d)=>X.jsxs("div",{className:"legend-item",style:{fontSize:"1.4em"},children:[X.jsx("span",{className:"legend-color",style:{backgroundColor:a.color}}),X.jsx("span",{children:a.label})]},d))]})};function zB(e){const[t,r,n]=e,i=Math.round(t).toString(16).padStart(2,"0"),s=Math.round(r).toString(16).padStart(2,"0"),c=Math.round(n).toString(16).padStart(2,"0");return`#${i}${s}${c}`}function yAe(e,t){return e==="NDVI_RAW"?{label:"NDVI",value:(t[1]/127.5-1).toFixed(2),color:zB(t)}:{label:"color",value:null,color:zB(t)}}function $B({dateRange:e,mapRef:t,showButton:r=!0}){var E;console.log("ppp mapRef",t);const n=(E=t==null?void 0:t.current)==null?void 0:E.getMap(),i=$t(O=>O.viewMode);$t(O=>O.mapMode);const s=$t(O=>O.toggleNormalPickerMode),c=$t(O=>O.toNormalMode),a=$t(O=>O.setPickerData),d=$t(O=>O.setCursorCords),p=$t(O=>O.setHoveredValue),y=$t(O=>O.rasterLayer),g=$t(O=>O.setCursor),v=$t(O=>O.resetCursor),w=Zn(),S=$t(O=>O.rasterOpacity),C=$t(O=>O.setRasterOpacity),M=U.useCallback(()=>{console.log("back to currentOpacity",S),C(100)},[S,C]),I=O=>{n&&(i==="PICKER"?n.setPaintProperty("raster-layer","raster-opacity",1):M()),s()};return U.useEffect(()=>{const O=N=>{N.key==="Escape"&&(M(),c())};return i==="PICKER"&&window.addEventListener("keydown",O),()=>{window.removeEventListener("keydown",O)}},[c,S,n,M,i]),U.useEffect(()=>{if(console.log("eee event",n,i),!n||i!=="PICKER")return;const O=N=>{console.log("eee clicked on map",e);let D={coordinates:N.lngLat,dateRange:e};if(n.getLayer("plots-layer")){const L=n.queryRenderedFeatures(N.point,{layers:["plots-layer"]});L.length>0&&(D.plot=L[0])}console.log("setting picker data",D),a(D)};return console.log("added event handler"),n.on("click",O),()=>{n.off("click",O)}},[n,i,e,a]),U.useEffect(()=>{const O=N=>{const{lng:D,lat:L}=N.lngLat;d([D,L])};return n&&n.on("mousemove",O),()=>{n&&n.off("mousemove",O)}},[n,d,i]),U.useEffect(()=>{const N=Wf(D=>{const L=n.getCanvas(),R=n.painter.context.gl;if(!R){console.error("WebGL context is not available.");return}const Y=new Uint8Array(4),ie=window.devicePixelRatio||1,re=Math.floor(D.point.x*ie),V=Math.floor(L.height-D.point.y*ie);if(re<0||V<0||re>=L.width||V>=L.height){console.warn("Mouse is outside the canvas bounds");return}R.readPixels(re,V,1,1,R.RGBA,R.UNSIGNED_BYTE,Y);const Z=yAe(y==null?void 0:y.value,Y);p(Z)},100);return n&&i==="PICKER"&&(n!=null&&n.loaded)&&(console.log("Adding pixel event listener"),n.on("mousemove",N)),()=>{n&&n.off("mousemove",N)}},[n,i,p,y]),U.useEffect(()=>{i==="PICKER"?g("crosshair"):v()},[i]),r?X.jsx(Fr,{variant:"outline",size:"icon",title:w.formatMessage({id:"app.agviewer_map.activate_picker_mode",defaultMessage:"Activate picker mode"}),"aria-label":w.formatMessage({id:"app.agviewer_map.activate_picker_mode",defaultMessage:"Activate picker mode"}),onClick:I,className:` ${i===Ur.PICKER?" bg-gray-200 dark:bg-gray-600":""}`,children:X.jsx(gz,{})}):null}function GB({dateRange:e,mapRef:t}){const{current:r}=yg(),[n,i]=U.useState(!1);U.useRef(null);const{settings:s,setSettings:c}=U.useContext(of),[a,d]=U.useState(!1),p=$t(I=>I.setViewMode),y=$t(I=>I.viewMode),g=$t(I=>I.mapMode),v=$t(I=>I.setMapMode),w=Zn(),S=()=>{g==La.COMPARISION_VIEW?v(La.NORMAL):v(La.COMPARISION_VIEW)},C=U.useCallback(()=>{i(I=>!I),c(I=>({...I,basemap:{...I.basemap,id:I.basemap.id==="basic"?"satellite":"basic"}}))},[c]),M=U.useCallback(()=>{if(!r)return;const E=r.getContainer().parentNode;document.fullscreenElement?(document.exitFullscreen(),d(!1)):E.requestFullscreen?E.requestFullscreen():E.mozRequestFullScreen?E.mozRequestFullScreen():E.webkitRequestFullscreen?E.webkitRequestFullscreen():E.msRequestFullscreen&&E.msRequestFullscreen(),d(!0)},[r]);return y===Ur.ADD_PLOT||y===Ur.ADD_MARKER||y===Ur.EDIT_PLOT||y===Ur.EDIT_MARKER?null:(U.useEffect(()=>{console.log("daterange has changed in side mapControl eee",e)},[e]),X.jsx(X.Fragment,{children:X.jsxs("div",{className:" gap-1 flex flex-col",children:[r&&X.jsx(Fr,{variant:"outline",size:"icon","aria-label":"Change view mode",title:w.formatMessage({id:"app.agviewer_map.change_view_mode",defaultMessage:"Change view mode"}),onClick:C,children:s.basemap.id==="basic"?X.jsx(yz,{}):X.jsx(uz,{})}),X.jsx(Fr,{variant:"outline",size:"icon",onClick:M,children:a?X.jsx(dz,{}):X.jsx(hz,{})}),X.jsx(Fr,{variant:"outline",size:"icon",onClick:S,children:g===La.COMPARISION_VIEW?X.jsx(vz,{}):X.jsx(bz,{})}),X.jsx($B,{dateRange:e,mapRef:t}),g!==La.COMPARISION_VIEW&&X.jsxs(X.Fragment,{children:[X.jsx(Fr,{variant:"outline",size:"icon",title:w.formatMessage({id:"app.agviewer_map.add_view_plot",defaultMessage:"Add new plot"}),onClick:()=>p(Ur.ADD_PLOT),children:X.jsx(cz,{})}),X.jsx(Fr,{variant:"outline",size:"icon",title:w.formatMessage({id:"app.agviewer_map.add_new_station",defaultMessage:"Add new station"}),onClick:()=>p(Ur.ADD_MARKER),children:X.jsx(mz,{})}),X.jsx(Fr,{variant:"outline",size:"icon",title:w.formatMessage({id:"app.agviewer_map.add_new_farm_title",defaultMessage:"Add new farm"}),onClick:()=>p(y===Ur.ADD_NEW_FARM?Ur.NORMAL:Ur.ADD_NEW_FARM),children:X.jsx(xz,{})})]})]})}))}const lC=768;function vAe(){const[e,t]=Ae.useState(void 0);return Ae.useEffect(()=>{const r=window.matchMedia(`(max-width: ${lC-1}px)`),n=()=>{t(window.innerWidth<lC)};return r.addEventListener("change",n),t(window.innerWidth<lC),()=>r.removeEventListener("change",n)},[]),!!e}const VB=Ae.forwardRef(({className:e,type:t,...r},n)=>X.jsx("input",{type:t,className:Nr("flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-base ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",e),ref:n,...r}));VB.displayName="Input";var bAe="Separator",WB="horizontal",xAe=["horizontal","vertical"],HB=Ae.forwardRef((e,t)=>{const{decorative:r,orientation:n=WB,...i}=e,s=_Ae(n)?n:WB,a=r?{role:"none"}:{"aria-orientation":s==="vertical"?s:void 0,role:"separator"};return X.jsx(In.div,{"data-orientation":s,...a,...i,ref:t})});HB.displayName=bAe;function _Ae(e){return xAe.includes(e)}var UB=HB;const XB=Ae.forwardRef(({className:e,orientation:t="horizontal",decorative:r=!0,...n},i)=>X.jsx(UB,{ref:i,decorative:r,orientation:t,className:Nr("shrink-0 bg-border",t==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",e),...n}));XB.displayName=UB.displayName;const wAe=s_,SAe=o_,ZB=Ae.forwardRef(({className:e,...t},r)=>X.jsx(my,{className:Nr("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",e),...t,ref:r}));ZB.displayName=my.displayName;const CAe=C1("fixed z-50 gap-4 bg-background p-6 shadow-lg transition ease-in-out data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:duration-300 data-[state=open]:duration-500",{variants:{side:{top:"inset-x-0 top-0 border-b data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top",bottom:"inset-x-0 bottom-0 border-t data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom",left:"inset-y-0 left-0 h-full w-3/4 border-r data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left sm:max-w-sm",right:"inset-y-0 right-0 h-full w-3/4 border-l data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right sm:max-w-sm"}},defaultVariants:{side:"right"}}),YB=Ae.forwardRef(({side:e="right",className:t,children:r,...n},i)=>X.jsxs(SAe,{children:[X.jsx(ZB,{}),X.jsxs(gy,{ref:i,className:Nr(CAe({side:e}),t),...n,children:[r,X.jsxs(l_,{className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-secondary",children:[X.jsx(El,{className:"h-4 w-4"}),X.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));YB.displayName=gy.displayName;const MAe=Ae.forwardRef(({className:e,...t},r)=>X.jsx(yy,{ref:r,className:Nr("text-lg font-semibold text-foreground",e),...t}));MAe.displayName=yy.displayName;const EAe=Ae.forwardRef(({className:e,...t},r)=>X.jsx(vy,{ref:r,className:Nr("text-sm text-muted-foreground",e),...t}));EAe.displayName=vy.displayName;function qB({className:e,...t}){return X.jsx("div",{className:Nr("animate-pulse rounded-md bg-muted",e),...t})}const AAe=CA,TAe=MA,IAe=EA,JB=Ae.forwardRef(({className:e,sideOffset:t=4,...r},n)=>X.jsx(Wx,{ref:n,sideOffset:t,className:Nr("z-50 overflow-hidden rounded-md border bg-popover px-3 py-1.5 text-sm text-popover-foreground shadow-md animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",e),...r}));JB.displayName=Wx.displayName;const PAe="sidebar:state",OAe=60*60*24*7,kAe="16rem",DAe="18rem",LAe="3rem",NAe="b",KB=Ae.createContext(null);function $0(){const e=Ae.useContext(KB);if(!e)throw new Error("useSidebar must be used within a SidebarProvider.");return e}const QB=Ae.forwardRef(({defaultOpen:e=!0,open:t,onOpenChange:r,className:n,style:i,children:s,...c},a)=>{const d=vAe(),[p,y]=Ae.useState(!1),[g,v]=Ae.useState(e),w=t??g,S=Ae.useCallback(E=>{const O=typeof E=="function"?E(w):E;r?r(O):v(O),document.cookie=`${PAe}=${O}; path=/; max-age=${OAe}`},[r,w]),C=Ae.useCallback(()=>d?y(E=>!E):S(E=>!E),[d,S,y]);Ae.useEffect(()=>{const E=O=>{O.key===NAe&&(O.metaKey||O.ctrlKey)&&(O.preventDefault(),C())};return window.addEventListener("keydown",E),()=>window.removeEventListener("keydown",E)},[C]);const M=w?"expanded":"collapsed",I=Ae.useMemo(()=>({state:M,open:w,setOpen:S,isMobile:d,openMobile:p,setOpenMobile:y,toggleSidebar:C}),[M,w,S,d,p,y,C]);return X.jsx(KB.Provider,{value:I,children:X.jsx(AAe,{delayDuration:0,children:X.jsx("div",{style:{"--sidebar-width":kAe,"--sidebar-width-icon":LAe,...i},className:Nr("group/sidebar-wrapper flex min-h-svh w-full has-[[data-variant=inset]]:bg-sidebar",n),ref:a,...c,children:s})})})});QB.displayName="SidebarProvider";const RAe=Ae.forwardRef(({side:e="left",variant:t="sidebar",collapsible:r="offcanvas",className:n,children:i,...s},c)=>{const{isMobile:a,state:d,openMobile:p,setOpenMobile:y}=$0();return r==="none"?X.jsx("div",{className:Nr("flex w-[--sidebar-width] flex-col bg-sidebar text-sidebar-foreground",n),ref:c,...s,children:i}):a?X.jsx(wAe,{open:p,onOpenChange:y,...s,children:X.jsx(YB,{"data-sidebar":"sidebar","data-mobile":"true",className:"w-[--sidebar-width] bg-sidebar p-0 text-sidebar-foreground [&>button]:hidden",style:{"--sidebar-width":DAe},side:e,children:X.jsx("div",{className:"flex h-full w-full flex-col",children:i})})}):X.jsxs("div",{ref:c,className:"group peer hidden md:block text-sidebar-foreground","data-state":d,"data-collapsible":d==="collapsed"?r:"","data-variant":t,"data-side":e,children:[X.jsx("div",{className:Nr("duration-200 relative h-svh w-[--sidebar-width] bg-transparent transition-[width] ease-linear","group-data-[collapsible=offcanvas]:w-0","group-data-[side=right]:rotate-180",t==="floating"||t==="inset"?"group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)_+_theme(spacing.4))]":"group-data-[collapsible=icon]:w-[--sidebar-width-icon]")}),X.jsx("div",{className:Nr("duration-200 fixed inset-y-0 z-10 hidden h-svh w-[--sidebar-width] transition-[left,right,width] ease-linear md:flex",e==="left"?"left-0 group-data-[collapsible=offcanvas]:left-[calc(var(--sidebar-width)*-1)]":"right-0 group-data-[collapsible=offcanvas]:right-[calc(var(--sidebar-width)*-1)]",t==="floating"||t==="inset"?"p-2 group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)_+_theme(spacing.4)_+2px)]":"group-data-[collapsible=icon]:w-[--sidebar-width-icon] group-data-[side=left]:border-r group-data-[side=right]:border-l",n),...s,children:X.jsx("div",{"data-sidebar":"sidebar",className:"flex h-full w-full flex-col bg-sidebar group-data-[variant=floating]:rounded-lg group-data-[variant=floating]:border group-data-[variant=floating]:border-sidebar-border group-data-[variant=floating]:shadow",children:i})})]})});RAe.displayName="Sidebar";const BAe=Ae.forwardRef(({className:e,onClick:t,...r},n)=>{const{toggleSidebar:i}=$0();return X.jsxs(Fr,{ref:n,"data-sidebar":"trigger",variant:"ghost",size:"icon",className:Nr("h-7 w-7",e),onClick:s=>{t==null||t(s),i()},...r,children:[X.jsx(pz,{}),X.jsx("span",{className:"sr-only",children:"Toggle Sidebar"})]})});BAe.displayName="SidebarTrigger";const jAe=Ae.forwardRef(({className:e,...t},r)=>{const{toggleSidebar:n}=$0();return X.jsx("button",{ref:r,"data-sidebar":"rail","aria-label":"Toggle Sidebar",tabIndex:-1,onClick:n,title:"Toggle Sidebar",className:Nr("absolute inset-y-0 z-20 hidden w-4 -translate-x-1/2 transition-all ease-linear after:absolute after:inset-y-0 after:left-1/2 after:w-[2px] hover:after:bg-sidebar-border group-data-[side=left]:-right-4 group-data-[side=right]:left-0 sm:flex","[[data-side=left]_&]:cursor-w-resize [[data-side=right]_&]:cursor-e-resize","[[data-side=left][data-state=collapsed]_&]:cursor-e-resize [[data-side=right][data-state=collapsed]_&]:cursor-w-resize","group-data-[collapsible=offcanvas]:translate-x-0 group-data-[collapsible=offcanvas]:after:left-full group-data-[collapsible=offcanvas]:hover:bg-sidebar","[[data-side=left][data-collapsible=offcanvas]_&]:-right-2","[[data-side=right][data-collapsible=offcanvas]_&]:-left-2",e),...t})});jAe.displayName="SidebarRail";const FAe=Ae.forwardRef(({className:e,...t},r)=>X.jsx("main",{ref:r,className:Nr("relative flex min-h-svh flex-1 flex-col bg-background","peer-data-[variant=inset]:min-h-[calc(100svh-theme(spacing.4))] md:peer-data-[variant=inset]:m-2 md:peer-data-[state=collapsed]:peer-data-[variant=inset]:ml-2 md:peer-data-[variant=inset]:ml-0 md:peer-data-[variant=inset]:rounded-xl md:peer-data-[variant=inset]:shadow",e),...t}));FAe.displayName="SidebarInset";const zAe=Ae.forwardRef(({className:e,...t},r)=>X.jsx(VB,{ref:r,"data-sidebar":"input",className:Nr("h-8 w-full bg-background shadow-none focus-visible:ring-2 focus-visible:ring-sidebar-ring",e),...t}));zAe.displayName="SidebarInput";const $Ae=Ae.forwardRef(({className:e,...t},r)=>X.jsx("div",{ref:r,"data-sidebar":"header",className:Nr("flex flex-col gap-2 p-2",e),...t}));$Ae.displayName="SidebarHeader";const GAe=Ae.forwardRef(({className:e,...t},r)=>X.jsx("div",{ref:r,"data-sidebar":"footer",className:Nr("flex flex-col gap-2 p-2",e),...t}));GAe.displayName="SidebarFooter";const VAe=Ae.forwardRef(({className:e,...t},r)=>X.jsx(XB,{ref:r,"data-sidebar":"separator",className:Nr("mx-2 w-auto bg-sidebar-border",e),...t}));VAe.displayName="SidebarSeparator";const WAe=Ae.forwardRef(({className:e,...t},r)=>X.jsx("div",{ref:r,"data-sidebar":"content",className:Nr("flex min-h-0 flex-1 flex-col gap-2 overflow-auto group-data-[collapsible=icon]:overflow-hidden",e),...t}));WAe.displayName="SidebarContent";const HAe=Ae.forwardRef(({className:e,...t},r)=>X.jsx("div",{ref:r,"data-sidebar":"group",className:Nr("relative flex w-full min-w-0 flex-col p-2",e),...t}));HAe.displayName="SidebarGroup";const UAe=Ae.forwardRef(({className:e,asChild:t=!1,...r},n)=>{const i=t?Dc:"div";return X.jsx(i,{ref:n,"data-sidebar":"group-label",className:Nr("duration-200 flex h-8 shrink-0 items-center rounded-md px-2 text-xs font-medium text-sidebar-foreground/70 outline-none ring-sidebar-ring transition-[margin,opa] ease-linear focus-visible:ring-2 [&>svg]:size-4 [&>svg]:shrink-0","group-data-[collapsible=icon]:-mt-8 group-data-[collapsible=icon]:opacity-0",e),...r})});UAe.displayName="SidebarGroupLabel";const XAe=Ae.forwardRef(({className:e,asChild:t=!1,...r},n)=>{const i=t?Dc:"button";return X.jsx(i,{ref:n,"data-sidebar":"group-action",className:Nr("absolute right-3 top-3.5 flex aspect-square w-5 items-center justify-center rounded-md p-0 text-sidebar-foreground outline-none ring-sidebar-ring transition-transform hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 [&>svg]:size-4 [&>svg]:shrink-0","after:absolute after:-inset-2 after:md:hidden","group-data-[collapsible=icon]:hidden",e),...r})});XAe.displayName="SidebarGroupAction";const ZAe=Ae.forwardRef(({className:e,...t},r)=>X.jsx("div",{ref:r,"data-sidebar":"group-content",className:Nr("w-full text-sm",e),...t}));ZAe.displayName="SidebarGroupContent";const YAe=Ae.forwardRef(({className:e,...t},r)=>X.jsx("ul",{ref:r,"data-sidebar":"menu",className:Nr("flex w-full min-w-0 flex-col gap-1",e),...t}));YAe.displayName="SidebarMenu";const qAe=Ae.forwardRef(({className:e,...t},r)=>X.jsx("li",{ref:r,"data-sidebar":"menu-item",className:Nr("group/menu-item relative",e),...t}));qAe.displayName="SidebarMenuItem";const JAe=C1("peer/menu-button flex w-full items-center gap-2 overflow-hidden rounded-md p-2 text-left text-sm outline-none ring-sidebar-ring transition-[width,height,padding] hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 active:bg-sidebar-accent active:text-sidebar-accent-foreground disabled:pointer-events-none disabled:opacity-50 group-has-[[data-sidebar=menu-action]]/menu-item:pr-8 aria-disabled:pointer-events-none aria-disabled:opacity-50 data-[active=true]:bg-sidebar-accent data-[active=true]:font-medium data-[active=true]:text-sidebar-accent-foreground data-[state=open]:hover:bg-sidebar-accent data-[state=open]:hover:text-sidebar-accent-foreground group-data-[collapsible=icon]:!size-8 group-data-[collapsible=icon]:!p-2 [&>span:last-child]:truncate [&>svg]:size-4 [&>svg]:shrink-0",{variants:{variant:{default:"hover:bg-sidebar-accent hover:text-sidebar-accent-foreground",outline:"bg-background shadow-[0_0_0_1px_hsl(var(--sidebar-border))] hover:bg-sidebar-accent hover:text-sidebar-accent-foreground hover:shadow-[0_0_0_1px_hsl(var(--sidebar-accent))]"},size:{default:"h-8 text-sm",sm:"h-7 text-xs",lg:"h-12 text-sm group-data-[collapsible=icon]:!p-0"}},defaultVariants:{variant:"default",size:"default"}}),KAe=Ae.forwardRef(({asChild:e=!1,isActive:t=!1,variant:r="default",size:n="default",tooltip:i,className:s,...c},a)=>{const d=e?Dc:"button",{isMobile:p,state:y}=$0(),g=X.jsx(d,{ref:a,"data-sidebar":"menu-button","data-size":n,"data-active":t,className:Nr(JAe({variant:r,size:n}),s),...c});return i?(typeof i=="string"&&(i={children:i}),X.jsxs(TAe,{children:[X.jsx(IAe,{asChild:!0,children:g}),X.jsx(JB,{side:"right",align:"center",hidden:y!=="collapsed"||p,...i})]})):g});KAe.displayName="SidebarMenuButton";const QAe=Ae.forwardRef(({className:e,asChild:t=!1,showOnHover:r=!1,...n},i)=>{const s=t?Dc:"button";return X.jsx(s,{ref:i,"data-sidebar":"menu-action",className:Nr("absolute right-1 top-1.5 flex aspect-square w-5 items-center justify-center rounded-md p-0 text-sidebar-foreground outline-none ring-sidebar-ring transition-transform hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 peer-hover/menu-button:text-sidebar-accent-foreground [&>svg]:size-4 [&>svg]:shrink-0","after:absolute after:-inset-2 after:md:hidden","peer-data-[size=sm]/menu-button:top-1","peer-data-[size=default]/menu-button:top-1.5","peer-data-[size=lg]/menu-button:top-2.5","group-data-[collapsible=icon]:hidden",r&&"group-focus-within/menu-item:opacity-100 group-hover/menu-item:opacity-100 data-[state=open]:opacity-100 peer-data-[active=true]/menu-button:text-sidebar-accent-foreground md:opacity-0",e),...n})});QAe.displayName="SidebarMenuAction";const eTe=Ae.forwardRef(({className:e,...t},r)=>X.jsx("div",{ref:r,"data-sidebar":"menu-badge",className:Nr("absolute right-1 flex h-5 min-w-5 items-center justify-center rounded-md px-1 text-xs font-medium tabular-nums text-sidebar-foreground select-none pointer-events-none","peer-hover/menu-button:text-sidebar-accent-foreground peer-data-[active=true]/menu-button:text-sidebar-accent-foreground","peer-data-[size=sm]/menu-button:top-1","peer-data-[size=default]/menu-button:top-1.5","peer-data-[size=lg]/menu-button:top-2.5","group-data-[collapsible=icon]:hidden",e),...t}));eTe.displayName="SidebarMenuBadge";const tTe=Ae.forwardRef(({className:e,showIcon:t=!1,...r},n)=>{const i=Ae.useMemo(()=>`${Math.floor(Math.random()*40)+50}%`,[]);return X.jsxs("div",{ref:n,"data-sidebar":"menu-skeleton",className:Nr("rounded-md h-8 flex gap-2 px-2 items-center",e),...r,children:[t&&X.jsx(qB,{className:"size-4 rounded-md","data-sidebar":"menu-skeleton-icon"}),X.jsx(qB,{className:"h-4 flex-1 max-w-[--skeleton-width]","data-sidebar":"menu-skeleton-text",style:{"--skeleton-width":i}})]})});tTe.displayName="SidebarMenuSkeleton";const rTe=Ae.forwardRef(({className:e,...t},r)=>X.jsx("ul",{ref:r,"data-sidebar":"menu-sub",className:Nr("mx-3.5 flex min-w-0 translate-x-px flex-col gap-1 border-l border-sidebar-border px-2.5 py-0.5","group-data-[collapsible=icon]:hidden",e),...t}));rTe.displayName="SidebarMenuSub";const nTe=Ae.forwardRef(({...e},t)=>X.jsx("li",{ref:t,...e}));nTe.displayName="SidebarMenuSubItem";const iTe=Ae.forwardRef(({asChild:e=!1,size:t="md",isActive:r,className:n,...i},s)=>{const c=e?Dc:"a";return X.jsx(c,{ref:s,"data-sidebar":"menu-sub-button","data-size":t,"data-active":r,className:Nr("flex h-7 min-w-0 -translate-x-px items-center gap-2 overflow-hidden rounded-md px-2 text-sidebar-foreground outline-none ring-sidebar-ring hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 active:bg-sidebar-accent active:text-sidebar-accent-foreground disabled:pointer-events-none disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:opacity-50 [&>span:last-child]:truncate [&>svg]:size-4 [&>svg]:shrink-0 [&>svg]:text-sidebar-accent-foreground","data-[active=true]:bg-sidebar-accent data-[active=true]:text-sidebar-accent-foreground",t==="sm"&&"text-xs",t==="md"&&"text-sm","group-data-[collapsible=icon]:hidden",n),...i})});iTe.displayName="SidebarMenuSubButton";const aTe=({polygon:e,deleteFeature:t,trigger:r})=>{var M;const[n,i]=U.useState(!1),{mapRef:s}=U.useContext(zi),{addNewPlot:c}=U.useContext($o);U.useState(null);const[a,d]=U.useState([]),[p,y]=U.useState(!1),[g,v]=U.useState(!1),w=Zn(),S=()=>{i(!1),t()},C=I=>{console.log("handlePlotCreation data",I),v(!0),c(I).then(()=>{t(),zc.success(w.formatMessage({id:"app.agviewer_map.plot_success_message",defaultMessage:"Plot created successfully"}))}).catch(E=>{zc.error(w.formatMessage({id:"app.agviewer_map.plot_failed_message",defaultMessage:"Could not create the plot"}))}).finally(()=>{v(!1),S()})};return U.useEffect(()=>{y(!0),ry().then(I=>{d(I)}).finally(()=>{y(!1)})},[]),X.jsx(Fo,{trigger:r||X.jsx(Fr,{color:"primary",children:w.formatMessage({id:"app.agviewer_map.add_new_plot",defaultMessage:"Add New Plot"})}),title:w.formatMessage({id:"app.agviewer_map.add_new_plot",defaultMessage:"Add New Plot"}),headerClassName:"m-4",open:n,setOpen:i,portalContainer:s!=null&&s.current?(M=s==null?void 0:s.current)==null?void 0:M.getMap().getContainer():document.body,children:X.jsx(Oo,{children:X.jsx("div",{className:"h-[400px] overflow-y-auto",children:X.jsx(VO,{initialValues:{options:e},onSubmit:C,className:"p-4",submitButtonText:w.formatMessage({id:"app.agviewer_map.create_plot",defaultMessage:"Create Plot"}),onCancel:()=>i(!1)})})})})},sTe=({feature:e,deleteFeature:t,trigger:r})=>{var y,g;const[n,i]=U.useState(!1);U.useContext(zi);const{addNewMarker:s}=U.useContext(Us),c=Zn(),a={longitude:(y=e==null?void 0:e.geometry)==null?void 0:y.coordinates[0],latitude:(g=e==null?void 0:e.geometry)==null?void 0:g.coordinates[1]};console.log("feature",e);const d=()=>{t(),i(!1)},p=v=>{s(v),t(),d()};return console.log("initialValues",a),X.jsx(Fo,{trigger:r||X.jsxs(Cc,{color:"primary",children:[X.jsx(_W,{})," ",c.formatMessage({id:"app.agviewer_map.add_new_marker",defaultMessage:"Add New Marker"})]}),title:c.formatMessage({id:"app.agviewer_map.add_new_marker",defaultMessage:"Add New Marker"}),headerClassName:"m-4",open:n,setOpen:i,onClose:d,children:X.jsx(Oo,{children:X.jsx(tP,{initialValues:a,onSubmit:p,onCancel:d})})})};function oTe(){const[e,t]=U.useState({}),r=$t(Y=>Y.setViewMode),n=$t(Y=>Y.viewMode),[i,s]=U.useState(),{editingPlot:c,handlePlotUpdate:a}=U.useContext($o),[d,p]=U.useState(c==null?void 0:c.options),[y,g]=U.useState([]),{drawRef:v,showDrawActionPopup:w,setShowDrawActionPopup:S}=U.useContext(zi),C=v.current,{current:M}=yg(),I=pd.constants;I.classes.CONTROL_BASE="maplibregl-ctrl",I.classes.CONTROL_PREFIX="maplibregl-ctrl-",I.classes.CONTROL_GROUP="maplibregl-ctrl-group",U.useCallback(Y=>{console.log("onCreate"),t(ie=>{const re={...ie};for(const V of Y.features)re[V.id]=V;return re})},[]),U.useCallback(Y=>{n in[Ur.EDIT_PLOT,Ur.EDIT_MARKER]&&r(Ur.NORMAL),t(ie=>{const re={...ie};for(const V of Y.features)delete re[V.id];return re})},[]);const E=Y=>{console.log("event features",Y.features),console.log("editing plot",c),d&&a({...c,options:d}).then(()=>{console.log("mode",Y.mode),C.deleteAll(),r(Ur.NORMAL)}).catch(ie=>{console.error("error updating plot",ie)})};U.useEffect(()=>{console.log("editingPlot changed",c)},[c]);const O=Y=>{console.log("mode changed",Y.mode),s(Y.mode)},N=Y=>{console.log("selection changed",Y);const ie=v.current.getSelected();g(ie)},D=U.useCallback(Y=>{console.log("handling draw change",Y),Y.features&&Y.features.length>0?p(Y.features[0]):p(null)},[c,a]),L=()=>{C.deleteAll(),r(Ur.NORMAL)},R=()=>{C.getSelectedIds(),C.trash()};return U.useEffect(()=>{const Y=M.getMap();return Y.on("draw.modechange",O),Y.on("draw.selectionchange",N),()=>{Y.off("draw.modechange",O),Y.off("draw.selectionchange",N)}},[v]),U.useEffect(()=>{if(map&&C)return M.on("draw.update",D),()=>{M.off("draw.update",D)}},[M,C,D]),X.jsx(X.Fragment,{children:X.jsx("div",{className:"absolute top-0 right-0 m-2 ",children:X.jsxs("div",{className:" gap-1 flex flex-col",children:[X.jsx(Fr,{variant:"outline",size:"icon",onClick:L,children:X.jsx(El,{})}),X.jsx(Fr,{variant:"outline",size:"icon",onClick:R,children:X.jsx(vx,{})}),X.jsx(Fr,{variant:"outline",size:"icon",onClick:E,children:X.jsx(yx,{})})]})})})}function lTe(){U.useState({});const e=$t(O=>O.setViewMode);$t(O=>O.viewMode);const[t,r]=U.useState(),[n,i]=U.useState({}),[s,c]=U.useState([]),{drawRef:a,showDrawActionPopup:d,setShowDrawActionPopup:p}=U.useContext(zi),y=a.current,{current:g}=yg();U.useEffect(()=>{y.changeMode("draw_polygon")},[y]);const v=()=>{y&&y.delete(n.id),e(Ur.NORMAL)},w=O=>{console.log("mode changed",O.mode),r(O.mode)},S=O=>{console.log("selection changed",O);const N=a.current.getSelected();c(N)},C=O=>{console.log("delete event",O,y.getMode()),y.getAll().features.length===0&&y.getMode()==="simple_select"&&y.changeMode("draw_polygon")},M=U.useCallback(O=>{console.log("running plot shape change",O.features),console.log("handling draw change",O),O.features&&O.features.length>0&&i(O.features[0])},[]);U.useEffect(()=>{console.log("shape changed",n)},[n]);const I=()=>{y.deleteAll(),e(Ur.NORMAL)},E=()=>{y.getSelectedIds().length>0&&y.trash()};return U.useEffect(()=>{const O=g.getMap();return O.on("draw.modechange",w),O.on("draw.selectionchange",S),()=>{O.off("draw.modechange",w),O.off("draw.selectionchange",S)}},[a]),U.useEffect(()=>{if(map&&y)return g.on("draw.delete",C),g.on("draw.create",M),g.on("draw.update",M),()=>{g.off("draw.delete",C),g.off("draw.create",M),g.off("draw.update",M)}},[g,y,M]),X.jsx(X.Fragment,{children:X.jsx("div",{className:"absolute top-0 right-0 m-2 ",children:X.jsxs("div",{className:" gap-1 flex flex-col",children:[X.jsx(Fr,{variant:"outline",size:"icon",onClick:I,children:X.jsx(El,{})}),X.jsx(Fr,{variant:"outline",size:"icon",onClick:E,children:X.jsx(vx,{})}),X.jsx(aTe,{trigger:X.jsx(Fr,{variant:"outline",size:"icon",children:X.jsx(yx,{})}),polygon:n,deleteFeature:v})]})})})}function cTe(){U.useState({});const e=$t(E=>E.setViewMode);$t(E=>E.viewMode);const[t,r]=U.useState(),[n,i]=U.useState({}),[s,c]=U.useState([]),{drawRef:a,showDrawActionPopup:d,setShowDrawActionPopup:p}=U.useContext(zi),y=a.current,{current:g}=yg();U.useEffect(()=>{y.changeMode("draw_point")},[y]);const v=()=>{y&&y.delete(n.id),e(Ur.NORMAL)},w=E=>{console.log("mode changed",E.mode),r(E.mode)},S=E=>{console.log("selection changed",E);const O=a.current.getSelected();c(O)},C=U.useCallback(E=>{console.log("running plot shape change",E.features),console.log("handling draw change",E),E.features&&E.features.length>0&&i(E.features[0])},[]);U.useEffect(()=>{console.log("shape changed",n)},[n]);const M=()=>{y.deleteAll(),e(Ur.NORMAL)},I=()=>{y.getSelectedIds(),y.trash()};return U.useEffect(()=>{const E=g.getMap();return E.on("draw.modechange",w),E.on("draw.selectionchange",S),()=>{E.off("draw.modechange",w),E.off("draw.selectionchange",S)}},[a]),U.useEffect(()=>{if(map&&y)return g.on("draw.create",C),g.on("draw.update",C),()=>{g.off("draw.create",C),g.off("draw.update",C)}},[g,y,C]),X.jsx(X.Fragment,{children:X.jsx("div",{className:"absolute top-0 right-0 m-2 ",children:X.jsxs("div",{className:" gap-1 flex flex-col",children:[X.jsx(Fr,{variant:"outline",size:"icon",onClick:M,children:X.jsx(El,{})}),X.jsx(Fr,{variant:"outline",size:"icon",onClick:I,children:X.jsx(vx,{})}),X.jsx(sTe,{trigger:X.jsx(Fr,{variant:"outline",size:"icon",children:X.jsx(Fa,{text:"add station",children:X.jsx(yx,{})})}),feature:n,deleteFeature:v})]})})})}const uTe=()=>{var a;const[e,t]=U.useState(!0),{mapRef:r}=U.useContext(zi),n=$t(d=>d.setViewMode),i=Zn(),s=()=>{console.log("closing modal"),n(Ur.NORMAL),t(!1)},c=d=>{SW(d.name,d.marker_set).then(p=>{console.log("farm created successfully"),zc(i.formatMessage({id:"app.agviewer_map.farm_success_message",defaultMessage:"Farm Has been created successfully"}),{description:`name: ${d.name}`})}),s()};return X.jsx(Fo,{title:i.formatMessage({id:"app.agviewer_map.add_new_farm",defaultMessage:"Add New Farm"}),headerClassName:"m-4",open:e,setOpen:t,onChange:s,portalContainer:r!=null&&r.current?(a=r==null?void 0:r.current)==null?void 0:a.getMap().getContainer():document.body,children:X.jsx("div",{className:"h-[400px] overflow-y-auto",children:X.jsx(hTe,{onClose:s,onSubmit:c})})})};function hTe({onClose:e,onSubmit:t}){const r=U.useRef(),n=Zn(),{markers:i,loading:s}=U.useContext(Us),c=U.useMemo(()=>i.map(C=>({value:C.id,label:(C==null?void 0:C.name)||(C==null?void 0:C.title)||(C==null?void 0:C.label)})),[i]),[a,d]=U.useState(!1),[p,y]=U.useState(""),[g,v]=U.useState([]);let w=U.useMemo(()=>Lc(g,c),[g,c]);const S=C=>{C.preventDefault(),t({name:p,marker_set:g})};return X.jsxs("form",{onSubmit:S,className:"p-4 flex flex-col h-full",ref:r,children:[X.jsx(Gi,{label:n.formatMessage({id:"app.agviewer_map.name",defaultMessage:"Name"}),children:X.jsx(jo,{type:"text",name:"name",className:"w-full sm:max-w-[483px] max-w-[227px]",value:p,onChange:C=>y(C.target.value)})}),X.jsx(Gi,{label:n.formatMessage({id:"app.agviewer_map.markers",defaultMessage:"Markers"}),children:X.jsx(eo,{formRef:r,className:"w-full sm:max-w-[483px] max-w-[227px]",name:"marker_set",value:w,onChange:v,options:c,isMulti:!0,isClearable:!0,isLoading:s,isSearchable:!0,closeMenuOnSelect:!1})}),X.jsxs("div",{className:"mt-5 flex gap-2 mt-auto self-end",children:[X.jsx(Fr,{type:"cancel",variant:"outline",onClick:!a&&e,disabled:a,children:n.formatMessage({id:"app.agviewer_map.cancel",defaultMessage:"Cancel"})}),X.jsx(Fr,{type:"submit",color:"primary",children:n.formatMessage({id:"app.agviewer_map.add_farm",defaultMessage:"Add Farm"})})]})]})}function dTe({style:e,requestHeaders:t,configs:r,markers:n}){var L;const{settings:i}=U.useContext(of),{mapRef:s}=U.useContext(zi),c=U.useRef(),a=_6(),[d,p]=U.useState(a),y=$t(R=>R.viewMode),g=$t(R=>R.mapMode),v=$t(R=>R.cursor),w=$t(R=>R.setRequestHeaders),S=$t(R=>R.setConfigs),C=$t(R=>R.dateRange),M=$t(R=>R.setDateRange),I=$t(R=>R.dateRange2),E=$t(R=>R.setDateRange2),O=U.useCallback(R=>p(R.viewState),[]),[N,D]=U.useState(`${(L=FM.find(R=>R.id===i.basemap.id))==null?void 0:L.url}?key=${r==null?void 0:r.VITE_MAPTILER_ACCESS_KEY}`);return U.useEffect(()=>{var R;D(`${(R=FM.find(Y=>Y.id===i.basemap.id))==null?void 0:R.url}?key=${r==null?void 0:r.VITE_MAPTILER_ACCESS_KEY}`)},[i]),U.useEffect(()=>{w(t)},[t]),U.useEffect(()=>{S(r)},[]),U.useEffect(()=>{console.log("fff dateRange is",C),console.log("fff dateRange2 is",I)},[C,I]),a?X.jsx(IE,{providedMarkers:n,children:X.jsx(ZK,{children:X.jsx($O,{children:X.jsx(QB,{children:X.jsx(dre,{children:X.jsxs("div",{style:{width:"100%",height:"80vh"},className:"flex flex-row",children:[X.jsxs(cE,{id:"myMap",ref:s,initialViewState:a,...d,onMove:O,style:{width:"100%",...e},mapStyle:typeof N=="string"?N:N.toJS(),attributionControl:!1,reuseMaps:!0,preserveDrawingBuffer:!0,cursor:v,children:[X.jsx(jB,{mapRef:s,dateRange:C}),g==La.NORMAL&&X.jsx(vre,{mapRef:s}),X.jsx("div",{className:"absolute top-0 left-0",children:g==La.COMPARISION_VIEW&&X.jsx(k_,{mapRef:s,setDateRange:M,compact:!0})}),X.jsxs("div",{className:"absolute top-0 right-0 m-2",style:{zIndex:2},children:[g===La.NORMAL&&X.jsx(GB,{dateRange:C,mapRef:s}),g!==La.NORMAL&&X.jsx($B,{dateRange:C,mapRef:s,showButton:!1})]}),X.jsx(aAe,{}),y==Ur.EDIT_PLOT&&X.jsx(oTe,{}),y==Ur.ADD_PLOT&&X.jsx(lTe,{}),y==Ur.ADD_MARKER&&X.jsx(cTe,{}),y==Ur.ADD_NEW_FARM&&X.jsx(uTe,{}),X.jsx(mEe,{}),X.jsx(Ire,{}),X.jsx(Nre,{}),X.jsx(qR,{mapRef:s,dateRange:C}),X.jsx(sAe,{}),y===Ur.PICKER&&g!==La.COMPARISION_VIEW&&X.jsx(FB,{})]}),g===La.COMPARISION_VIEW&&X.jsxs(cE,{id:"myMap2",ref:c,initialViewState:a,...d,onMove:O,style:{width:"100%",...e},mapStyle:typeof N=="string"?N:N.toJS(),attributionControl:!1,reuseMaps:!0,preserveDrawingBuffer:!0,cursor:v,children:[X.jsx(jB,{mapRef:c,dateRange:I}),X.jsx("div",{className:"absolute top-0 left-0",children:X.jsx(k_,{mapRef:c,setDateRange:E,compact:!0})}),X.jsx("div",{className:"absolute top-0 right-0 m-2",style:{zIndex:2},children:X.jsx(GB,{dateRange:I,mapRef:c})}),X.jsx(qR,{mapRef:c,dateRange:I}),y===Ur.PICKER&&X.jsx(FB,{})]}),X.jsx(fAe,{})]})})})})})}):X.jsx(Ra,{})}var fTe={},ej={};(function(e){function t(I){"@babel/helpers - typeof";return t=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(E){return typeof E}:function(E){return E&&typeof Symbol=="function"&&E.constructor===Symbol&&E!==Symbol.prototype?"symbol":typeof E},t(I)}Object.defineProperty(e,"__esModule",{value:!0}),e.default=void 0;var r=s(U),n=["dispose","reject","resolve"];function i(I){if(typeof WeakMap!="function")return null;var E=new WeakMap,O=new WeakMap;return(i=function(D){return D?O:E})(I)}function s(I,E){if(I&&I.__esModule)return I;if(I===null||t(I)!=="object"&&typeof I!="function")return{default:I};var O=i(E);if(O&&O.has(I))return O.get(I);var N={},D=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var L in I)if(L!=="default"&&Object.prototype.hasOwnProperty.call(I,L)){var R=D?Object.getOwnPropertyDescriptor(I,L):null;R&&(R.get||R.set)?Object.defineProperty(N,L,R):N[L]=I[L]}return N.default=I,O&&O.set(I,N),N}function c(){return c=Object.assign||function(I){for(var E=1;E<arguments.length;E++){var O=arguments[E];for(var N in O)Object.prototype.hasOwnProperty.call(O,N)&&(I[N]=O[N])}return I},c.apply(this,arguments)}function a(I,E){return v(I)||g(I,E)||p(I,E)||d()}function d(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
|
|
1019
|
+
}`,$S={},GS={};async function bEe(e,{weeksBefore:t=0,accessToken:r,dateRange:n}){if(console.log("downloading cropped ndvi",n),!r)return console.error("No access token provided"),null;let i=new Date(n.start.setHours(0,0,1)).toISOString(),s=new Date(n.end.setHours(23,59,59)).toISOString();const c=`${e.properties.id}-${i}`;if(console.log("crop cacheKey",c),$S[c])return console.log("NDVI data found in cache"),$S[c];if(console.log("access Token",r),!mK(Mf(e)))throw new Error("Invalid BBOX");const d="https://services.sentinel-hub.com/api/v1/process",p={input:{bounds:{geometry:{type:"Polygon",coordinates:e.geometry.coordinates},properties:{crs:"http://www.opengis.net/def/crs/EPSG/0/4326"}},data:[{type:"sentinel-2-l2a",dataFilter:{timeRange:{from:i,to:s}}}]},output:{width:512,height:512,responses:[{identifier:"default",format:{type:"image/png"}}]},evalscript:vEe};try{const y=await fetch(d,{method:"POST",headers:{Authorization:`Bearer ${r}`,"Content-Type":"application/json"},body:JSON.stringify(p)});if(!y.ok)throw new Error("Failed to fetch NDVI data");const g=await y.blob();if(!g)return null;const v=URL.createObjectURL(g);return $S[c]=v,v}catch(y){return console.error("Error fetching NDVI data:",y),null}}async function xEe(e,t){console.log("downloading cropped et",t);let r,n;r=t.start.toISOString().split("T")[0],n=t.end.toISOString().split("T")[0];const i=`${r}/${n}`,s=Mf(e);if(!s)throw new Error("Invalid BBOX");const c=`${e.properties.id}-${r}`;if(console.log("crop cacheKey",c),GS[c])return console.log("ET data found in cache"),GS[c];const a=s.join(","),d="https://d27s6pvwcjpmsu.cloudfront.net/geoserver/ne/wms?"+new URLSearchParams({service:"WMS",version:"1.1.0",request:"GetMap",layers:"ne:et_data",styles:"",bbox:a,width:512,height:512,srs:"EPSG:4326",format:"image/png",transparent:"true",TIME:i});try{const p=await fetch(d);if(!p.ok)throw new Error("Failed to fetch cropped NDVI from GeoServer");const y=await p.blob();if(!y)return null;const g=URL.createObjectURL(y);return GS[c]=g,g}catch(p){return console.error("Error fetching cropped NDVI:",p),null}}async function _Ee(e,t){return new Promise(r=>{const n=new Image;n.onload=function(){const i=document.createElement("canvas"),s=i.getContext("2d");i.width=n.width,i.height=n.height,s.drawImage(n,0,0,n.width,n.height);const c=t.geometry.coordinates[0].map(([a,d])=>wEe(a,d,Mf(t),n.width,n.height));s.globalCompositeOperation="destination-in",s.beginPath(),c.forEach(([a,d],p)=>{p===0?s.moveTo(a,d):s.lineTo(a,d)}),s.closePath(),s.fill(),r(i.toDataURL("image/png"))},n.src=e})}function wEe(e,t,r,n,i){const[s,c,a,d]=r,p=(e-s)/(a-s)*n,y=i-(t-c)/(d-c)*i;return[p,y]}async function SEe(e,{rasterLayer:t,dateRange:r,accessToken:n,map:i}){if(console.log("getCroppedRaster rasterLayer",t,r),!(r!=null&&r.start)instanceof Date||!(r!=null&&r.end)instanceof Date){console.error("DateRange is not of type Date");return}if(t==="ET"||(t==null?void 0:t.value)==="ET"){const s=await xEe(e,r);if(!s)return null;const c=await _Ee(s,e);return console.log("croppedImageURl",c),c?(console.log("crop getCroppedRaster crop image URL",s),c):null}else if(t==="3_NDVI"||(t==null?void 0:t.value)==="3_NDVI")return await bEe(e,{accessToken:n,dateRange:r})}function qR({mapRef:e,dateRange:t}){var K;const{plots:r,showPlots:n,clickedPlot:i,setClickedPlot:s}=U.useContext($o),c=$t(Q=>Q.showCroppedImages),a=$t(Q=>Q.datesLoading),d=$t(Q=>Q.mapMode),p=$t(Q=>Q.rasterLayer),{isVisible:y,setIsVisible:g}=U.useContext(Hf),{settings:v}=U.useContext(of),w=$t(Q=>Q.setCursor),S=$t(Q=>Q.resetCursor),{drawRef:C}=U.useContext(zi),M=U.useContext(Ry),I=(K=e==null?void 0:e.current)==null?void 0:K.getMap(),E=$t(Q=>Q.viewMode),O=$t(Q=>Q.addLoadingNDVIImage),N=$t(Q=>Q.removeLoadingNDVIImage),D=$t(Q=>Q.isNDVIImageLoading);$t(Q=>Q.setShowCroppedImages);const L=U.useCallback((Q,ae,{map:J})=>{if(console.log("eeeeee croppp adding image to map",Q,ae,J),!J)throw new Error("map is not defined");if(!c||!y)return console.log("showCroppedImages is off",c),null;if(console.log("plotss",ae),!ae||!ae.geometry||ae.geometry.type!=="Polygon")return null;const[pe,xe,se,ge]=Mf(ae.geometry),Se=[[pe,ge],[se,ge],[se,xe],[pe,xe]],Ee=`croppedImageSource-${ae.properties.id}`,$e=`croppedImageLayer-${ae.properties.id}`;J.getLayer($e)&&J.removeLayer($e),J.getSource(Ee)&&J.removeSource(Ee),console.log("adding the cropped raster to map"),console.log("adding source"),J.addSource(Ee,{type:"image",url:Q,coordinates:Se});let le=J.getLayer("plots-line-layer")?"plots-line-layer":void 0;console.log("cropped beforeId",le),console.log("adding layer"),J.addLayer({id:$e,type:"raster",source:Ee,paint:{"raster-opacity":1}},le);const ne=J.getPitch();J.setPitch(ne+.01),console.log("croppp layer order",J.getLayersOrder())},[c]),R=U.useCallback(async(Q,{accessToken:ae,map:J,timeTravel:pe,dateRange:xe,isVisible:se,showCroppedImages:ge})=>{if(console.log("handleCroppedImageDownload started"),console.log("crop download plot",Q),!J)throw new Error("map is not defined");const Se=`croppedImageLayer-${Q.properties.id}`;if(console.log("crop visible, showCropped",se,ge),!se||!ge){console.log("crop either isVisible or not plot mode selected, deleting layer and returning"),J.getLayer(Se)&&J.removeLayer(Se);return}if(J.getLayer(Se))if(pe)console.log("only time travel"),J.removeLayer(Se);else{console.log("NDVI layer already added for this plot",Se);return}try{if(D(Q.properties.id))return;O(Q.properties.id);const Ee=await SEe(Q,{rasterLayer:p,dateRange:xe,accessToken:ae});if(console.log("ndvi URL",Ee),!Q)throw new Error("plot is not defined");console.log("mapp",J),Ee&&(console.log(),L(Ee,Q,{map:J}))}catch(Ee){console.log("error in loading ndvi layer",Ee)}finally{N(Q.properties.id)}},[p,M,D,O,L,N]),Y={id:"plots-line-layer",type:"line",paint:{"line-color":"#e31717","line-width":2}},ie={id:"plots-layer",type:"fill",paint:{"fill-color":"#e31717","fill-opacity":0}},re=U.useCallback(()=>{var J;const Q=(J=C==null?void 0:C.current)==null?void 0:J.getAll();return((Q==null?void 0:Q.features)||[]).length>0},[C]),V=U.useCallback(Q=>{if(re()){console.log("no popup info"),s(null);return}const ae=I.queryRenderedFeatures(Q.point,{layers:["plots-layer"]});if(ae.length>0){const J=ae[0];console.log("clickedPlot",J),s({lngLat:Q.lngLat,plot:J})}else s(null)},[re,I,s]),Z=U.useCallback(()=>{w("pointer")},[w,I]),W=U.useCallback(()=>{S()},[w,I]),B=U.useCallback((Q,ae)=>{const[J,pe,xe,se]=Q,[[ge,Se],[Ee,$e]]=ae.toArray();return!(J>Ee||xe<ge||pe>$e||se<Se)},[]),F=U.useCallback(({timeTravel:Q=!1})=>{if(console.log("handleLoadingCroppedRasterLayerToMap start"),!I||a){console.log("ddd either map or dates are loading");return}if(I.getZoom()<10)return;const J=I.getBounds();r.forEach(pe=>{if(RO(pe.options))return;const xe=Mf(pe.options);B(xe,J)&&R(pe.options,{dateRange:t,accessToken:M,map:I,timeTravel:Q,isVisible:y,showCroppedImages:c})}),console.log("handleLoadingCroppedRasterLayerToMap end")},[I,r,M,t,B,E,y,c,p]),q=U.useMemo(()=>Wf(F,500),[F]);return U.useEffect(()=>{y&&(console.log("loading cropped images"),F({timeTravel:!0}))},[t,y,c,r,p]),U.useEffect(()=>{y&&(console.log("settings changed resetting cropped layer"),F({timeTravel:!0}))},[v]),U.useEffect(()=>(I&&n&&E!=="PICKER"&&I.on("click","plots-layer",V),()=>{I&&I.off("click","plots-layer",V)}),[V,E,n,I]),U.useEffect(()=>{if(console.log("running useEffect inside plots"),!(!I||E!=="NORMAL"||!n||!c))return console.log("adding viewport change event to map"),I.on("moveend",q),I.on("zoomend",q),I.on("style.load",q),()=>{console.log("removing viewport change event from map"),q.cancel(),I.off("style.load",q),I.off("moveend",q),I.off("zoomend",q)}},[I,n,E,q,c]),U.useEffect(()=>(I&&E!=="PICKER"&&(I.on("mouseenter","plots-layer",Z),I.on("mouseleave","plots-layer",W)),()=>{I&&E!=="PICKER"&&(I.off("mouseenter","plots-layer",Z),I.off("mouseleave","plots-layer",W))}),[I,Z,W,E]),n?X.jsxs(X.Fragment,{children:[X.jsxs(hE,{id:"plots",type:"geojson",data:{type:"FeatureCollection",features:r.map(Q=>Q==null?void 0:Q.options)},children:[X.jsx(gx,{...ie},"12kmsn"),X.jsx(gx,{...Y},"12kkd")]}),i&&d!==La.COMPARISION_VIEW&&E==Ur.NORMAL&&X.jsx(yEe,{popupInfo:i,onClose:()=>s(null)})]}):null}const VS=function(e,t){const r={drag:[],click:[],mousemove:[],mousedown:[],mouseup:[],mouseout:[],keydown:[],keyup:[],touchstart:[],touchmove:[],touchend:[],tap:[]},n={on(s,c,a){if(r[s]===void 0)throw new Error(`Invalid event type: ${s}`);r[s].push({selector:c,fn:a})},render(s){t.store.featureChanged(s)}},i=function(s,c){const a=r[s];let d=a.length;for(;d--;){const p=a[d];if(p.selector(c)){p.fn.call(n,c)||t.store.render(),t.ui.updateMapClasses();break}}};return e.start.call(n),{render:e.render,stop(){e.stop&&e.stop()},trash(){e.trash&&(e.trash(),t.store.render())},combineFeatures(){e.combineFeatures&&e.combineFeatures()},uncombineFeatures(){e.uncombineFeatures&&e.uncombineFeatures()},drag(s){i("drag",s)},click(s){i("click",s)},mousemove(s){i("mousemove",s)},mousedown(s){i("mousedown",s)},mouseup(s){i("mouseup",s)},mouseout(s){i("mouseout",s)},keydown(s){i("keydown",s)},keyup(s){i("keyup",s)},touchstart(s){i("touchstart",s)},touchmove(s){i("touchmove",s)},touchend(s){i("touchend",s)},tap(s){i("tap",s)}}};var WS={},I0={};I0.RADIUS=6378137,I0.FLATTENING=1/298.257223563,I0.POLAR_RADIUS=63567523142e-4;var JR=I0;WS.geometry=KR,WS.ring=HS;function KR(e){var t=0,r;switch(e.type){case"Polygon":return QR(e.coordinates);case"MultiPolygon":for(r=0;r<e.coordinates.length;r++)t+=QR(e.coordinates[r]);return t;case"Point":case"MultiPoint":case"LineString":case"MultiLineString":return 0;case"GeometryCollection":for(r=0;r<e.geometries.length;r++)t+=KR(e.geometries[r]);return t}}function QR(e){var t=0;if(e&&e.length>0){t+=Math.abs(HS(e[0]));for(var r=1;r<e.length;r++)t-=Math.abs(HS(e[r]))}return t}function HS(e){var t,r,n,i,s,c,a,d=0,p=e.length;if(p>2){for(a=0;a<p;a++)a===p-2?(i=p-2,s=p-1,c=0):a===p-1?(i=p-1,s=0,c=1):(i=a,s=a+1,c=a+2),t=e[i],r=e[s],n=e[c],d+=(US(n[0])-US(t[0]))*Math.sin(US(r[1]));d=d*JR.RADIUS*JR.RADIUS/2}return d}function US(e){return e*Math.PI/180}const Ta={CANVAS:"mapboxgl-canvas",CONTROL_BASE:"mapboxgl-ctrl",CONTROL_PREFIX:"mapboxgl-ctrl-",CONTROL_BUTTON:"mapbox-gl-draw_ctrl-draw-btn",CONTROL_BUTTON_LINE:"mapbox-gl-draw_line",CONTROL_BUTTON_POLYGON:"mapbox-gl-draw_polygon",CONTROL_BUTTON_POINT:"mapbox-gl-draw_point",CONTROL_BUTTON_TRASH:"mapbox-gl-draw_trash",CONTROL_BUTTON_COMBINE_FEATURES:"mapbox-gl-draw_combine",CONTROL_BUTTON_UNCOMBINE_FEATURES:"mapbox-gl-draw_uncombine",CONTROL_GROUP:"mapboxgl-ctrl-group",ATTRIBUTION:"mapboxgl-ctrl-attrib",ACTIVE_BUTTON:"active",BOX_SELECT:"mapbox-gl-draw_boxselect"},ys={HOT:"mapbox-gl-draw-hot",COLD:"mapbox-gl-draw-cold"},Vn={ADD:"add",MOVE:"move",DRAG:"drag",POINTER:"pointer",NONE:"none"},Ia={POLYGON:"polygon",LINE:"line_string",POINT:"point"},yr={FEATURE:"Feature",POLYGON:"Polygon",LINE_STRING:"LineString",POINT:"Point",FEATURE_COLLECTION:"FeatureCollection",MULTI_PREFIX:"Multi",MULTI_POINT:"MultiPoint",MULTI_LINE_STRING:"MultiLineString",MULTI_POLYGON:"MultiPolygon"},Vr={DRAW_LINE_STRING:"draw_line_string",DRAW_POLYGON:"draw_polygon",DRAW_POINT:"draw_point",SIMPLE_SELECT:"simple_select",DIRECT_SELECT:"direct_select"},la={CREATE:"draw.create",DELETE:"draw.delete",UPDATE:"draw.update",SELECTION_CHANGE:"draw.selectionchange",MODE_CHANGE:"draw.modechange",ACTIONABLE:"draw.actionable",RENDER:"draw.render",COMBINE_FEATURES:"draw.combine",UNCOMBINE_FEATURES:"draw.uncombine"},am={MOVE:"move",CHANGE_PROPERTIES:"change_properties",CHANGE_COORDINATES:"change_coordinates"},Hi={FEATURE:"feature",MIDPOINT:"midpoint",VERTEX:"vertex"},vi={ACTIVE:"true",INACTIVE:"false"},eB=["scrollZoom","boxZoom","dragRotate","dragPan","keyboard","doubleClickZoom","touchZoomRotate"],CEe=-90,XS=-85,MEe=90,ZS=85,tB=Object.freeze(Object.defineProperty({__proto__:null,LAT_MAX:MEe,LAT_MIN:CEe,LAT_RENDERED_MAX:ZS,LAT_RENDERED_MIN:XS,LNG_MAX:270,LNG_MIN:-270,activeStates:vi,classes:Ta,cursors:Vn,events:la,geojsonTypes:yr,interactions:eB,meta:Hi,modes:Vr,sources:ys,types:Ia,updateActions:am},Symbol.toStringTag,{value:"Module"})),rB={Point:0,LineString:1,MultiLineString:1,Polygon:2};function EEe(e,t){const r=rB[e.geometry.type]-rB[t.geometry.type];return r===0&&e.geometry.type===yr.POLYGON?e.area-t.area:r}function nB(e){return e.map(t=>(t.geometry.type===yr.POLYGON&&(t.area=WS.geometry({type:yr.FEATURE,property:{},geometry:t.geometry})),t)).sort(EEe).map(t=>(delete t.area,t))}function iB(e,t=0){return[[e.point.x-t,e.point.y-t],[e.point.x+t,e.point.y+t]]}function vs(e){if(this._items={},this._nums={},this._length=e?e.length:0,!!e)for(let t=0,r=e.length;t<r;t++)this.add(e[t]),e[t]!==void 0&&(typeof e[t]=="string"?this._items[e[t]]=t:this._nums[e[t]]=t)}vs.prototype.add=function(e){return this.has(e)?this:(this._length++,typeof e=="string"?this._items[e]=this._length:this._nums[e]=this._length,this)},vs.prototype.delete=function(e){return this.has(e)===!1?this:(this._length--,delete this._items[e],delete this._nums[e],this)},vs.prototype.has=function(e){return typeof e!="string"&&typeof e!="number"?!1:this._items[e]!==void 0||this._nums[e]!==void 0},vs.prototype.values=function(){const e=[];return Object.keys(this._items).forEach(t=>{e.push({k:t,v:this._items[t]})}),Object.keys(this._nums).forEach(t=>{e.push({k:JSON.parse(t),v:this._nums[t]})}),e.sort((t,r)=>t.v-r.v).map(t=>t.k)},vs.prototype.clear=function(){return this._length=0,this._items={},this._nums={},this};const AEe=[Hi.FEATURE,Hi.MIDPOINT,Hi.VERTEX],dd={click:TEe,touch:IEe};function TEe(e,t,r){return aB(e,t,r,r.options.clickBuffer)}function IEe(e,t,r){return aB(e,t,r,r.options.touchBuffer)}function aB(e,t,r,n){if(r.map===null)return[];const i=e?iB(e,n):t,s={};r.options.styles&&(s.layers=r.options.styles.map(p=>p.id).filter(p=>r.map.getLayer(p)!=null));const c=r.map.queryRenderedFeatures(i,s).filter(p=>AEe.indexOf(p.properties.meta)!==-1),a=new vs,d=[];return c.forEach(p=>{const y=p.properties.id;a.has(y)||(a.add(y),d.push(p))}),nB(d)}function P0(e,t){const r=dd.click(e,null,t),n={mouse:Vn.NONE};return r[0]&&(n.mouse=r[0].properties.active===vi.ACTIVE?Vn.MOVE:Vn.POINTER,n.feature=r[0].properties.meta),t.events.currentModeName().indexOf("draw")!==-1&&(n.mouse=Vn.ADD),t.ui.queueMapClasses(n),t.ui.updateMapClasses(),r[0]}function YS(e,t){const r=e.x-t.x,n=e.y-t.y;return Math.sqrt(r*r+n*n)}const PEe=4,OEe=12,kEe=500;function qS(e,t,r={}){const n=r.fineTolerance!=null?r.fineTolerance:PEe,i=r.grossTolerance!=null?r.grossTolerance:OEe,s=r.interval!=null?r.interval:kEe;e.point=e.point||t.point,e.time=e.time||t.time;const c=YS(e.point,t.point);return c<n||c<i&&t.time-e.time<s}const DEe=25,LEe=250;function JS(e,t,r={}){const n=r.tolerance!=null?r.tolerance:DEe,i=r.interval!=null?r.interval:LEe;return e.point=e.point||t.point,e.time=e.time||t.time,YS(e.point,t.point)<n&&t.time-e.time<i}const NEe=((e,t=21)=>(r=t)=>{let n="",i=r|0;for(;i--;)n+=e[Math.random()*e.length|0];return n})("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",32);function KS(){return NEe()}const ca=function(e,t){this.ctx=e,this.properties=t.properties||{},this.coordinates=t.geometry.coordinates,this.id=t.id||KS(),this.type=t.geometry.type};ca.prototype.changed=function(){this.ctx.store.featureChanged(this.id)},ca.prototype.incomingCoords=function(e){this.setCoordinates(e)},ca.prototype.setCoordinates=function(e){this.coordinates=e,this.changed()},ca.prototype.getCoordinates=function(){return JSON.parse(JSON.stringify(this.coordinates))},ca.prototype.setProperty=function(e,t){this.properties[e]=t},ca.prototype.toGeoJSON=function(){return JSON.parse(JSON.stringify({id:this.id,type:yr.FEATURE,properties:this.properties,geometry:{coordinates:this.getCoordinates(),type:this.type}}))},ca.prototype.internal=function(e){const t={id:this.id,meta:Hi.FEATURE,"meta:type":this.type,active:vi.INACTIVE,mode:e};if(this.ctx.options.userProperties)for(const r in this.properties)t[`user_${r}`]=this.properties[r];return{type:yr.FEATURE,properties:t,geometry:{coordinates:this.getCoordinates(),type:this.type}}};const Jl=function(e,t){ca.call(this,e,t)};Jl.prototype=Object.create(ca.prototype),Jl.prototype.isValid=function(){return typeof this.coordinates[0]=="number"&&typeof this.coordinates[1]=="number"},Jl.prototype.updateCoordinate=function(e,t,r){arguments.length===3?this.coordinates=[t,r]:this.coordinates=[e,t],this.changed()},Jl.prototype.getCoordinate=function(){return this.getCoordinates()};const yo=function(e,t){ca.call(this,e,t)};yo.prototype=Object.create(ca.prototype),yo.prototype.isValid=function(){return this.coordinates.length>1},yo.prototype.addCoordinate=function(e,t,r){this.changed();const n=parseInt(e,10);this.coordinates.splice(n,0,[t,r])},yo.prototype.getCoordinate=function(e){const t=parseInt(e,10);return JSON.parse(JSON.stringify(this.coordinates[t]))},yo.prototype.removeCoordinate=function(e){this.changed(),this.coordinates.splice(parseInt(e,10),1)},yo.prototype.updateCoordinate=function(e,t,r){const n=parseInt(e,10);this.coordinates[n]=[t,r],this.changed()};const Wa=function(e,t){ca.call(this,e,t),this.coordinates=this.coordinates.map(r=>r.slice(0,-1))};Wa.prototype=Object.create(ca.prototype),Wa.prototype.isValid=function(){return this.coordinates.length===0?!1:this.coordinates.every(e=>e.length>2)},Wa.prototype.incomingCoords=function(e){this.coordinates=e.map(t=>t.slice(0,-1)),this.changed()},Wa.prototype.setCoordinates=function(e){this.coordinates=e,this.changed()},Wa.prototype.addCoordinate=function(e,t,r){this.changed();const n=e.split(".").map(s=>parseInt(s,10));this.coordinates[n[0]].splice(n[1],0,[t,r])},Wa.prototype.removeCoordinate=function(e){this.changed();const t=e.split(".").map(n=>parseInt(n,10)),r=this.coordinates[t[0]];r&&(r.splice(t[1],1),r.length<3&&this.coordinates.splice(t[0],1))},Wa.prototype.getCoordinate=function(e){const t=e.split(".").map(n=>parseInt(n,10)),r=this.coordinates[t[0]];return JSON.parse(JSON.stringify(r[t[1]]))},Wa.prototype.getCoordinates=function(){return this.coordinates.map(e=>e.concat([e[0]]))},Wa.prototype.updateCoordinate=function(e,t,r){this.changed();const n=e.split("."),i=parseInt(n[0],10),s=parseInt(n[1],10);this.coordinates[i]===void 0&&(this.coordinates[i]=[]),this.coordinates[i][s]=[t,r]};const REe={MultiPoint:Jl,MultiLineString:yo,MultiPolygon:Wa},O0=(e,t,r,n,i)=>{const s=r.split("."),c=parseInt(s[0],10),a=s[1]?s.slice(1).join("."):null;return e[c][t](a,n,i)},ua=function(e,t){if(ca.call(this,e,t),delete this.coordinates,this.model=REe[t.geometry.type],this.model===void 0)throw new TypeError(`${t.geometry.type} is not a valid type`);this.features=this._coordinatesToFeatures(t.geometry.coordinates)};ua.prototype=Object.create(ca.prototype),ua.prototype._coordinatesToFeatures=function(e){const t=this.model.bind(this);return e.map(r=>new t(this.ctx,{id:KS(),type:yr.FEATURE,properties:{},geometry:{coordinates:r,type:this.type.replace("Multi","")}}))},ua.prototype.isValid=function(){return this.features.every(e=>e.isValid())},ua.prototype.setCoordinates=function(e){this.features=this._coordinatesToFeatures(e),this.changed()},ua.prototype.getCoordinate=function(e){return O0(this.features,"getCoordinate",e)},ua.prototype.getCoordinates=function(){return JSON.parse(JSON.stringify(this.features.map(e=>e.type===yr.POLYGON?e.getCoordinates():e.coordinates)))},ua.prototype.updateCoordinate=function(e,t,r){O0(this.features,"updateCoordinate",e,t,r),this.changed()},ua.prototype.addCoordinate=function(e,t,r){O0(this.features,"addCoordinate",e,t,r),this.changed()},ua.prototype.removeCoordinate=function(e){O0(this.features,"removeCoordinate",e),this.changed()},ua.prototype.getFeatures=function(){return this.features};function $r(e){this.map=e.map,this.drawConfig=JSON.parse(JSON.stringify(e.options||{})),this._ctx=e}$r.prototype.setSelected=function(e){return this._ctx.store.setSelected(e)},$r.prototype.setSelectedCoordinates=function(e){this._ctx.store.setSelectedCoordinates(e),e.reduce((t,r)=>(t[r.feature_id]===void 0&&(t[r.feature_id]=!0,this._ctx.store.get(r.feature_id).changed()),t),{})},$r.prototype.getSelected=function(){return this._ctx.store.getSelected()},$r.prototype.getSelectedIds=function(){return this._ctx.store.getSelectedIds()},$r.prototype.isSelected=function(e){return this._ctx.store.isSelected(e)},$r.prototype.getFeature=function(e){return this._ctx.store.get(e)},$r.prototype.select=function(e){return this._ctx.store.select(e)},$r.prototype.deselect=function(e){return this._ctx.store.deselect(e)},$r.prototype.deleteFeature=function(e,t={}){return this._ctx.store.delete(e,t)},$r.prototype.addFeature=function(e,t={}){return this._ctx.store.add(e,t)},$r.prototype.clearSelectedFeatures=function(){return this._ctx.store.clearSelected()},$r.prototype.clearSelectedCoordinates=function(){return this._ctx.store.clearSelectedCoordinates()},$r.prototype.setActionableState=function(e={}){const t={trash:e.trash||!1,combineFeatures:e.combineFeatures||!1,uncombineFeatures:e.uncombineFeatures||!1};return this._ctx.events.actionable(t)},$r.prototype.changeMode=function(e,t={},r={}){return this._ctx.events.changeMode(e,t,r)},$r.prototype.fire=function(e,t){return this._ctx.events.fire(e,t)},$r.prototype.updateUIClasses=function(e){return this._ctx.ui.queueMapClasses(e)},$r.prototype.activateUIButton=function(e){return this._ctx.ui.setActiveButton(e)},$r.prototype.featuresAt=function(e,t,r="click"){if(r!=="click"&&r!=="touch")throw new Error("invalid buffer type");return dd[r](e,t,this._ctx)},$r.prototype.newFeature=function(e){const t=e.geometry.type;return t===yr.POINT?new Jl(this._ctx,e):t===yr.LINE_STRING?new yo(this._ctx,e):t===yr.POLYGON?new Wa(this._ctx,e):new ua(this._ctx,e)},$r.prototype.isInstanceOf=function(e,t){if(e===yr.POINT)return t instanceof Jl;if(e===yr.LINE_STRING)return t instanceof yo;if(e===yr.POLYGON)return t instanceof Wa;if(e==="MultiFeature")return t instanceof ua;throw new Error(`Unknown feature class: ${e}`)},$r.prototype.doRender=function(e){return this._ctx.store.featureChanged(e)},$r.prototype.onSetup=function(){},$r.prototype.onDrag=function(){},$r.prototype.onClick=function(){},$r.prototype.onMouseMove=function(){},$r.prototype.onMouseDown=function(){},$r.prototype.onMouseUp=function(){},$r.prototype.onMouseOut=function(){},$r.prototype.onKeyUp=function(){},$r.prototype.onKeyDown=function(){},$r.prototype.onTouchStart=function(){},$r.prototype.onTouchMove=function(){},$r.prototype.onTouchEnd=function(){},$r.prototype.onTap=function(){},$r.prototype.onStop=function(){},$r.prototype.onTrash=function(){},$r.prototype.onCombineFeature=function(){},$r.prototype.onUncombineFeature=function(){},$r.prototype.toDisplayFeatures=function(){throw new Error("You must overwrite toDisplayFeatures")};const sB={drag:"onDrag",click:"onClick",mousemove:"onMouseMove",mousedown:"onMouseDown",mouseup:"onMouseUp",mouseout:"onMouseOut",keyup:"onKeyUp",keydown:"onKeyDown",touchstart:"onTouchStart",touchmove:"onTouchMove",touchend:"onTouchEnd",tap:"onTap"},BEe=Object.keys(sB);function jEe(e){const t=Object.keys(e);return function(r,n={}){let i={};const s=t.reduce((a,d)=>(a[d]=e[d],a),new $r(r));function c(a){return d=>s[a](i,d)}return{start(){i=s.onSetup(n),BEe.forEach(a=>{const d=sB[a];let p=()=>!1;e[d]&&(p=()=>!0),this.on(a,p,c(d))})},stop(){s.onStop(i)},trash(){s.onTrash(i)},combineFeatures(){s.onCombineFeatures(i)},uncombineFeatures(){s.onUncombineFeatures(i)},render(a,d){s.toDisplayFeatures(i,a,d)}}}}function FEe(e){const t=Object.keys(e.options.modes).reduce((v,w)=>(v[w]=jEe(e.options.modes[w]),v),{});let r={},n={};const i={};let s=null,c=null;i.drag=function(v,w){w({point:v.point,time:new Date().getTime()})?(e.ui.queueMapClasses({mouse:Vn.DRAG}),c.drag(v)):v.originalEvent.stopPropagation()},i.mousedrag=function(v){i.drag(v,w=>!qS(r,w))},i.touchdrag=function(v){i.drag(v,w=>!JS(n,w))},i.mousemove=function(v){if((v.originalEvent.buttons!==void 0?v.originalEvent.buttons:v.originalEvent.which)===1)return i.mousedrag(v);const S=P0(v,e);v.featureTarget=S,c.mousemove(v)},i.mousedown=function(v){r={time:new Date().getTime(),point:v.point};const w=P0(v,e);v.featureTarget=w,c.mousedown(v)},i.mouseup=function(v){const w=P0(v,e);v.featureTarget=w,qS(r,{point:v.point,time:new Date().getTime()})?c.click(v):c.mouseup(v)},i.mouseout=function(v){c.mouseout(v)},i.touchstart=function(v){if(!e.options.touchEnabled)return;n={time:new Date().getTime(),point:v.point};const w=dd.touch(v,null,e)[0];v.featureTarget=w,c.touchstart(v)},i.touchmove=function(v){if(e.options.touchEnabled)return c.touchmove(v),i.touchdrag(v)},i.touchend=function(v){if(v.originalEvent.preventDefault(),!e.options.touchEnabled)return;const w=dd.touch(v,null,e)[0];v.featureTarget=w,JS(n,{time:new Date().getTime(),point:v.point})?c.tap(v):c.touchend(v)};const a=v=>!(v===8||v===46||v>=48&&v<=57);i.keydown=function(v){(v.srcElement||v.target).classList.contains(Ta.CANVAS)&&((v.keyCode===8||v.keyCode===46)&&e.options.controls.trash?(v.preventDefault(),c.trash()):a(v.keyCode)?c.keydown(v):v.keyCode===49&&e.options.controls.point?d(Vr.DRAW_POINT):v.keyCode===50&&e.options.controls.line_string?d(Vr.DRAW_LINE_STRING):v.keyCode===51&&e.options.controls.polygon&&d(Vr.DRAW_POLYGON))},i.keyup=function(v){a(v.keyCode)&&c.keyup(v)},i.zoomend=function(){e.store.changeZoom()},i.data=function(v){if(v.dataType==="style"){const{setup:w,map:S,options:C,store:M}=e;C.styles.some(E=>S.getLayer(E.id))||(w.addLayers(),M.setDirty(),M.render())}};function d(v,w,S={}){c.stop();const C=t[v];if(C===void 0)throw new Error(`${v} is not valid`);s=v;const M=C(e,w);c=VS(M,e),S.silent||e.map.fire(la.MODE_CHANGE,{mode:v}),e.store.setDirty(),e.store.render()}const p={trash:!1,combineFeatures:!1,uncombineFeatures:!1};function y(v){let w=!1;Object.keys(v).forEach(S=>{if(p[S]===void 0)throw new Error("Invalid action type");p[S]!==v[S]&&(w=!0),p[S]=v[S]}),w&&e.map.fire(la.ACTIONABLE,{actions:p})}return{start(){s=e.options.defaultMode,c=VS(t[s](e),e)},changeMode:d,actionable:y,currentModeName(){return s},currentModeRender(v,w){return c.render(v,w)},fire(v,w){e.map&&e.map.fire(v,w)},addEventListeners(){e.map.on("mousemove",i.mousemove),e.map.on("mousedown",i.mousedown),e.map.on("mouseup",i.mouseup),e.map.on("data",i.data),e.map.on("touchmove",i.touchmove),e.map.on("touchstart",i.touchstart),e.map.on("touchend",i.touchend),e.container.addEventListener("mouseout",i.mouseout),e.options.keybindings&&(e.container.addEventListener("keydown",i.keydown),e.container.addEventListener("keyup",i.keyup))},removeEventListeners(){e.map.off("mousemove",i.mousemove),e.map.off("mousedown",i.mousedown),e.map.off("mouseup",i.mouseup),e.map.off("data",i.data),e.map.off("touchmove",i.touchmove),e.map.off("touchstart",i.touchstart),e.map.off("touchend",i.touchend),e.container.removeEventListener("mouseout",i.mouseout),e.options.keybindings&&(e.container.removeEventListener("keydown",i.keydown),e.container.removeEventListener("keyup",i.keyup))},trash(v){c.trash(v)},combineFeatures(){c.combineFeatures()},uncombineFeatures(){c.uncombineFeatures()},getMode(){return s}}}function sm(e){return[].concat(e).filter(t=>t!==void 0)}function zEe(){const e=this;if(!(e.ctx.map&&e.ctx.map.getSource(ys.HOT)!==void 0))return d();const r=e.ctx.events.currentModeName();e.ctx.ui.queueMapClasses({mode:r});let n=[],i=[];e.isDirty?i=e.getAllIds():(n=e.getChangedIds().filter(p=>e.get(p)!==void 0),i=e.sources.hot.filter(p=>p.properties.id&&n.indexOf(p.properties.id)===-1&&e.get(p.properties.id)!==void 0).map(p=>p.properties.id)),e.sources.hot=[];const s=e.sources.cold.length;e.sources.cold=e.isDirty?[]:e.sources.cold.filter(p=>{const y=p.properties.id||p.properties.parent;return n.indexOf(y)===-1});const c=s!==e.sources.cold.length||i.length>0;n.forEach(p=>a(p,"hot")),i.forEach(p=>a(p,"cold"));function a(p,y){const v=e.get(p).internal(r);e.ctx.events.currentModeRender(v,w=>{w.properties.mode=r,e.sources[y].push(w)})}c&&e.ctx.map.getSource(ys.COLD).setData({type:yr.FEATURE_COLLECTION,features:e.sources.cold}),e.ctx.map.getSource(ys.HOT).setData({type:yr.FEATURE_COLLECTION,features:e.sources.hot}),d();function d(){e.isDirty=!1,e.clearChangedIds()}}function Nn(e){this._features={},this._featureIds=new vs,this._selectedFeatureIds=new vs,this._selectedCoordinates=[],this._changedFeatureIds=new vs,this._emitSelectionChange=!1,this._mapInitialConfig={},this.ctx=e,this.sources={hot:[],cold:[]};let t;this.render=()=>{t||(t=requestAnimationFrame(()=>{t=null,zEe.call(this),this._emitSelectionChange&&(this.ctx.events.fire(la.SELECTION_CHANGE,{features:this.getSelected().map(r=>r.toGeoJSON()),points:this.getSelectedCoordinates().map(r=>({type:yr.FEATURE,properties:{},geometry:{type:yr.POINT,coordinates:r.coordinates}}))}),this._emitSelectionChange=!1),this.ctx.events.fire(la.RENDER,{})}))},this.isDirty=!1}Nn.prototype.createRenderBatch=function(){const e=this.render;let t=0;return this.render=function(){t++},()=>{this.render=e,t>0&&this.render()}},Nn.prototype.setDirty=function(){return this.isDirty=!0,this},Nn.prototype.featureCreated=function(e,t={}){if(this._changedFeatureIds.add(e),(t.silent!=null?t.silent:this.ctx.options.suppressAPIEvents)!==!0){const n=this.get(e);this.ctx.events.fire(la.CREATE,{features:[n.toGeoJSON()]})}return this},Nn.prototype.featureChanged=function(e,t={}){return this._changedFeatureIds.add(e),(t.silent!=null?t.silent:this.ctx.options.suppressAPIEvents)!==!0&&this.ctx.events.fire(la.UPDATE,{action:t.action?t.action:am.CHANGE_COORDINATES,features:[this.get(e).toGeoJSON()]}),this},Nn.prototype.getChangedIds=function(){return this._changedFeatureIds.values()},Nn.prototype.clearChangedIds=function(){return this._changedFeatureIds.clear(),this},Nn.prototype.getAllIds=function(){return this._featureIds.values()},Nn.prototype.add=function(e,t={}){return this._features[e.id]=e,this._featureIds.add(e.id),this.featureCreated(e.id,{silent:t.silent}),this},Nn.prototype.delete=function(e,t={}){const r=[];return sm(e).forEach(n=>{this._featureIds.has(n)&&(this._featureIds.delete(n),this._selectedFeatureIds.delete(n),t.silent||r.indexOf(this._features[n])===-1&&r.push(this._features[n].toGeoJSON()),delete this._features[n],this.isDirty=!0)}),r.length&&this.ctx.events.fire(la.DELETE,{features:r}),oB(this,t),this},Nn.prototype.get=function(e){return this._features[e]},Nn.prototype.getAll=function(){return Object.keys(this._features).map(e=>this._features[e])},Nn.prototype.select=function(e,t={}){return sm(e).forEach(r=>{this._selectedFeatureIds.has(r)||(this._selectedFeatureIds.add(r),this._changedFeatureIds.add(r),t.silent||(this._emitSelectionChange=!0))}),this},Nn.prototype.deselect=function(e,t={}){return sm(e).forEach(r=>{this._selectedFeatureIds.has(r)&&(this._selectedFeatureIds.delete(r),this._changedFeatureIds.add(r),t.silent||(this._emitSelectionChange=!0))}),oB(this,t),this},Nn.prototype.clearSelected=function(e={}){return this.deselect(this._selectedFeatureIds.values(),{silent:e.silent}),this},Nn.prototype.setSelected=function(e,t={}){return e=sm(e),this.deselect(this._selectedFeatureIds.values().filter(r=>e.indexOf(r)===-1),{silent:t.silent}),this.select(e.filter(r=>!this._selectedFeatureIds.has(r)),{silent:t.silent}),this},Nn.prototype.setSelectedCoordinates=function(e){return this._selectedCoordinates=e,this._emitSelectionChange=!0,this},Nn.prototype.clearSelectedCoordinates=function(){return this._selectedCoordinates=[],this._emitSelectionChange=!0,this},Nn.prototype.getSelectedIds=function(){return this._selectedFeatureIds.values()},Nn.prototype.getSelected=function(){return this.getSelectedIds().map(e=>this.get(e))},Nn.prototype.getSelectedCoordinates=function(){return this._selectedCoordinates.map(t=>({coordinates:this.get(t.feature_id).getCoordinate(t.coord_path)}))},Nn.prototype.isSelected=function(e){return this._selectedFeatureIds.has(e)},Nn.prototype.setFeatureProperty=function(e,t,r,n={}){this.get(e).setProperty(t,r),this.featureChanged(e,{silent:n.silent,action:am.CHANGE_PROPERTIES})};function oB(e,t={}){const r=e._selectedCoordinates.filter(n=>e._selectedFeatureIds.has(n.feature_id));e._selectedCoordinates.length!==r.length&&!t.silent&&(e._emitSelectionChange=!0),e._selectedCoordinates=r}Nn.prototype.storeMapConfig=function(){eB.forEach(e=>{this.ctx.map[e]&&(this._mapInitialConfig[e]=this.ctx.map[e].isEnabled())})},Nn.prototype.restoreMapConfig=function(){Object.keys(this._mapInitialConfig).forEach(e=>{this._mapInitialConfig[e]?this.ctx.map[e].enable():this.ctx.map[e].disable()})},Nn.prototype.getInitialConfigValue=function(e){return this._mapInitialConfig[e]!==void 0?this._mapInitialConfig[e]:!0};const $Ee=["mode","feature","mouse"];function GEe(e){const t={};let r=null,n={mode:null,feature:null,mouse:null},i={mode:null,feature:null,mouse:null};function s(){c({mode:null,feature:null,mouse:null}),a()}function c(w){i=Object.assign(i,w)}function a(){if(!e.container)return;const w=[],S=[];$Ee.forEach(C=>{i[C]!==n[C]&&(w.push(`${C}-${n[C]}`),i[C]!==null&&S.push(`${C}-${i[C]}`))}),w.length>0&&e.container.classList.remove(...w),S.length>0&&e.container.classList.add(...S),n=Object.assign(n,i)}function d(w,S={}){const C=document.createElement("button");return C.className=`${Ta.CONTROL_BUTTON} ${S.className}`,C.setAttribute("title",S.title),S.container.appendChild(C),C.addEventListener("click",M=>{if(M.preventDefault(),M.stopPropagation(),M.target===r){p(),S.onDeactivate();return}y(w),S.onActivate()},!0),C}function p(){r&&(r.classList.remove(Ta.ACTIVE_BUTTON),r=null)}function y(w){p();const S=t[w];S&&S&&w!=="trash"&&(S.classList.add(Ta.ACTIVE_BUTTON),r=S)}function g(){const w=e.options.controls,S=document.createElement("div");return S.className=`${Ta.CONTROL_GROUP} ${Ta.CONTROL_BASE}`,w&&(w[Ia.LINE]&&(t[Ia.LINE]=d(Ia.LINE,{container:S,className:Ta.CONTROL_BUTTON_LINE,title:`LineString tool ${e.options.keybindings?"(l)":""}`,onActivate:()=>e.events.changeMode(Vr.DRAW_LINE_STRING),onDeactivate:()=>e.events.trash()})),w[Ia.POLYGON]&&(t[Ia.POLYGON]=d(Ia.POLYGON,{container:S,className:Ta.CONTROL_BUTTON_POLYGON,title:`Polygon tool ${e.options.keybindings?"(p)":""}`,onActivate:()=>e.events.changeMode(Vr.DRAW_POLYGON),onDeactivate:()=>e.events.trash()})),w[Ia.POINT]&&(t[Ia.POINT]=d(Ia.POINT,{container:S,className:Ta.CONTROL_BUTTON_POINT,title:`Marker tool ${e.options.keybindings?"(m)":""}`,onActivate:()=>e.events.changeMode(Vr.DRAW_POINT),onDeactivate:()=>e.events.trash()})),w.trash&&(t.trash=d("trash",{container:S,className:Ta.CONTROL_BUTTON_TRASH,title:"Delete",onActivate:()=>{e.events.trash()}})),w.combine_features&&(t.combine_features=d("combineFeatures",{container:S,className:Ta.CONTROL_BUTTON_COMBINE_FEATURES,title:"Combine",onActivate:()=>{e.events.combineFeatures()}})),w.uncombine_features&&(t.uncombine_features=d("uncombineFeatures",{container:S,className:Ta.CONTROL_BUTTON_UNCOMBINE_FEATURES,title:"Uncombine",onActivate:()=>{e.events.uncombineFeatures()}}))),S}function v(){Object.keys(t).forEach(w=>{const S=t[w];S.parentNode&&S.parentNode.removeChild(S),delete t[w]})}return{setActiveButton:y,queueMapClasses:c,updateMapClasses:a,clearMapClasses:s,addButtons:g,removeButtons:v}}function VEe(e){let t=null,r=null;const n={onRemove(){return e.map.off("load",n.connect),clearInterval(r),n.removeLayers(),e.store.restoreMapConfig(),e.ui.removeButtons(),e.events.removeEventListeners(),e.ui.clearMapClasses(),e.boxZoomInitial&&e.map.boxZoom.enable(),e.map=null,e.container=null,e.store=null,t&&t.parentNode&&t.parentNode.removeChild(t),t=null,this},connect(){e.map.off("load",n.connect),clearInterval(r),n.addLayers(),e.store.storeMapConfig(),e.events.addEventListeners()},onAdd(i){if(e.map=i,e.events=FEe(e),e.ui=GEe(e),e.container=i.getContainer(),e.store=new Nn(e),t=e.ui.addButtons(),e.options.boxSelect){e.boxZoomInitial=i.boxZoom.isEnabled(),i.boxZoom.disable();const s=i.dragPan.isEnabled();i.dragPan.disable(),i.dragPan.enable(),s||i.dragPan.disable()}return i.loaded()?n.connect():(i.on("load",n.connect),r=setInterval(()=>{i.loaded()&&n.connect()},16)),e.events.start(),t},addLayers(){e.map.addSource(ys.COLD,{data:{type:yr.FEATURE_COLLECTION,features:[]},type:"geojson"}),e.map.addSource(ys.HOT,{data:{type:yr.FEATURE_COLLECTION,features:[]},type:"geojson"}),e.options.styles.forEach(i=>{e.map.addLayer(i)}),e.store.setDirty(!0),e.store.render()},removeLayers(){e.options.styles.forEach(i=>{e.map.getLayer(i.id)&&e.map.removeLayer(i.id)}),e.map.getSource(ys.COLD)&&e.map.removeSource(ys.COLD),e.map.getSource(ys.HOT)&&e.map.removeSource(ys.HOT)}};return e.setup=n,n}const QS="#3bb2d0",om="#fbb03b",lB="#fff",cB=[{id:"gl-draw-polygon-fill",type:"fill",filter:["all",["==","$type","Polygon"]],paint:{"fill-color":["case",["==",["get","active"],"true"],om,QS],"fill-opacity":.1}},{id:"gl-draw-lines",type:"line",filter:["any",["==","$type","LineString"],["==","$type","Polygon"]],layout:{"line-cap":"round","line-join":"round"},paint:{"line-color":["case",["==",["get","active"],"true"],om,QS],"line-dasharray":["case",["==",["get","active"],"true"],[.2,2],[2,0]],"line-width":2}},{id:"gl-draw-point-outer",type:"circle",filter:["all",["==","$type","Point"],["==","meta","feature"]],paint:{"circle-radius":["case",["==",["get","active"],"true"],7,5],"circle-color":lB}},{id:"gl-draw-point-inner",type:"circle",filter:["all",["==","$type","Point"],["==","meta","feature"]],paint:{"circle-radius":["case",["==",["get","active"],"true"],5,3],"circle-color":["case",["==",["get","active"],"true"],om,QS]}},{id:"gl-draw-vertex-outer",type:"circle",filter:["all",["==","$type","Point"],["==","meta","vertex"],["!=","mode","simple_select"]],paint:{"circle-radius":["case",["==",["get","active"],"true"],7,5],"circle-color":lB}},{id:"gl-draw-vertex-inner",type:"circle",filter:["all",["==","$type","Point"],["==","meta","vertex"],["!=","mode","simple_select"]],paint:{"circle-radius":["case",["==",["get","active"],"true"],5,3],"circle-color":om}},{id:"gl-draw-midpoint",type:"circle",filter:["all",["==","meta","midpoint"]],paint:{"circle-radius":3,"circle-color":om}}];function k0(e){return function(t){const r=t.featureTarget;return!r||!r.properties?!1:r.properties.meta===e}}function uB(e){return!e.originalEvent||!e.originalEvent.shiftKey?!1:e.originalEvent.button===0}function lu(e){return!e.featureTarget||!e.featureTarget.properties?!1:e.featureTarget.properties.active===vi.ACTIVE&&e.featureTarget.properties.meta===Hi.FEATURE}function eC(e){return!e.featureTarget||!e.featureTarget.properties?!1:e.featureTarget.properties.active===vi.INACTIVE&&e.featureTarget.properties.meta===Hi.FEATURE}function D0(e){return e.featureTarget===void 0}function tC(e){return!e.featureTarget||!e.featureTarget.properties?!1:e.featureTarget.properties.meta===Hi.FEATURE}function lm(e){const t=e.featureTarget;return!t||!t.properties?!1:t.properties.meta===Hi.VERTEX}function L0(e){return e.originalEvent?e.originalEvent.shiftKey===!0:!1}function N0(e){return e.keyCode===27}function R0(e){return e.keyCode===13}function WEe(){return!0}const HEe=Object.freeze(Object.defineProperty({__proto__:null,isActiveFeature:lu,isEnterKey:R0,isEscapeKey:N0,isFeature:tC,isInactiveFeature:eC,isOfMetaType:k0,isShiftDown:L0,isShiftMousedown:uB,isTrue:WEe,isVertex:lm,noTarget:D0},Symbol.toStringTag,{value:"Module"}));function Kl(e,t){this.x=e,this.y=t}Kl.prototype={clone(){return new Kl(this.x,this.y)},add(e){return this.clone()._add(e)},sub(e){return this.clone()._sub(e)},multByPoint(e){return this.clone()._multByPoint(e)},divByPoint(e){return this.clone()._divByPoint(e)},mult(e){return this.clone()._mult(e)},div(e){return this.clone()._div(e)},rotate(e){return this.clone()._rotate(e)},rotateAround(e,t){return this.clone()._rotateAround(e,t)},matMult(e){return this.clone()._matMult(e)},unit(){return this.clone()._unit()},perp(){return this.clone()._perp()},round(){return this.clone()._round()},mag(){return Math.sqrt(this.x*this.x+this.y*this.y)},equals(e){return this.x===e.x&&this.y===e.y},dist(e){return Math.sqrt(this.distSqr(e))},distSqr(e){const t=e.x-this.x,r=e.y-this.y;return t*t+r*r},angle(){return Math.atan2(this.y,this.x)},angleTo(e){return Math.atan2(this.y-e.y,this.x-e.x)},angleWith(e){return this.angleWithSep(e.x,e.y)},angleWithSep(e,t){return Math.atan2(this.x*t-this.y*e,this.x*e+this.y*t)},_matMult(e){const t=e[0]*this.x+e[1]*this.y,r=e[2]*this.x+e[3]*this.y;return this.x=t,this.y=r,this},_add(e){return this.x+=e.x,this.y+=e.y,this},_sub(e){return this.x-=e.x,this.y-=e.y,this},_mult(e){return this.x*=e,this.y*=e,this},_div(e){return this.x/=e,this.y/=e,this},_multByPoint(e){return this.x*=e.x,this.y*=e.y,this},_divByPoint(e){return this.x/=e.x,this.y/=e.y,this},_unit(){return this._div(this.mag()),this},_perp(){const e=this.y;return this.y=this.x,this.x=-e,this},_rotate(e){const t=Math.cos(e),r=Math.sin(e),n=t*this.x-r*this.y,i=r*this.x+t*this.y;return this.x=n,this.y=i,this},_rotateAround(e,t){const r=Math.cos(e),n=Math.sin(e),i=t.x+r*(this.x-t.x)-n*(this.y-t.y),s=t.y+n*(this.x-t.x)+r*(this.y-t.y);return this.x=i,this.y=s,this},_round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this},constructor:Kl},Kl.convert=function(e){if(e instanceof Kl)return e;if(Array.isArray(e))return new Kl(+e[0],+e[1]);if(e.x!==void 0&&e.y!==void 0)return new Kl(+e.x,+e.y);throw new Error("Expected [x, y] or {x, y} point format")};function rC(e,t){const r=t.getBoundingClientRect();return new Kl(e.clientX-r.left-(t.clientLeft||0),e.clientY-r.top-(t.clientTop||0))}function fd(e,t,r,n){return{type:yr.FEATURE,properties:{meta:Hi.VERTEX,parent:e,coord_path:r,active:n?vi.ACTIVE:vi.INACTIVE},geometry:{type:yr.POINT,coordinates:t}}}function hB(e,t,r){const n=t.geometry.coordinates,i=r.geometry.coordinates;if(n[1]>ZS||n[1]<XS||i[1]>ZS||i[1]<XS)return null;const s={lng:(n[0]+i[0])/2,lat:(n[1]+i[1])/2};return{type:yr.FEATURE,properties:{meta:Hi.MIDPOINT,parent:e,lng:s.lng,lat:s.lat,coord_path:r.properties.coord_path},geometry:{type:yr.POINT,coordinates:[s.lng,s.lat]}}}function B0(e,t={},r=null){const{type:n,coordinates:i}=e.geometry,s=e.properties&&e.properties.id;let c=[];n===yr.POINT?c.push(fd(s,i,r,d(r))):n===yr.POLYGON?i.forEach((y,g)=>{a(y,r!==null?`${r}.${g}`:String(g))}):n===yr.LINE_STRING?a(i,r):n.indexOf(yr.MULTI_PREFIX)===0&&p();function a(y,g){let v="",w=null;y.forEach((S,C)=>{const M=g!=null?`${g}.${C}`:String(C),I=fd(s,S,M,d(M));if(t.midpoints&&w){const O=hB(s,w,I);O&&c.push(O)}w=I;const E=JSON.stringify(S);v!==E&&c.push(I),C===0&&(v=E)})}function d(y){return t.selectedPaths?t.selectedPaths.indexOf(y)!==-1:!1}function p(){const y=n.replace(yr.MULTI_PREFIX,"");i.forEach((g,v)=>{const w={type:yr.FEATURE,properties:e.properties,geometry:{type:y,coordinates:g}};c=c.concat(B0(w,t,v))})}return c}const Bs={enable(e){setTimeout(()=>{!e.map||!e.map.doubleClickZoom||!e._ctx||!e._ctx.store||!e._ctx.store.getInitialConfigValue||e._ctx.store.getInitialConfigValue("doubleClickZoom")&&e.map.doubleClickZoom.enable()},0)},disable(e){setTimeout(()=>{!e.map||!e.map.doubleClickZoom||e.map.doubleClickZoom.disable()},0)}},{LAT_MIN:j0,LAT_MAX:F0,LAT_RENDERED_MIN:dB,LAT_RENDERED_MAX:fB,LNG_MIN:pB,LNG_MAX:mB}=tB;function UEe(e){const t={Point:0,LineString:1,Polygon:2,MultiPoint:1,MultiLineString:2,MultiPolygon:3}[e.geometry.type],r=[e.geometry.coordinates].flat(t),n=r.map(a=>a[0]),i=r.map(a=>a[1]),s=a=>Math.min.apply(null,a),c=a=>Math.max.apply(null,a);return[s(n),s(i),c(n),c(i)]}function nC(e,t){let r=j0,n=F0,i=j0,s=F0,c=mB,a=pB;e.forEach(p=>{const y=UEe(p),g=y[1],v=y[3],w=y[0],S=y[2];g>r&&(r=g),v<n&&(n=v),v>i&&(i=v),g<s&&(s=g),w<c&&(c=w),S>a&&(a=S)});const d=t;return r+d.lat>fB&&(d.lat=fB-r),i+d.lat>F0&&(d.lat=F0-i),n+d.lat<dB&&(d.lat=dB-n),s+d.lat<j0&&(d.lat=j0-s),c+d.lng<=pB&&(d.lng+=Math.ceil(Math.abs(d.lng)/360)*360),a+d.lng>=mB&&(d.lng-=Math.ceil(Math.abs(d.lng)/360)*360),d}function iC(e,t){const r=nC(e.map(n=>n.toGeoJSON()),t);e.forEach(n=>{const i=n.getCoordinates(),s=p=>{const y={lng:p[0]+r.lng,lat:p[1]+r.lat};return[y.lng,y.lat]},c=p=>p.map(y=>s(y)),a=p=>p.map(y=>c(y));let d;n.type===yr.POINT?d=s(i):n.type===yr.LINE_STRING||n.type===yr.MULTI_POINT?d=i.map(s):n.type===yr.POLYGON||n.type===yr.MULTI_LINE_STRING?d=i.map(c):n.type===yr.MULTI_POLYGON&&(d=i.map(a)),n.incomingCoords(d)})}const An={};An.onSetup=function(e){const t={dragMoveLocation:null,boxSelectStartLocation:null,boxSelectElement:void 0,boxSelecting:!1,canBoxSelect:!1,dragMoving:!1,canDragMove:!1,initialDragPanState:this.map.dragPan.isEnabled(),initiallySelectedFeatureIds:e.featureIds||[]};return this.setSelected(t.initiallySelectedFeatureIds.filter(r=>this.getFeature(r)!==void 0)),this.fireActionable(),this.setActionableState({combineFeatures:!0,uncombineFeatures:!0,trash:!0}),t},An.fireUpdate=function(){this.fire(la.UPDATE,{action:am.MOVE,features:this.getSelected().map(e=>e.toGeoJSON())})},An.fireActionable=function(){const e=this.getSelected(),t=e.filter(s=>this.isInstanceOf("MultiFeature",s));let r=!1;if(e.length>1){r=!0;const s=e[0].type.replace("Multi","");e.forEach(c=>{c.type.replace("Multi","")!==s&&(r=!1)})}const n=t.length>0,i=e.length>0;this.setActionableState({combineFeatures:r,uncombineFeatures:n,trash:i})},An.getUniqueIds=function(e){return e.length?e.map(r=>r.properties.id).filter(r=>r!==void 0).reduce((r,n)=>(r.add(n),r),new vs).values():[]},An.stopExtendedInteractions=function(e){e.boxSelectElement&&(e.boxSelectElement.parentNode&&e.boxSelectElement.parentNode.removeChild(e.boxSelectElement),e.boxSelectElement=null),(e.canDragMove||e.canBoxSelect)&&e.initialDragPanState===!0&&this.map.dragPan.enable(),e.boxSelecting=!1,e.canBoxSelect=!1,e.dragMoving=!1,e.canDragMove=!1},An.onStop=function(){Bs.enable(this)},An.onMouseMove=function(e,t){return tC(t)&&e.dragMoving&&this.fireUpdate(),this.stopExtendedInteractions(e),!0},An.onMouseOut=function(e){return e.dragMoving?this.fireUpdate():!0},An.onTap=An.onClick=function(e,t){if(D0(t))return this.clickAnywhere(e,t);if(k0(Hi.VERTEX)(t))return this.clickOnVertex(e,t);if(tC(t))return this.clickOnFeature(e,t)},An.clickAnywhere=function(e){const t=this.getSelectedIds();t.length&&(this.clearSelectedFeatures(),t.forEach(r=>this.doRender(r))),Bs.enable(this),this.stopExtendedInteractions(e)},An.clickOnVertex=function(e,t){this.changeMode(Vr.DIRECT_SELECT,{featureId:t.featureTarget.properties.parent,coordPath:t.featureTarget.properties.coord_path,startPos:t.lngLat}),this.updateUIClasses({mouse:Vn.MOVE})},An.startOnActiveFeature=function(e,t){this.stopExtendedInteractions(e),this.map.dragPan.disable(),this.doRender(t.featureTarget.properties.id),e.canDragMove=!0,e.dragMoveLocation=t.lngLat},An.clickOnFeature=function(e,t){Bs.disable(this),this.stopExtendedInteractions(e);const r=L0(t),n=this.getSelectedIds(),i=t.featureTarget.properties.id,s=this.isSelected(i);if(!r&&s&&this.getFeature(i).type!==yr.POINT)return this.changeMode(Vr.DIRECT_SELECT,{featureId:i});s&&r?(this.deselect(i),this.updateUIClasses({mouse:Vn.POINTER}),n.length===1&&Bs.enable(this)):!s&&r?(this.select(i),this.updateUIClasses({mouse:Vn.MOVE})):!s&&!r&&(n.forEach(c=>this.doRender(c)),this.setSelected(i),this.updateUIClasses({mouse:Vn.MOVE})),this.doRender(i)},An.onMouseDown=function(e,t){if(e.initialDragPanState=this.map.dragPan.isEnabled(),lu(t))return this.startOnActiveFeature(e,t);if(this.drawConfig.boxSelect&&uB(t))return this.startBoxSelect(e,t)},An.startBoxSelect=function(e,t){this.stopExtendedInteractions(e),this.map.dragPan.disable(),e.boxSelectStartLocation=rC(t.originalEvent,this.map.getContainer()),e.canBoxSelect=!0},An.onTouchStart=function(e,t){if(lu(t))return this.startOnActiveFeature(e,t)},An.onDrag=function(e,t){if(e.canDragMove)return this.dragMove(e,t);if(this.drawConfig.boxSelect&&e.canBoxSelect)return this.whileBoxSelect(e,t)},An.whileBoxSelect=function(e,t){e.boxSelecting=!0,this.updateUIClasses({mouse:Vn.ADD}),e.boxSelectElement||(e.boxSelectElement=document.createElement("div"),e.boxSelectElement.classList.add(Ta.BOX_SELECT),this.map.getContainer().appendChild(e.boxSelectElement));const r=rC(t.originalEvent,this.map.getContainer()),n=Math.min(e.boxSelectStartLocation.x,r.x),i=Math.max(e.boxSelectStartLocation.x,r.x),s=Math.min(e.boxSelectStartLocation.y,r.y),c=Math.max(e.boxSelectStartLocation.y,r.y),a=`translate(${n}px, ${s}px)`;e.boxSelectElement.style.transform=a,e.boxSelectElement.style.WebkitTransform=a,e.boxSelectElement.style.width=`${i-n}px`,e.boxSelectElement.style.height=`${c-s}px`},An.dragMove=function(e,t){e.dragMoving=!0,t.originalEvent.stopPropagation();const r={lng:t.lngLat.lng-e.dragMoveLocation.lng,lat:t.lngLat.lat-e.dragMoveLocation.lat};iC(this.getSelected(),r),e.dragMoveLocation=t.lngLat},An.onTouchEnd=An.onMouseUp=function(e,t){if(e.dragMoving)this.fireUpdate();else if(e.boxSelecting){const r=[e.boxSelectStartLocation,rC(t.originalEvent,this.map.getContainer())],n=this.featuresAt(null,r,"click"),i=this.getUniqueIds(n).filter(s=>!this.isSelected(s));i.length&&(this.select(i),i.forEach(s=>this.doRender(s)),this.updateUIClasses({mouse:Vn.MOVE}))}this.stopExtendedInteractions(e)},An.toDisplayFeatures=function(e,t,r){t.properties.active=this.isSelected(t.properties.id)?vi.ACTIVE:vi.INACTIVE,r(t),this.fireActionable(),!(t.properties.active!==vi.ACTIVE||t.geometry.type===yr.POINT)&&B0(t).forEach(r)},An.onTrash=function(){this.deleteFeature(this.getSelectedIds()),this.fireActionable()},An.onCombineFeatures=function(){const e=this.getSelected();if(e.length===0||e.length<2)return;const t=[],r=[],n=e[0].type.replace("Multi","");for(let i=0;i<e.length;i++){const s=e[i];if(s.type.replace("Multi","")!==n)return;s.type.includes("Multi")?s.getCoordinates().forEach(c=>{t.push(c)}):t.push(s.getCoordinates()),r.push(s.toGeoJSON())}if(r.length>1){const i=this.newFeature({type:yr.FEATURE,properties:r[0].properties,geometry:{type:`Multi${n}`,coordinates:t}});this.addFeature(i),this.deleteFeature(this.getSelectedIds(),{silent:!0}),this.setSelected([i.id]),this.fire(la.COMBINE_FEATURES,{createdFeatures:[i.toGeoJSON()],deletedFeatures:r})}this.fireActionable()},An.onUncombineFeatures=function(){const e=this.getSelected();if(e.length===0)return;const t=[],r=[];for(let n=0;n<e.length;n++){const i=e[n];this.isInstanceOf("MultiFeature",i)&&(i.getFeatures().forEach(s=>{this.addFeature(s),s.properties=i.properties,t.push(s.toGeoJSON()),this.select([s.id])}),this.deleteFeature(i.id,{silent:!0}),r.push(i.toGeoJSON()))}t.length>1&&this.fire(la.UNCOMBINE_FEATURES,{createdFeatures:t,deletedFeatures:r}),this.fireActionable()};const gB=k0(Hi.VERTEX),yB=k0(Hi.MIDPOINT),Tn={};Tn.fireUpdate=function(){this.fire(la.UPDATE,{action:am.CHANGE_COORDINATES,features:this.getSelected().map(e=>e.toGeoJSON())})},Tn.fireActionable=function(e){this.setActionableState({combineFeatures:!1,uncombineFeatures:!1,trash:e.selectedCoordPaths.length>0})},Tn.startDragging=function(e,t){e.initialDragPanState=this.map.dragPan.isEnabled(),this.map.dragPan.disable(),e.canDragMove=!0,e.dragMoveLocation=t.lngLat},Tn.stopDragging=function(e){e.canDragMove&&e.initialDragPanState===!0&&this.map.dragPan.enable(),e.dragMoving=!1,e.canDragMove=!1,e.dragMoveLocation=null},Tn.onVertex=function(e,t){this.startDragging(e,t);const r=t.featureTarget.properties,n=e.selectedCoordPaths.indexOf(r.coord_path);!L0(t)&&n===-1?e.selectedCoordPaths=[r.coord_path]:L0(t)&&n===-1&&e.selectedCoordPaths.push(r.coord_path);const i=this.pathsToCoordinates(e.featureId,e.selectedCoordPaths);this.setSelectedCoordinates(i)},Tn.onMidpoint=function(e,t){this.startDragging(e,t);const r=t.featureTarget.properties;e.feature.addCoordinate(r.coord_path,r.lng,r.lat),this.fireUpdate(),e.selectedCoordPaths=[r.coord_path]},Tn.pathsToCoordinates=function(e,t){return t.map(r=>({feature_id:e,coord_path:r}))},Tn.onFeature=function(e,t){e.selectedCoordPaths.length===0?this.startDragging(e,t):this.stopDragging(e)},Tn.dragFeature=function(e,t,r){iC(this.getSelected(),r),e.dragMoveLocation=t.lngLat},Tn.dragVertex=function(e,t,r){const n=e.selectedCoordPaths.map(c=>e.feature.getCoordinate(c)),i=n.map(c=>({type:yr.FEATURE,properties:{},geometry:{type:yr.POINT,coordinates:c}})),s=nC(i,r);for(let c=0;c<n.length;c++){const a=n[c];e.feature.updateCoordinate(e.selectedCoordPaths[c],a[0]+s.lng,a[1]+s.lat)}},Tn.clickNoTarget=function(){this.changeMode(Vr.SIMPLE_SELECT)},Tn.clickInactive=function(){this.changeMode(Vr.SIMPLE_SELECT)},Tn.clickActiveFeature=function(e){e.selectedCoordPaths=[],this.clearSelectedCoordinates(),e.feature.changed()},Tn.onSetup=function(e){const t=e.featureId,r=this.getFeature(t);if(!r)throw new Error("You must provide a featureId to enter direct_select mode");if(r.type===yr.POINT)throw new TypeError("direct_select mode doesn't handle point features");const n={featureId:t,feature:r,dragMoveLocation:e.startPos||null,dragMoving:!1,canDragMove:!1,selectedCoordPaths:e.coordPath?[e.coordPath]:[]};return this.setSelectedCoordinates(this.pathsToCoordinates(t,n.selectedCoordPaths)),this.setSelected(t),Bs.disable(this),this.setActionableState({trash:!0}),n},Tn.onStop=function(){Bs.enable(this),this.clearSelectedCoordinates()},Tn.toDisplayFeatures=function(e,t,r){e.featureId===t.properties.id?(t.properties.active=vi.ACTIVE,r(t),B0(t,{map:this.map,midpoints:!0,selectedPaths:e.selectedCoordPaths}).forEach(r)):(t.properties.active=vi.INACTIVE,r(t)),this.fireActionable(e)},Tn.onTrash=function(e){e.selectedCoordPaths.sort((t,r)=>r.localeCompare(t,"en",{numeric:!0})).forEach(t=>e.feature.removeCoordinate(t)),this.fireUpdate(),e.selectedCoordPaths=[],this.clearSelectedCoordinates(),this.fireActionable(e),e.feature.isValid()===!1&&(this.deleteFeature([e.featureId]),this.changeMode(Vr.SIMPLE_SELECT,{}))},Tn.onMouseMove=function(e,t){const r=lu(t),n=gB(t),i=yB(t),s=e.selectedCoordPaths.length===0;return r&&s?this.updateUIClasses({mouse:Vn.MOVE}):n&&!s?this.updateUIClasses({mouse:Vn.MOVE}):this.updateUIClasses({mouse:Vn.NONE}),(n||r||i)&&e.dragMoving&&this.fireUpdate(),this.stopDragging(e),!0},Tn.onMouseOut=function(e){return e.dragMoving&&this.fireUpdate(),!0},Tn.onTouchStart=Tn.onMouseDown=function(e,t){if(gB(t))return this.onVertex(e,t);if(lu(t))return this.onFeature(e,t);if(yB(t))return this.onMidpoint(e,t)},Tn.onDrag=function(e,t){if(e.canDragMove!==!0)return;e.dragMoving=!0,t.originalEvent.stopPropagation();const r={lng:t.lngLat.lng-e.dragMoveLocation.lng,lat:t.lngLat.lat-e.dragMoveLocation.lat};e.selectedCoordPaths.length>0?this.dragVertex(e,t,r):this.dragFeature(e,t,r),e.dragMoveLocation=t.lngLat},Tn.onClick=function(e,t){if(D0(t))return this.clickNoTarget(e,t);if(lu(t))return this.clickActiveFeature(e,t);if(eC(t))return this.clickInactive(e,t);this.stopDragging(e)},Tn.onTap=function(e,t){if(D0(t))return this.clickNoTarget(e,t);if(lu(t))return this.clickActiveFeature(e,t);if(eC(t))return this.clickInactive(e,t)},Tn.onTouchEnd=Tn.onMouseUp=function(e){e.dragMoving&&this.fireUpdate(),this.stopDragging(e)};const vo={};vo.onSetup=function(){const e=this.newFeature({type:yr.FEATURE,properties:{},geometry:{type:yr.POINT,coordinates:[]}});return this.addFeature(e),this.clearSelectedFeatures(),this.updateUIClasses({mouse:Vn.ADD}),this.activateUIButton(Ia.POINT),this.setActionableState({trash:!0}),{point:e}},vo.stopDrawingAndRemove=function(e){this.deleteFeature([e.point.id],{silent:!0}),this.changeMode(Vr.SIMPLE_SELECT)},vo.onTap=vo.onClick=function(e,t){this.updateUIClasses({mouse:Vn.MOVE}),e.point.updateCoordinate("",t.lngLat.lng,t.lngLat.lat),this.fire(la.CREATE,{features:[e.point.toGeoJSON()]}),this.changeMode(Vr.SIMPLE_SELECT,{featureIds:[e.point.id]})},vo.onStop=function(e){this.activateUIButton(),e.point.getCoordinate().length||this.deleteFeature([e.point.id],{silent:!0})},vo.toDisplayFeatures=function(e,t,r){const n=t.properties.id===e.point.id;if(t.properties.active=n?vi.ACTIVE:vi.INACTIVE,!n)return r(t)},vo.onTrash=vo.stopDrawingAndRemove,vo.onKeyUp=function(e,t){if(N0(t)||R0(t))return this.stopDrawingAndRemove(e,t)};function z0(e,t){return e.lngLat?e.lngLat.lng===t[0]&&e.lngLat.lat===t[1]:!1}const js={};js.onSetup=function(){const e=this.newFeature({type:yr.FEATURE,properties:{},geometry:{type:yr.POLYGON,coordinates:[[]]}});return this.addFeature(e),this.clearSelectedFeatures(),Bs.disable(this),this.updateUIClasses({mouse:Vn.ADD}),this.activateUIButton(Ia.POLYGON),this.setActionableState({trash:!0}),{polygon:e,currentVertexPosition:0}},js.clickAnywhere=function(e,t){if(e.currentVertexPosition>0&&z0(t,e.polygon.coordinates[0][e.currentVertexPosition-1]))return this.changeMode(Vr.SIMPLE_SELECT,{featureIds:[e.polygon.id]});this.updateUIClasses({mouse:Vn.ADD}),e.polygon.updateCoordinate(`0.${e.currentVertexPosition}`,t.lngLat.lng,t.lngLat.lat),e.currentVertexPosition++,e.polygon.updateCoordinate(`0.${e.currentVertexPosition}`,t.lngLat.lng,t.lngLat.lat)},js.clickOnVertex=function(e){return this.changeMode(Vr.SIMPLE_SELECT,{featureIds:[e.polygon.id]})},js.onMouseMove=function(e,t){e.polygon.updateCoordinate(`0.${e.currentVertexPosition}`,t.lngLat.lng,t.lngLat.lat),lm(t)&&this.updateUIClasses({mouse:Vn.POINTER})},js.onTap=js.onClick=function(e,t){return lm(t)?this.clickOnVertex(e,t):this.clickAnywhere(e,t)},js.onKeyUp=function(e,t){N0(t)?(this.deleteFeature([e.polygon.id],{silent:!0}),this.changeMode(Vr.SIMPLE_SELECT)):R0(t)&&this.changeMode(Vr.SIMPLE_SELECT,{featureIds:[e.polygon.id]})},js.onStop=function(e){this.updateUIClasses({mouse:Vn.NONE}),Bs.enable(this),this.activateUIButton(),this.getFeature(e.polygon.id)!==void 0&&(e.polygon.removeCoordinate(`0.${e.currentVertexPosition}`),e.polygon.isValid()?this.fire(la.CREATE,{features:[e.polygon.toGeoJSON()]}):(this.deleteFeature([e.polygon.id],{silent:!0}),this.changeMode(Vr.SIMPLE_SELECT,{},{silent:!0})))},js.toDisplayFeatures=function(e,t,r){const n=t.properties.id===e.polygon.id;if(t.properties.active=n?vi.ACTIVE:vi.INACTIVE,!n)return r(t);if(t.geometry.coordinates.length===0)return;const i=t.geometry.coordinates[0].length;if(!(i<3)){if(t.properties.meta=Hi.FEATURE,r(fd(e.polygon.id,t.geometry.coordinates[0][0],"0.0",!1)),i>3){const s=t.geometry.coordinates[0].length-3;r(fd(e.polygon.id,t.geometry.coordinates[0][s],`0.${s}`,!1))}if(i<=4){const s=[[t.geometry.coordinates[0][0][0],t.geometry.coordinates[0][0][1]],[t.geometry.coordinates[0][1][0],t.geometry.coordinates[0][1][1]]];if(r({type:yr.FEATURE,properties:t.properties,geometry:{coordinates:s,type:yr.LINE_STRING}}),i===3)return}return r(t)}},js.onTrash=function(e){this.deleteFeature([e.polygon.id],{silent:!0}),this.changeMode(Vr.SIMPLE_SELECT)};const Fs={};Fs.onSetup=function(e){e=e||{};const t=e.featureId;let r,n,i="forward";if(t){if(r=this.getFeature(t),!r)throw new Error("Could not find a feature with the provided featureId");let s=e.from;if(s&&s.type==="Feature"&&s.geometry&&s.geometry.type==="Point"&&(s=s.geometry),s&&s.type==="Point"&&s.coordinates&&s.coordinates.length===2&&(s=s.coordinates),!s||!Array.isArray(s))throw new Error("Please use the `from` property to indicate which point to continue the line from");const c=r.coordinates.length-1;if(r.coordinates[c][0]===s[0]&&r.coordinates[c][1]===s[1])n=c+1,r.addCoordinate(n,...r.coordinates[c]);else if(r.coordinates[0][0]===s[0]&&r.coordinates[0][1]===s[1])i="backwards",n=0,r.addCoordinate(n,...r.coordinates[0]);else throw new Error("`from` should match the point at either the start or the end of the provided LineString")}else r=this.newFeature({type:yr.FEATURE,properties:{},geometry:{type:yr.LINE_STRING,coordinates:[]}}),n=0,this.addFeature(r);return this.clearSelectedFeatures(),Bs.disable(this),this.updateUIClasses({mouse:Vn.ADD}),this.activateUIButton(Ia.LINE),this.setActionableState({trash:!0}),{line:r,currentVertexPosition:n,direction:i}},Fs.clickAnywhere=function(e,t){if(e.currentVertexPosition>0&&z0(t,e.line.coordinates[e.currentVertexPosition-1])||e.direction==="backwards"&&z0(t,e.line.coordinates[e.currentVertexPosition+1]))return this.changeMode(Vr.SIMPLE_SELECT,{featureIds:[e.line.id]});this.updateUIClasses({mouse:Vn.ADD}),e.line.updateCoordinate(e.currentVertexPosition,t.lngLat.lng,t.lngLat.lat),e.direction==="forward"?(e.currentVertexPosition++,e.line.updateCoordinate(e.currentVertexPosition,t.lngLat.lng,t.lngLat.lat)):e.line.addCoordinate(0,t.lngLat.lng,t.lngLat.lat)},Fs.clickOnVertex=function(e){return this.changeMode(Vr.SIMPLE_SELECT,{featureIds:[e.line.id]})},Fs.onMouseMove=function(e,t){e.line.updateCoordinate(e.currentVertexPosition,t.lngLat.lng,t.lngLat.lat),lm(t)&&this.updateUIClasses({mouse:Vn.POINTER})},Fs.onTap=Fs.onClick=function(e,t){if(lm(t))return this.clickOnVertex(e,t);this.clickAnywhere(e,t)},Fs.onKeyUp=function(e,t){R0(t)?this.changeMode(Vr.SIMPLE_SELECT,{featureIds:[e.line.id]}):N0(t)&&(this.deleteFeature([e.line.id],{silent:!0}),this.changeMode(Vr.SIMPLE_SELECT))},Fs.onStop=function(e){Bs.enable(this),this.activateUIButton(),this.getFeature(e.line.id)!==void 0&&(e.line.removeCoordinate(`${e.currentVertexPosition}`),e.line.isValid()?this.fire(la.CREATE,{features:[e.line.toGeoJSON()]}):(this.deleteFeature([e.line.id],{silent:!0}),this.changeMode(Vr.SIMPLE_SELECT,{},{silent:!0})))},Fs.onTrash=function(e){this.deleteFeature([e.line.id],{silent:!0}),this.changeMode(Vr.SIMPLE_SELECT)},Fs.toDisplayFeatures=function(e,t,r){const n=t.properties.id===e.line.id;if(t.properties.active=n?vi.ACTIVE:vi.INACTIVE,!n)return r(t);t.geometry.coordinates.length<2||(t.properties.meta=Hi.FEATURE,r(fd(e.line.id,t.geometry.coordinates[e.direction==="forward"?t.geometry.coordinates.length-2:1],`${e.direction==="forward"?t.geometry.coordinates.length-2:1}`,!1)),r(t))};const vB={simple_select:An,direct_select:Tn,draw_point:vo,draw_polygon:js,draw_line_string:Fs},XEe={defaultMode:Vr.SIMPLE_SELECT,keybindings:!0,touchEnabled:!0,clickBuffer:2,touchBuffer:25,boxSelect:!0,displayControlsDefault:!0,styles:cB,modes:vB,controls:{},userProperties:!1,suppressAPIEvents:!0},ZEe={point:!0,line_string:!0,polygon:!0,trash:!0,combine_features:!0,uncombine_features:!0},YEe={point:!1,line_string:!1,polygon:!1,trash:!1,combine_features:!1,uncombine_features:!1};function bB(e,t){return e.map(r=>r.source?r:Object.assign({},r,{id:`${r.id}.${t}`,source:t==="hot"?ys.HOT:ys.COLD}))}function qEe(e={}){let t=Object.assign({},e);return e.controls||(t.controls={}),e.displayControlsDefault===!1?t.controls=Object.assign({},YEe,e.controls):t.controls=Object.assign({},ZEe,e.controls),t=Object.assign({},XEe,t),t.styles=bB(t.styles,"cold").concat(bB(t.styles,"hot")),t}var JEe=QEe,KEe={Point:"geometry",MultiPoint:"geometry",LineString:"geometry",MultiLineString:"geometry",Polygon:"geometry",MultiPolygon:"geometry",GeometryCollection:"geometry",Feature:"feature",FeatureCollection:"featurecollection"};function QEe(e){if(!e||!e.type)return null;var t=KEe[e.type];if(!t)return null;if(t==="geometry")return{type:"FeatureCollection",features:[{type:"Feature",properties:{},geometry:e}]};if(t==="feature")return{type:"FeatureCollection",features:[e]};if(t==="featurecollection")return e}const eAe=Qr(JEe);function xB(e,t){return e.length!==t.length?!1:JSON.stringify(e.map(r=>r).sort())===JSON.stringify(t.map(r=>r).sort())}const tAe={Polygon:Wa,LineString:yo,Point:Jl,MultiPolygon:ua,MultiLineString:ua,MultiPoint:ua};function rAe(e,t){t.modes=Vr;const r=e.options.suppressAPIEvents!==void 0?!!e.options.suppressAPIEvents:!0;return t.getFeatureIdsAt=function(n){return dd.click({point:n},null,e).map(s=>s.properties.id)},t.getSelectedIds=function(){return e.store.getSelectedIds()},t.getSelected=function(){return{type:yr.FEATURE_COLLECTION,features:e.store.getSelectedIds().map(n=>e.store.get(n)).map(n=>n.toGeoJSON())}},t.getSelectedPoints=function(){return{type:yr.FEATURE_COLLECTION,features:e.store.getSelectedCoordinates().map(n=>({type:yr.FEATURE,properties:{},geometry:{type:yr.POINT,coordinates:n.coordinates}}))}},t.set=function(n){if(n.type===void 0||n.type!==yr.FEATURE_COLLECTION||!Array.isArray(n.features))throw new Error("Invalid FeatureCollection");const i=e.store.createRenderBatch();let s=e.store.getAllIds().slice();const c=t.add(n),a=new vs(c);return s=s.filter(d=>!a.has(d)),s.length&&t.delete(s),i(),c},t.add=function(n){const s=JSON.parse(JSON.stringify(eAe(n))).features.map(c=>{if(c.id=c.id||KS(),c.geometry===null)throw new Error("Invalid geometry: null");if(e.store.get(c.id)===void 0||e.store.get(c.id).type!==c.geometry.type){const a=tAe[c.geometry.type];if(a===void 0)throw new Error(`Invalid geometry type: ${c.geometry.type}.`);const d=new a(e,c);e.store.add(d,{silent:r})}else{const a=e.store.get(c.id),d=a.properties;a.properties=c.properties,YP(d,c.properties)||e.store.featureChanged(a.id,{silent:r}),YP(a.getCoordinates(),c.geometry.coordinates)||a.incomingCoords(c.geometry.coordinates)}return c.id});return e.store.render(),s},t.get=function(n){const i=e.store.get(n);if(i)return i.toGeoJSON()},t.getAll=function(){return{type:yr.FEATURE_COLLECTION,features:e.store.getAll().map(n=>n.toGeoJSON())}},t.delete=function(n){return e.store.delete(n,{silent:r}),t.getMode()===Vr.DIRECT_SELECT&&!e.store.getSelectedIds().length?e.events.changeMode(Vr.SIMPLE_SELECT,void 0,{silent:r}):e.store.render(),t},t.deleteAll=function(){return e.store.delete(e.store.getAllIds(),{silent:r}),t.getMode()===Vr.DIRECT_SELECT?e.events.changeMode(Vr.SIMPLE_SELECT,void 0,{silent:r}):e.store.render(),t},t.changeMode=function(n,i={}){return n===Vr.SIMPLE_SELECT&&t.getMode()===Vr.SIMPLE_SELECT?(xB(i.featureIds||[],e.store.getSelectedIds())||(e.store.setSelected(i.featureIds,{silent:r}),e.store.render()),t):(n===Vr.DIRECT_SELECT&&t.getMode()===Vr.DIRECT_SELECT&&i.featureId===e.store.getSelectedIds()[0]||e.events.changeMode(n,i,{silent:r}),t)},t.getMode=function(){return e.events.getMode()},t.trash=function(){return e.events.trash({silent:r}),t},t.combineFeatures=function(){return e.events.combineFeatures({silent:r}),t},t.uncombineFeatures=function(){return e.events.uncombineFeatures({silent:r}),t},t.setFeatureProperty=function(n,i,s){return e.store.setFeatureProperty(n,i,s,{silent:r}),t},t}const nAe=Object.freeze(Object.defineProperty({__proto__:null,CommonSelectors:HEe,ModeHandler:VS,StringSet:vs,constrainFeatureMovement:nC,createMidPoint:hB,createSupplementaryPoints:B0,createVertex:fd,doubleClickZoom:Bs,euclideanDistance:YS,featuresAt:dd,getFeatureAtAndSetCursors:P0,isClick:qS,isEventAtCoordinates:z0,isTap:JS,mapEventToBoundingBox:iB,moveFeatures:iC,sortFeatures:nB,stringSetsAreEqual:xB,theme:cB,toDenseArray:sm},Symbol.toStringTag,{value:"Module"})),iAe=function(e,t){e=qEe(e);const r={options:e};t=rAe(r,t),r.api=t;const n=VEe(r);return t.onAdd=n.onAdd,t.onRemove=n.onRemove,t.types=Ia,t.options=e,t};function pd(e){iAe(e,this)}pd.modes=vB,pd.constants=tB,pd.lib=nAe;function aAe(){const{drawRef:e}=U.useContext(zi),t=pd.constants;t.classes.CONTROL_BASE="maplibregl-ctrl",t.classes.CONTROL_PREFIX="maplibregl-ctrl-",t.classes.CONTROL_GROUP="maplibregl-ctrl-group";const r=U.useCallback(i=>{console.log("onCreate")},[]),n=r;return Wu(()=>{const i=new pd({displayControlsDefault:!1,styles:[{id:"gl-draw-polygon-fill",type:"fill",filter:["all",["==","$type","Polygon"],["!=","mode","static"]],paint:{"fill-color":"#FF0000","fill-opacity":.5}},{id:"gl-draw-line-active",type:"line",filter:["all",["==","$type","LineString"],["==","active","true"]],layout:{"line-cap":"round","line-join":"round"},paint:{"line-color":"#FF0000","line-width":3,"line-dasharray":[2,2]}},{id:"gl-draw-polygon-stroke-active",type:"line",filter:["all",["==","$type","Polygon"],["!=","mode","static"]],layout:{"line-cap":"round","line-join":"round"},paint:{"line-color":"#0000FF","line-width":2}},{id:"gl-draw-polygon-midpoint",type:"circle",filter:["all",["==","meta","midpoint"]],paint:{"circle-radius":5,"circle-color":"#00FF00"}},{id:"gl-draw-polygon-vertex",type:"circle",filter:["all",["==","meta","vertex"],["==","$type","Point"]],paint:{"circle-radius":7,"circle-color":"#FFA500"}},{id:"gl-draw-polygon-point-active",type:"circle",filter:["all",["==","active","true"],["==","$type","Point"]],paint:{"circle-radius":10,"circle-color":"red"}}]});return e.current=i,i},({map:i})=>{i.on("draw.create",r),i.on("draw.update",n)},({map:i})=>{i.off("draw.create",r),i.off("draw.update",n)},{position:"top-right"}),null}const sAe=()=>{const e=$t(n=>n.viewMode),t=$t(n=>n.cursorCords),r=$t(n=>n.hoveredValue);return X.jsxs("div",{className:"absolute bottom-0 left-0 w-full bg-black bg-opacity-50 p-1 text-xs text-white flex justify-between",children:[X.jsxs("span",{children:["mode: ",e]}),X.jsxs("span",{children:[r&&X.jsxs("span",{children:[X.jsxs("span",{children:[r.label,":",(r==null?void 0:r.value)&&r.value]}),X.jsx("div",{style:{width:10,height:10,backgroundColor:r.color,display:"inline-block"}})]})," ",X.jsx("span",{children:`${t[0].toFixed(6)}, ${t[1].toFixed(6)}`})]})]})};var aC="Tabs",[oAe,qPe]=ko(aC,[Ng]),_B=Ng(),[lAe,sC]=oAe(aC),wB=Ae.forwardRef((e,t)=>{const{__scopeTabs:r,value:n,onValueChange:i,defaultValue:s,orientation:c="horizontal",dir:a,activationMode:d="automatic",...p}=e,y=Xx(a),[g,v]=Ju({prop:n,onChange:i,defaultProp:s});return X.jsx(lAe,{scope:r,baseId:Ic(),value:g,onValueChange:v,orientation:c,dir:y,activationMode:d,children:X.jsx(In.div,{dir:y,"data-orientation":c,...p,ref:t})})});wB.displayName=aC;var SB="TabsList",CB=Ae.forwardRef((e,t)=>{const{__scopeTabs:r,loop:n=!0,...i}=e,s=sC(SB,r),c=_B(r);return X.jsx(kA,{asChild:!0,...c,orientation:s.orientation,dir:s.dir,loop:n,children:X.jsx(In.div,{role:"tablist","aria-orientation":s.orientation,...i,ref:t})})});CB.displayName=SB;var MB="TabsTrigger",EB=Ae.forwardRef((e,t)=>{const{__scopeTabs:r,value:n,disabled:i=!1,...s}=e,c=sC(MB,r),a=_B(r),d=IB(c.baseId,n),p=PB(c.baseId,n),y=n===c.value;return X.jsx(DA,{asChild:!0,...a,focusable:!i,active:y,children:X.jsx(In.button,{type:"button",role:"tab","aria-selected":y,"aria-controls":p,"data-state":y?"active":"inactive","data-disabled":i?"":void 0,disabled:i,id:d,...s,ref:t,onMouseDown:an(e.onMouseDown,g=>{!i&&g.button===0&&g.ctrlKey===!1?c.onValueChange(n):g.preventDefault()}),onKeyDown:an(e.onKeyDown,g=>{[" ","Enter"].includes(g.key)&&c.onValueChange(n)}),onFocus:an(e.onFocus,()=>{const g=c.activationMode!=="manual";!y&&!i&&g&&c.onValueChange(n)})})})});EB.displayName=MB;var AB="TabsContent",TB=Ae.forwardRef((e,t)=>{const{__scopeTabs:r,value:n,forceMount:i,children:s,...c}=e,a=sC(AB,r),d=IB(a.baseId,n),p=PB(a.baseId,n),y=n===a.value,g=Ae.useRef(y);return Ae.useEffect(()=>{const v=requestAnimationFrame(()=>g.current=!1);return()=>cancelAnimationFrame(v)},[]),X.jsx(qs,{present:i||y,children:({present:v})=>X.jsx(In.div,{"data-state":y?"active":"inactive","data-orientation":a.orientation,role:"tabpanel","aria-labelledby":d,hidden:!v,id:p,tabIndex:0,...c,ref:t,style:{...e.style,animationDuration:g.current?"0s":void 0},children:v&&s})})});TB.displayName=AB;function IB(e,t){return`${e}-trigger-${t}`}function PB(e,t){return`${e}-content-${t}`}var cAe=wB,OB=CB,kB=EB,DB=TB;const uAe=cAe,LB=Ae.forwardRef(({className:e,...t},r)=>X.jsx(OB,{ref:r,className:Nr("inline-flex h-10 items-center justify-center rounded-md bg-muted p-1 text-muted-foreground",e),...t}));LB.displayName=OB.displayName;const oC=Ae.forwardRef(({className:e,...t},r)=>X.jsx(kB,{ref:r,className:Nr("inline-flex items-center justify-center whitespace-nowrap rounded-sm px-3 py-1.5 text-sm font-medium ring-offset-background transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:bg-background data-[state=active]:text-foreground data-[state=active]:shadow-sm",e),...t}));oC.displayName=kB.displayName;const NB=Ae.forwardRef(({className:e,...t},r)=>X.jsx(DB,{ref:r,className:Nr("mt-2 ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",e),...t}));NB.displayName=DB.displayName;function RB({value:e,children:t}){return X.jsx(NB,{value:e,children:t})}rr.arrayOf(rr.shape({id:rr.string.isRequired,title:rr.string.isRequired,icon:rr.node,content:rr.node.isRequired,tooltipText:rr.string})).isRequired,rr.string.isRequired,rr.func,rr.func;function hAe(e){return kc({tag:"svg",attr:{viewBox:"0 0 576 512"},child:[{tag:"path",attr:{d:"M565.6 36.2C572.1 40.7 576 48.1 576 56l0 336c0 10-6.2 18.9-15.5 22.4l-168 64c-5.2 2-10.9 2.1-16.1 .3L192.5 417.5l-160 61c-7.4 2.8-15.7 1.8-22.2-2.7S0 463.9 0 456L0 120c0-10 6.1-18.9 15.5-22.4l168-64c5.2-2 10.9-2.1 16.1-.3L383.5 94.5l160-61c7.4-2.8 15.7-1.8 22.2 2.7zM48 136.5l0 284.6 120-45.7 0-284.6L48 136.5zM360 422.7l0-285.4-144-48 0 285.4 144 48zm48-1.5l120-45.7 0-284.6L408 136.5l0 284.6z"},child:[]}]})(e)}function dAe(e){return kc({tag:"svg",attr:{fill:"none",viewBox:"0 0 24 24",strokeWidth:"1.5",stroke:"currentColor","aria-hidden":"true"},child:[{tag:"path",attr:{strokeLinecap:"round",strokeLinejoin:"round",d:"M15 10.5a3 3 0 1 1-6 0 3 3 0 0 1 6 0Z"},child:[]},{tag:"path",attr:{strokeLinecap:"round",strokeLinejoin:"round",d:"M19.5 10.5c0 7.142-7.5 11.25-7.5 11.25S4.5 17.642 4.5 10.5a7.5 7.5 0 1 1 15 0Z"},child:[]}]})(e)}function fAe(){const e=$t(g=>g.pickerData),t=$t(g=>g.setPickerData),r=$t(g=>g.rasterLayer),[n,i]=U.useState(null),[s,c]=U.useState(!1),[a,d]=U.useState(null),p=e==null?void 0:e.dateRange;console.log("inside area details picker",p);function y(g){console.log("getting value"),c(!0),i(null),d(null);const v=g.coordinates;console.log("coordinates are",v);const w=1e-6,S=[v.lng-w,v.lat-w,v.lng+w,v.lat+w].join(","),C="https://d27s6pvwcjpmsu.cloudfront.net/geoserver/ne/wms",M=new URLSearchParams({service:"WMS",version:"1.1.1",request:"GetFeatureInfo",layers:"ne:et_data",query_layers:"ne:et_data",bbox:S,width:1,height:1,srs:"EPSG:4326",time:(p==null?void 0:p.start.toISOString().split("T")[0])||void 0,info_format:"application/json",x:0,y:0}),I=`${C}?${M.toString()}`;return fetch(I).then(E=>(console.log("response is",E),E.json())).then(E=>{var O,N,D,L,R;console.log("Received coverage data for point:",E),console.log("Data:",E,typeof E),((O=E==null?void 0:E.features)==null?void 0:O.length)>0&&(console.log("Value is",(D=(N=E==null?void 0:E.features[0])==null?void 0:N.properties)==null?void 0:D.GRAY_INDEX),i((R=(L=E==null?void 0:E.features[0])==null?void 0:L.properties)==null?void 0:R.GRAY_INDEX))}).catch(E=>(console.error("There was a problem with the fetch operation:",E.message),i(void 0),d("could not load ET value at point"),null)).finally(()=>{c(!1)})}return U.useEffect(()=>{console.log("pickerData",e),e&&r.value==="ET"&&y(e)},[e,r]),U.useEffect(()=>{e&&r.value==="ET"&&y(e)},[p]),e?X.jsx(X.Fragment,{children:X.jsx(Fo,{open:!0,setOpen:()=>t(null),title:"Area Details",headerClassName:"m-4",children:X.jsxs(uAe,{className:"flex flex-col w-full h-full overflow-y-hidden",defaultValue:"point",children:[X.jsxs(LB,{className:"grid w-full grid-cols-2","aria-label":"Manage your account",children:[X.jsxs(oC,{value:"point",children:[X.jsx(dAe,{className:"cursor-pointer"})," ",X.jsx("span",{children:"Point"})]}),(e==null?void 0:e.plot)&&X.jsxs(oC,{value:"plot",tooltipText:"Plot",children:[X.jsx(hAe,{className:"cursor-pointer"})," ",X.jsx("span",{children:"Plot"})]})]}),X.jsx("br",{}),X.jsxs(RB,{value:"point",children:[r.value==="3_NDVI"&&X.jsx(zS,{point:e.coordinates}),s?X.jsx(Ra,{}):a?X.jsx("div",{className:"text-red ",children:"Could not load ET value"}):n&&X.jsxs("div",{className:"flex items-center justify-between w-full gap-2 rounded-md bg-zinc-100 dark:bg-zinc-800 p-2 ",children:[X.jsxs("h4",{className:"scroll-m-20 text-xs font-medium tracking-tight",children:["ET value at this point (",e.dateRange.start.toISOString().split("T")[0],")"]}),X.jsx("div",{className:"flex items-center space-x-2",children:X.jsx("span",{className:"text-xs text-gray-700 dark:text-gray-200 font-bold",children:n.toFixed(3)})})]})]}),(e==null?void 0:e.plot)&&X.jsx(RB,{value:"plot",children:X.jsx(zS,{plot:e.plot})})]})})}):null}(lj=$t.getState().configs)==null||lj.VITE_SENTINAL_HUB_WMTS_ID;function BB({layer:e,dateRange:t}){var a;const n=`https://services.sentinel-hub.com/ogc/wmts/${(a=$t.getState().configs)==null?void 0:a.VITE_SENTINAL_HUB_WMTS_ID}?TILEMATRIXSET=PopularWebMercator256&Service=WMTS&Request=GetTile&RESOLUTION=10&MAXCC=20&TileMatrix={z}&TileCol={x}&TileRow={y}&FORMAT=image/png`;if(console.log("dateRange",t),!e||!t||!(t!=null&&t.start))return null;t.start instanceof Date&&(t.start=t.start.toISOString().split("T")[0]),t.end instanceof Date&&(t.end=t.end.toISOString().split("T")[0]);const i=`${t.start}/${t.end}`,s=pg.find(d=>d.value===e);return s&&(s!=null&&s.url)?`${s.url}&TIME=${i}`:`${n}&LAYER=${e}&TIME=${i}`}const jB=({mapRef:e,dateRange:t})=>{var w;const{isVisible:r}=U.useContext(Hf),n=$t(S=>S.showCroppedImages);console.log("uuu daterange inside NDVI layre",t);const i=$t(S=>S.rasterLayer),[s,c]=U.useState(BB({layer:i.value,dateRange:{...t}})),[a,d]=U.useState(null),p=$t(S=>S.rasterOpacity),y=e==null?void 0:e.current,g=(w=e==null?void 0:e.current)==null?void 0:w.getMap();U.useEffect(()=>{console.log("uuu dateRange in useEffect layerUrl",t);const S=BB({layer:i.value,dateRange:{...t}});console.log("uuu url has changed",S),c(S)},[i,t]),U.useEffect(()=>{console.log("uuu dateRnage has changeed",t)},[t]),U.useEffect(()=>{y&&(y!=null&&y.loaded())&&y.getLayer("plots-line-layer")?(console.log("order setting before id to plots-line-layer"),d("plots-line-layer")):(console.log("order setting before id to plots-line-layer"),d(null))},[y]);const v=U.useCallback(S=>{console.log("croppp handleLayerOrder");const C=g.getLayersOrder();console.log("layers",C),g.getLayer("plots-line-layer")&&g.getLayer("raster-layer")&&C.indexOf("plots-line-layer")<C.indexOf("raster-layer")&&(console.log("reordering layers"),g.moveLayer("raster-layer","plots-line-layer"))},[y]);return U.useEffect(()=>(g&&g.on("style.load",v),()=>{g&&g.off("style.load",v)}),[y]),s?X.jsx(X.Fragment,{children:r&&!n&&X.jsx(hE,{id:"raster-source",type:"raster",tiles:[s],tileSize:256,minzoom:10,maxzoom:21,children:X.jsx(gx,{id:"raster-layer",type:"raster",source:"raster-source",paint:{"raster-opacity":p/100},beforeId:a||void 0})})}):null},pAe=[{color:"#ffffcc",label:"Bare Soil"},{color:"#c7e9b4",label:"Low Vegetation"},{color:"#7fcdbb",label:"Moderate Vegetation"},{color:"#41b6c4",label:"Healthy Vegetation"},{color:"#1d91c0",label:"Very Healthy Vegetation"},{color:"#225ea8",label:"Dense Vegetation"},{color:"#0c2c84",label:"Water Bodies"}],mAe=[{color:"#f8d5cc",label:"Bare Soil"},{color:"#d73027",label:"Low Vegetation"},{color:"#f46d43",label:"Sparse Vegetation"},{color:"#66bd63",label:"Moderate Vegetation"},{color:"#1a9850",label:"Healthy Vegetation"},{color:"#542788",label:"Water"}],gAe=[{color:"#a50026",label:"Very Dry"},{color:"#d73027",label:"Dry"},{color:"#f46d43",label:"Moderate Moisture"},{color:"#fdae61",label:"High Moisture"},{color:"#fee08b",label:"Very High Moisture"},{color:"#d9ef8b",label:"Saturated"},{color:"#66bd63",label:"Water Body"}],FB=()=>{const e=$t(a=>a.rasterLayer),t=$t(a=>a.pixelColor),r=Zn(),n=[{color:"#004400",label:` (${r.formatNumber(.5)} to ${r.formatNumber(1)})`},{color:"#0f540a",label:` (${r.formatNumber(.4)} to ${r.formatNumber(.5)})`},{color:"#3f7c23",label:` (${r.formatNumber(.25)} to ${r.formatNumber(.3)})`},{color:"#bcb76b",label:` (${r.formatNumber(-.1)} to ${r.formatNumber(0)})`},{color:"#fff9cc",label:` (${r.formatNumber(-.35)} to ${r.formatNumber(-.3)})`},{color:"#c0c0c0",label:` (${r.formatNumber(-.7)} to ${r.formatNumber(-.6)})`},{color:"#0c0c0c",label:` (${r.formatNumber(-1)} to ${r.formatNumber(-.7)})`}],i=[{color:"#00008B",label:`Very Low (${r.formatNumber(.001)})`},{color:"#0000FF",label:`Low (${r.formatNumber(3)})`},{color:"#00FF00",label:`Moderate (${r.formatNumber(6)})`},{color:"#FFA500",label:`High (${r.formatNumber(9)})`},{color:"#FF0000",label:`Very High (${r.formatNumber(12)})`}];console.log("colorLegend rasterLayer",e);let s;switch(e==null?void 0:e.value){case"3_NDVI":s=n;break;case"AGRICULTURE":s=pAe;break;case"2_FALSE_COLOR":s=mAe;break;case"5-MOISTURE-INDEX1":s=gAe;break;case"ET":s=i}if(!s)return null;const c=s.find(a=>a.color==t);return console.log("item",c),X.jsxs("div",{className:"legend",children:[X.jsx("h4",{className:"mb-2",children:e==null?void 0:e.label}),s.map((a,d)=>X.jsxs("div",{className:"legend-item",style:{fontSize:"1.4em"},children:[X.jsx("span",{className:"legend-color",style:{backgroundColor:a.color}}),X.jsx("span",{children:a.label})]},d))]})};function zB(e){const[t,r,n]=e,i=Math.round(t).toString(16).padStart(2,"0"),s=Math.round(r).toString(16).padStart(2,"0"),c=Math.round(n).toString(16).padStart(2,"0");return`#${i}${s}${c}`}function yAe(e,t){return e==="NDVI_RAW"?{label:"NDVI",value:(t[1]/127.5-1).toFixed(2),color:zB(t)}:{label:"color",value:null,color:zB(t)}}function $B({dateRange:e,mapRef:t,showButton:r=!0}){var E;console.log("ppp mapRef",t);const n=(E=t==null?void 0:t.current)==null?void 0:E.getMap(),i=$t(O=>O.viewMode);$t(O=>O.mapMode);const s=$t(O=>O.toggleNormalPickerMode),c=$t(O=>O.toNormalMode),a=$t(O=>O.setPickerData),d=$t(O=>O.setCursorCords),p=$t(O=>O.setHoveredValue),y=$t(O=>O.rasterLayer),g=$t(O=>O.setCursor),v=$t(O=>O.resetCursor),w=Zn(),S=$t(O=>O.rasterOpacity),C=$t(O=>O.setRasterOpacity),M=U.useCallback(()=>{console.log("back to currentOpacity",S),C(100)},[S,C]),I=O=>{n&&(i==="PICKER"?n.setPaintProperty("raster-layer","raster-opacity",1):M()),s()};return U.useEffect(()=>{const O=N=>{N.key==="Escape"&&(M(),c())};return i==="PICKER"&&window.addEventListener("keydown",O),()=>{window.removeEventListener("keydown",O)}},[c,S,n,M,i]),U.useEffect(()=>{if(console.log("eee event",n,i),!n||i!=="PICKER")return;const O=N=>{console.log("eee clicked on map",e);let D={coordinates:N.lngLat,dateRange:e};if(n.getLayer("plots-layer")){const L=n.queryRenderedFeatures(N.point,{layers:["plots-layer"]});L.length>0&&(D.plot=L[0])}console.log("setting picker data",D),a(D)};return console.log("added event handler"),n.on("click",O),()=>{n.off("click",O)}},[n,i,e,a]),U.useEffect(()=>{const O=N=>{const{lng:D,lat:L}=N.lngLat;d([D,L])};return n&&n.on("mousemove",O),()=>{n&&n.off("mousemove",O)}},[n,d,i]),U.useEffect(()=>{const N=Wf(D=>{const L=n.getCanvas(),R=n.painter.context.gl;if(!R){console.error("WebGL context is not available.");return}const Y=new Uint8Array(4),ie=window.devicePixelRatio||1,re=Math.floor(D.point.x*ie),V=Math.floor(L.height-D.point.y*ie);if(re<0||V<0||re>=L.width||V>=L.height){console.warn("Mouse is outside the canvas bounds");return}R.readPixels(re,V,1,1,R.RGBA,R.UNSIGNED_BYTE,Y);const Z=yAe(y==null?void 0:y.value,Y);p(Z)},100);return n&&i==="PICKER"&&(n!=null&&n.loaded)&&(console.log("Adding pixel event listener"),n.on("mousemove",N)),()=>{n&&n.off("mousemove",N)}},[n,i,p,y]),U.useEffect(()=>{i==="PICKER"?g("crosshair"):v()},[i]),r?X.jsx(Fr,{variant:"outline",size:"icon",title:w.formatMessage({id:"app.agviewer_map.activate_picker_mode",defaultMessage:"Activate picker mode"}),"aria-label":w.formatMessage({id:"app.agviewer_map.activate_picker_mode",defaultMessage:"Activate picker mode"}),onClick:I,className:` ${i===Ur.PICKER?" bg-gray-200 dark:bg-gray-600":""}`,children:X.jsx(gz,{})}):null}function GB({dateRange:e,mapRef:t}){const{current:r}=yg(),[n,i]=U.useState(!1);U.useRef(null);const{settings:s,setSettings:c}=U.useContext(of),[a,d]=U.useState(!1),p=$t(I=>I.setViewMode),y=$t(I=>I.viewMode),g=$t(I=>I.mapMode),v=$t(I=>I.setMapMode),w=Zn(),S=()=>{g==La.COMPARISION_VIEW?v(La.NORMAL):v(La.COMPARISION_VIEW)},C=U.useCallback(()=>{i(I=>!I),c(I=>({...I,basemap:{...I.basemap,id:I.basemap.id==="basic"?"satellite":"basic"}}))},[c]),M=U.useCallback(()=>{if(!r)return;const E=r.getContainer().parentNode;document.fullscreenElement?(document.exitFullscreen(),d(!1)):E.requestFullscreen?E.requestFullscreen():E.mozRequestFullScreen?E.mozRequestFullScreen():E.webkitRequestFullscreen?E.webkitRequestFullscreen():E.msRequestFullscreen&&E.msRequestFullscreen(),d(!0)},[r]);return y===Ur.ADD_PLOT||y===Ur.ADD_MARKER||y===Ur.EDIT_PLOT||y===Ur.EDIT_MARKER?null:X.jsx(X.Fragment,{children:X.jsxs("div",{className:" gap-1 flex flex-col",children:[r&&X.jsx(Fr,{variant:"outline",size:"icon","aria-label":"Change view mode",title:w.formatMessage({id:"app.agviewer_map.change_view_mode",defaultMessage:"Change view mode"}),onClick:C,children:s.basemap.id==="basic"?X.jsx(yz,{}):X.jsx(uz,{})}),X.jsx(Fr,{variant:"outline",size:"icon",onClick:M,children:a?X.jsx(dz,{}):X.jsx(hz,{})}),X.jsx(Fr,{variant:"outline",size:"icon",onClick:S,children:g===La.COMPARISION_VIEW?X.jsx(vz,{}):X.jsx(bz,{})}),X.jsx($B,{dateRange:e,mapRef:t}),g!==La.COMPARISION_VIEW&&X.jsxs(X.Fragment,{children:[X.jsx(Fr,{variant:"outline",size:"icon",title:w.formatMessage({id:"app.agviewer_map.add_view_plot",defaultMessage:"Add new plot"}),onClick:()=>p(Ur.ADD_PLOT),children:X.jsx(cz,{})}),X.jsx(Fr,{variant:"outline",size:"icon",title:w.formatMessage({id:"app.agviewer_map.add_new_station",defaultMessage:"Add new station"}),onClick:()=>p(Ur.ADD_MARKER),children:X.jsx(mz,{})}),X.jsx(Fr,{variant:"outline",size:"icon",title:w.formatMessage({id:"app.agviewer_map.add_new_farm_title",defaultMessage:"Add new farm"}),onClick:()=>p(y===Ur.ADD_NEW_FARM?Ur.NORMAL:Ur.ADD_NEW_FARM),children:X.jsx(xz,{})})]})]})})}const lC=768;function vAe(){const[e,t]=Ae.useState(void 0);return Ae.useEffect(()=>{const r=window.matchMedia(`(max-width: ${lC-1}px)`),n=()=>{t(window.innerWidth<lC)};return r.addEventListener("change",n),t(window.innerWidth<lC),()=>r.removeEventListener("change",n)},[]),!!e}const VB=Ae.forwardRef(({className:e,type:t,...r},n)=>X.jsx("input",{type:t,className:Nr("flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-base ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",e),ref:n,...r}));VB.displayName="Input";var bAe="Separator",WB="horizontal",xAe=["horizontal","vertical"],HB=Ae.forwardRef((e,t)=>{const{decorative:r,orientation:n=WB,...i}=e,s=_Ae(n)?n:WB,a=r?{role:"none"}:{"aria-orientation":s==="vertical"?s:void 0,role:"separator"};return X.jsx(In.div,{"data-orientation":s,...a,...i,ref:t})});HB.displayName=bAe;function _Ae(e){return xAe.includes(e)}var UB=HB;const XB=Ae.forwardRef(({className:e,orientation:t="horizontal",decorative:r=!0,...n},i)=>X.jsx(UB,{ref:i,decorative:r,orientation:t,className:Nr("shrink-0 bg-border",t==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",e),...n}));XB.displayName=UB.displayName;const wAe=s_,SAe=o_,ZB=Ae.forwardRef(({className:e,...t},r)=>X.jsx(my,{className:Nr("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",e),...t,ref:r}));ZB.displayName=my.displayName;const CAe=C1("fixed z-50 gap-4 bg-background p-6 shadow-lg transition ease-in-out data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:duration-300 data-[state=open]:duration-500",{variants:{side:{top:"inset-x-0 top-0 border-b data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top",bottom:"inset-x-0 bottom-0 border-t data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom",left:"inset-y-0 left-0 h-full w-3/4 border-r data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left sm:max-w-sm",right:"inset-y-0 right-0 h-full w-3/4 border-l data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right sm:max-w-sm"}},defaultVariants:{side:"right"}}),YB=Ae.forwardRef(({side:e="right",className:t,children:r,...n},i)=>X.jsxs(SAe,{children:[X.jsx(ZB,{}),X.jsxs(gy,{ref:i,className:Nr(CAe({side:e}),t),...n,children:[r,X.jsxs(l_,{className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-secondary",children:[X.jsx(El,{className:"h-4 w-4"}),X.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));YB.displayName=gy.displayName;const MAe=Ae.forwardRef(({className:e,...t},r)=>X.jsx(yy,{ref:r,className:Nr("text-lg font-semibold text-foreground",e),...t}));MAe.displayName=yy.displayName;const EAe=Ae.forwardRef(({className:e,...t},r)=>X.jsx(vy,{ref:r,className:Nr("text-sm text-muted-foreground",e),...t}));EAe.displayName=vy.displayName;function qB({className:e,...t}){return X.jsx("div",{className:Nr("animate-pulse rounded-md bg-muted",e),...t})}const AAe=CA,TAe=MA,IAe=EA,JB=Ae.forwardRef(({className:e,sideOffset:t=4,...r},n)=>X.jsx(Wx,{ref:n,sideOffset:t,className:Nr("z-50 overflow-hidden rounded-md border bg-popover px-3 py-1.5 text-sm text-popover-foreground shadow-md animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",e),...r}));JB.displayName=Wx.displayName;const PAe="sidebar:state",OAe=60*60*24*7,kAe="16rem",DAe="18rem",LAe="3rem",NAe="b",KB=Ae.createContext(null);function $0(){const e=Ae.useContext(KB);if(!e)throw new Error("useSidebar must be used within a SidebarProvider.");return e}const QB=Ae.forwardRef(({defaultOpen:e=!0,open:t,onOpenChange:r,className:n,style:i,children:s,...c},a)=>{const d=vAe(),[p,y]=Ae.useState(!1),[g,v]=Ae.useState(e),w=t??g,S=Ae.useCallback(E=>{const O=typeof E=="function"?E(w):E;r?r(O):v(O),document.cookie=`${PAe}=${O}; path=/; max-age=${OAe}`},[r,w]),C=Ae.useCallback(()=>d?y(E=>!E):S(E=>!E),[d,S,y]);Ae.useEffect(()=>{const E=O=>{O.key===NAe&&(O.metaKey||O.ctrlKey)&&(O.preventDefault(),C())};return window.addEventListener("keydown",E),()=>window.removeEventListener("keydown",E)},[C]);const M=w?"expanded":"collapsed",I=Ae.useMemo(()=>({state:M,open:w,setOpen:S,isMobile:d,openMobile:p,setOpenMobile:y,toggleSidebar:C}),[M,w,S,d,p,y,C]);return X.jsx(KB.Provider,{value:I,children:X.jsx(AAe,{delayDuration:0,children:X.jsx("div",{style:{"--sidebar-width":kAe,"--sidebar-width-icon":LAe,...i},className:Nr("group/sidebar-wrapper flex min-h-svh w-full has-[[data-variant=inset]]:bg-sidebar",n),ref:a,...c,children:s})})})});QB.displayName="SidebarProvider";const RAe=Ae.forwardRef(({side:e="left",variant:t="sidebar",collapsible:r="offcanvas",className:n,children:i,...s},c)=>{const{isMobile:a,state:d,openMobile:p,setOpenMobile:y}=$0();return r==="none"?X.jsx("div",{className:Nr("flex w-[--sidebar-width] flex-col bg-sidebar text-sidebar-foreground",n),ref:c,...s,children:i}):a?X.jsx(wAe,{open:p,onOpenChange:y,...s,children:X.jsx(YB,{"data-sidebar":"sidebar","data-mobile":"true",className:"w-[--sidebar-width] bg-sidebar p-0 text-sidebar-foreground [&>button]:hidden",style:{"--sidebar-width":DAe},side:e,children:X.jsx("div",{className:"flex h-full w-full flex-col",children:i})})}):X.jsxs("div",{ref:c,className:"group peer hidden md:block text-sidebar-foreground","data-state":d,"data-collapsible":d==="collapsed"?r:"","data-variant":t,"data-side":e,children:[X.jsx("div",{className:Nr("duration-200 relative h-svh w-[--sidebar-width] bg-transparent transition-[width] ease-linear","group-data-[collapsible=offcanvas]:w-0","group-data-[side=right]:rotate-180",t==="floating"||t==="inset"?"group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)_+_theme(spacing.4))]":"group-data-[collapsible=icon]:w-[--sidebar-width-icon]")}),X.jsx("div",{className:Nr("duration-200 fixed inset-y-0 z-10 hidden h-svh w-[--sidebar-width] transition-[left,right,width] ease-linear md:flex",e==="left"?"left-0 group-data-[collapsible=offcanvas]:left-[calc(var(--sidebar-width)*-1)]":"right-0 group-data-[collapsible=offcanvas]:right-[calc(var(--sidebar-width)*-1)]",t==="floating"||t==="inset"?"p-2 group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)_+_theme(spacing.4)_+2px)]":"group-data-[collapsible=icon]:w-[--sidebar-width-icon] group-data-[side=left]:border-r group-data-[side=right]:border-l",n),...s,children:X.jsx("div",{"data-sidebar":"sidebar",className:"flex h-full w-full flex-col bg-sidebar group-data-[variant=floating]:rounded-lg group-data-[variant=floating]:border group-data-[variant=floating]:border-sidebar-border group-data-[variant=floating]:shadow",children:i})})]})});RAe.displayName="Sidebar";const BAe=Ae.forwardRef(({className:e,onClick:t,...r},n)=>{const{toggleSidebar:i}=$0();return X.jsxs(Fr,{ref:n,"data-sidebar":"trigger",variant:"ghost",size:"icon",className:Nr("h-7 w-7",e),onClick:s=>{t==null||t(s),i()},...r,children:[X.jsx(pz,{}),X.jsx("span",{className:"sr-only",children:"Toggle Sidebar"})]})});BAe.displayName="SidebarTrigger";const jAe=Ae.forwardRef(({className:e,...t},r)=>{const{toggleSidebar:n}=$0();return X.jsx("button",{ref:r,"data-sidebar":"rail","aria-label":"Toggle Sidebar",tabIndex:-1,onClick:n,title:"Toggle Sidebar",className:Nr("absolute inset-y-0 z-20 hidden w-4 -translate-x-1/2 transition-all ease-linear after:absolute after:inset-y-0 after:left-1/2 after:w-[2px] hover:after:bg-sidebar-border group-data-[side=left]:-right-4 group-data-[side=right]:left-0 sm:flex","[[data-side=left]_&]:cursor-w-resize [[data-side=right]_&]:cursor-e-resize","[[data-side=left][data-state=collapsed]_&]:cursor-e-resize [[data-side=right][data-state=collapsed]_&]:cursor-w-resize","group-data-[collapsible=offcanvas]:translate-x-0 group-data-[collapsible=offcanvas]:after:left-full group-data-[collapsible=offcanvas]:hover:bg-sidebar","[[data-side=left][data-collapsible=offcanvas]_&]:-right-2","[[data-side=right][data-collapsible=offcanvas]_&]:-left-2",e),...t})});jAe.displayName="SidebarRail";const FAe=Ae.forwardRef(({className:e,...t},r)=>X.jsx("main",{ref:r,className:Nr("relative flex min-h-svh flex-1 flex-col bg-background","peer-data-[variant=inset]:min-h-[calc(100svh-theme(spacing.4))] md:peer-data-[variant=inset]:m-2 md:peer-data-[state=collapsed]:peer-data-[variant=inset]:ml-2 md:peer-data-[variant=inset]:ml-0 md:peer-data-[variant=inset]:rounded-xl md:peer-data-[variant=inset]:shadow",e),...t}));FAe.displayName="SidebarInset";const zAe=Ae.forwardRef(({className:e,...t},r)=>X.jsx(VB,{ref:r,"data-sidebar":"input",className:Nr("h-8 w-full bg-background shadow-none focus-visible:ring-2 focus-visible:ring-sidebar-ring",e),...t}));zAe.displayName="SidebarInput";const $Ae=Ae.forwardRef(({className:e,...t},r)=>X.jsx("div",{ref:r,"data-sidebar":"header",className:Nr("flex flex-col gap-2 p-2",e),...t}));$Ae.displayName="SidebarHeader";const GAe=Ae.forwardRef(({className:e,...t},r)=>X.jsx("div",{ref:r,"data-sidebar":"footer",className:Nr("flex flex-col gap-2 p-2",e),...t}));GAe.displayName="SidebarFooter";const VAe=Ae.forwardRef(({className:e,...t},r)=>X.jsx(XB,{ref:r,"data-sidebar":"separator",className:Nr("mx-2 w-auto bg-sidebar-border",e),...t}));VAe.displayName="SidebarSeparator";const WAe=Ae.forwardRef(({className:e,...t},r)=>X.jsx("div",{ref:r,"data-sidebar":"content",className:Nr("flex min-h-0 flex-1 flex-col gap-2 overflow-auto group-data-[collapsible=icon]:overflow-hidden",e),...t}));WAe.displayName="SidebarContent";const HAe=Ae.forwardRef(({className:e,...t},r)=>X.jsx("div",{ref:r,"data-sidebar":"group",className:Nr("relative flex w-full min-w-0 flex-col p-2",e),...t}));HAe.displayName="SidebarGroup";const UAe=Ae.forwardRef(({className:e,asChild:t=!1,...r},n)=>{const i=t?Dc:"div";return X.jsx(i,{ref:n,"data-sidebar":"group-label",className:Nr("duration-200 flex h-8 shrink-0 items-center rounded-md px-2 text-xs font-medium text-sidebar-foreground/70 outline-none ring-sidebar-ring transition-[margin,opa] ease-linear focus-visible:ring-2 [&>svg]:size-4 [&>svg]:shrink-0","group-data-[collapsible=icon]:-mt-8 group-data-[collapsible=icon]:opacity-0",e),...r})});UAe.displayName="SidebarGroupLabel";const XAe=Ae.forwardRef(({className:e,asChild:t=!1,...r},n)=>{const i=t?Dc:"button";return X.jsx(i,{ref:n,"data-sidebar":"group-action",className:Nr("absolute right-3 top-3.5 flex aspect-square w-5 items-center justify-center rounded-md p-0 text-sidebar-foreground outline-none ring-sidebar-ring transition-transform hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 [&>svg]:size-4 [&>svg]:shrink-0","after:absolute after:-inset-2 after:md:hidden","group-data-[collapsible=icon]:hidden",e),...r})});XAe.displayName="SidebarGroupAction";const ZAe=Ae.forwardRef(({className:e,...t},r)=>X.jsx("div",{ref:r,"data-sidebar":"group-content",className:Nr("w-full text-sm",e),...t}));ZAe.displayName="SidebarGroupContent";const YAe=Ae.forwardRef(({className:e,...t},r)=>X.jsx("ul",{ref:r,"data-sidebar":"menu",className:Nr("flex w-full min-w-0 flex-col gap-1",e),...t}));YAe.displayName="SidebarMenu";const qAe=Ae.forwardRef(({className:e,...t},r)=>X.jsx("li",{ref:r,"data-sidebar":"menu-item",className:Nr("group/menu-item relative",e),...t}));qAe.displayName="SidebarMenuItem";const JAe=C1("peer/menu-button flex w-full items-center gap-2 overflow-hidden rounded-md p-2 text-left text-sm outline-none ring-sidebar-ring transition-[width,height,padding] hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 active:bg-sidebar-accent active:text-sidebar-accent-foreground disabled:pointer-events-none disabled:opacity-50 group-has-[[data-sidebar=menu-action]]/menu-item:pr-8 aria-disabled:pointer-events-none aria-disabled:opacity-50 data-[active=true]:bg-sidebar-accent data-[active=true]:font-medium data-[active=true]:text-sidebar-accent-foreground data-[state=open]:hover:bg-sidebar-accent data-[state=open]:hover:text-sidebar-accent-foreground group-data-[collapsible=icon]:!size-8 group-data-[collapsible=icon]:!p-2 [&>span:last-child]:truncate [&>svg]:size-4 [&>svg]:shrink-0",{variants:{variant:{default:"hover:bg-sidebar-accent hover:text-sidebar-accent-foreground",outline:"bg-background shadow-[0_0_0_1px_hsl(var(--sidebar-border))] hover:bg-sidebar-accent hover:text-sidebar-accent-foreground hover:shadow-[0_0_0_1px_hsl(var(--sidebar-accent))]"},size:{default:"h-8 text-sm",sm:"h-7 text-xs",lg:"h-12 text-sm group-data-[collapsible=icon]:!p-0"}},defaultVariants:{variant:"default",size:"default"}}),KAe=Ae.forwardRef(({asChild:e=!1,isActive:t=!1,variant:r="default",size:n="default",tooltip:i,className:s,...c},a)=>{const d=e?Dc:"button",{isMobile:p,state:y}=$0(),g=X.jsx(d,{ref:a,"data-sidebar":"menu-button","data-size":n,"data-active":t,className:Nr(JAe({variant:r,size:n}),s),...c});return i?(typeof i=="string"&&(i={children:i}),X.jsxs(TAe,{children:[X.jsx(IAe,{asChild:!0,children:g}),X.jsx(JB,{side:"right",align:"center",hidden:y!=="collapsed"||p,...i})]})):g});KAe.displayName="SidebarMenuButton";const QAe=Ae.forwardRef(({className:e,asChild:t=!1,showOnHover:r=!1,...n},i)=>{const s=t?Dc:"button";return X.jsx(s,{ref:i,"data-sidebar":"menu-action",className:Nr("absolute right-1 top-1.5 flex aspect-square w-5 items-center justify-center rounded-md p-0 text-sidebar-foreground outline-none ring-sidebar-ring transition-transform hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 peer-hover/menu-button:text-sidebar-accent-foreground [&>svg]:size-4 [&>svg]:shrink-0","after:absolute after:-inset-2 after:md:hidden","peer-data-[size=sm]/menu-button:top-1","peer-data-[size=default]/menu-button:top-1.5","peer-data-[size=lg]/menu-button:top-2.5","group-data-[collapsible=icon]:hidden",r&&"group-focus-within/menu-item:opacity-100 group-hover/menu-item:opacity-100 data-[state=open]:opacity-100 peer-data-[active=true]/menu-button:text-sidebar-accent-foreground md:opacity-0",e),...n})});QAe.displayName="SidebarMenuAction";const eTe=Ae.forwardRef(({className:e,...t},r)=>X.jsx("div",{ref:r,"data-sidebar":"menu-badge",className:Nr("absolute right-1 flex h-5 min-w-5 items-center justify-center rounded-md px-1 text-xs font-medium tabular-nums text-sidebar-foreground select-none pointer-events-none","peer-hover/menu-button:text-sidebar-accent-foreground peer-data-[active=true]/menu-button:text-sidebar-accent-foreground","peer-data-[size=sm]/menu-button:top-1","peer-data-[size=default]/menu-button:top-1.5","peer-data-[size=lg]/menu-button:top-2.5","group-data-[collapsible=icon]:hidden",e),...t}));eTe.displayName="SidebarMenuBadge";const tTe=Ae.forwardRef(({className:e,showIcon:t=!1,...r},n)=>{const i=Ae.useMemo(()=>`${Math.floor(Math.random()*40)+50}%`,[]);return X.jsxs("div",{ref:n,"data-sidebar":"menu-skeleton",className:Nr("rounded-md h-8 flex gap-2 px-2 items-center",e),...r,children:[t&&X.jsx(qB,{className:"size-4 rounded-md","data-sidebar":"menu-skeleton-icon"}),X.jsx(qB,{className:"h-4 flex-1 max-w-[--skeleton-width]","data-sidebar":"menu-skeleton-text",style:{"--skeleton-width":i}})]})});tTe.displayName="SidebarMenuSkeleton";const rTe=Ae.forwardRef(({className:e,...t},r)=>X.jsx("ul",{ref:r,"data-sidebar":"menu-sub",className:Nr("mx-3.5 flex min-w-0 translate-x-px flex-col gap-1 border-l border-sidebar-border px-2.5 py-0.5","group-data-[collapsible=icon]:hidden",e),...t}));rTe.displayName="SidebarMenuSub";const nTe=Ae.forwardRef(({...e},t)=>X.jsx("li",{ref:t,...e}));nTe.displayName="SidebarMenuSubItem";const iTe=Ae.forwardRef(({asChild:e=!1,size:t="md",isActive:r,className:n,...i},s)=>{const c=e?Dc:"a";return X.jsx(c,{ref:s,"data-sidebar":"menu-sub-button","data-size":t,"data-active":r,className:Nr("flex h-7 min-w-0 -translate-x-px items-center gap-2 overflow-hidden rounded-md px-2 text-sidebar-foreground outline-none ring-sidebar-ring hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 active:bg-sidebar-accent active:text-sidebar-accent-foreground disabled:pointer-events-none disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:opacity-50 [&>span:last-child]:truncate [&>svg]:size-4 [&>svg]:shrink-0 [&>svg]:text-sidebar-accent-foreground","data-[active=true]:bg-sidebar-accent data-[active=true]:text-sidebar-accent-foreground",t==="sm"&&"text-xs",t==="md"&&"text-sm","group-data-[collapsible=icon]:hidden",n),...i})});iTe.displayName="SidebarMenuSubButton";const aTe=({polygon:e,deleteFeature:t,trigger:r})=>{var M;const[n,i]=U.useState(!1),{mapRef:s}=U.useContext(zi),{addNewPlot:c}=U.useContext($o);U.useState(null);const[a,d]=U.useState([]),[p,y]=U.useState(!1),[g,v]=U.useState(!1),w=Zn(),S=()=>{i(!1),t()},C=I=>{console.log("handlePlotCreation data",I),v(!0),c(I).then(()=>{t(),zc.success(w.formatMessage({id:"app.agviewer_map.plot_success_message",defaultMessage:"Plot created successfully"}))}).catch(E=>{zc.error(w.formatMessage({id:"app.agviewer_map.plot_failed_message",defaultMessage:"Could not create the plot"}))}).finally(()=>{v(!1),S()})};return U.useEffect(()=>{y(!0),ry().then(I=>{d(I)}).finally(()=>{y(!1)})},[]),X.jsx(Fo,{trigger:r||X.jsx(Fr,{color:"primary",children:w.formatMessage({id:"app.agviewer_map.add_new_plot",defaultMessage:"Add New Plot"})}),title:w.formatMessage({id:"app.agviewer_map.add_new_plot",defaultMessage:"Add New Plot"}),headerClassName:"m-4",open:n,setOpen:i,portalContainer:s!=null&&s.current?(M=s==null?void 0:s.current)==null?void 0:M.getMap().getContainer():document.body,children:X.jsx(Oo,{children:X.jsx("div",{className:"h-[400px] overflow-y-auto",children:X.jsx(VO,{initialValues:{options:e},onSubmit:C,className:"p-4",submitButtonText:w.formatMessage({id:"app.agviewer_map.create_plot",defaultMessage:"Create Plot"}),onCancel:()=>i(!1)})})})})},sTe=({feature:e,deleteFeature:t,trigger:r})=>{var y,g;const[n,i]=U.useState(!1);U.useContext(zi);const{addNewMarker:s}=U.useContext(Us),c=Zn(),a={longitude:(y=e==null?void 0:e.geometry)==null?void 0:y.coordinates[0],latitude:(g=e==null?void 0:e.geometry)==null?void 0:g.coordinates[1]};console.log("feature",e);const d=()=>{t(),i(!1)},p=v=>{s(v),t(),d()};return console.log("initialValues",a),X.jsx(Fo,{trigger:r||X.jsxs(Cc,{color:"primary",children:[X.jsx(_W,{})," ",c.formatMessage({id:"app.agviewer_map.add_new_marker",defaultMessage:"Add New Marker"})]}),title:c.formatMessage({id:"app.agviewer_map.add_new_marker",defaultMessage:"Add New Marker"}),headerClassName:"m-4",open:n,setOpen:i,onClose:d,children:X.jsx(Oo,{children:X.jsx(tP,{initialValues:a,onSubmit:p,onCancel:d})})})};function oTe(){const[e,t]=U.useState({}),r=$t(Y=>Y.setViewMode),n=$t(Y=>Y.viewMode),[i,s]=U.useState(),{editingPlot:c,handlePlotUpdate:a}=U.useContext($o),[d,p]=U.useState(c==null?void 0:c.options),[y,g]=U.useState([]),{drawRef:v,showDrawActionPopup:w,setShowDrawActionPopup:S}=U.useContext(zi),C=v.current,{current:M}=yg(),I=pd.constants;I.classes.CONTROL_BASE="maplibregl-ctrl",I.classes.CONTROL_PREFIX="maplibregl-ctrl-",I.classes.CONTROL_GROUP="maplibregl-ctrl-group",U.useCallback(Y=>{console.log("onCreate"),t(ie=>{const re={...ie};for(const V of Y.features)re[V.id]=V;return re})},[]),U.useCallback(Y=>{n in[Ur.EDIT_PLOT,Ur.EDIT_MARKER]&&r(Ur.NORMAL),t(ie=>{const re={...ie};for(const V of Y.features)delete re[V.id];return re})},[]);const E=Y=>{console.log("event features",Y.features),console.log("editing plot",c),d&&a({...c,options:d}).then(()=>{console.log("mode",Y.mode),C.deleteAll(),r(Ur.NORMAL)}).catch(ie=>{console.error("error updating plot",ie)})};U.useEffect(()=>{console.log("editingPlot changed",c)},[c]);const O=Y=>{console.log("mode changed",Y.mode),s(Y.mode)},N=Y=>{console.log("selection changed",Y);const ie=v.current.getSelected();g(ie)},D=U.useCallback(Y=>{console.log("handling draw change",Y),Y.features&&Y.features.length>0?p(Y.features[0]):p(null)},[c,a]),L=()=>{C.deleteAll(),r(Ur.NORMAL)},R=()=>{C.getSelectedIds(),C.trash()};return U.useEffect(()=>{const Y=M.getMap();return Y.on("draw.modechange",O),Y.on("draw.selectionchange",N),()=>{Y.off("draw.modechange",O),Y.off("draw.selectionchange",N)}},[v]),U.useEffect(()=>{if(map&&C)return M.on("draw.update",D),()=>{M.off("draw.update",D)}},[M,C,D]),X.jsx(X.Fragment,{children:X.jsx("div",{className:"absolute top-0 right-0 m-2 ",children:X.jsxs("div",{className:" gap-1 flex flex-col",children:[X.jsx(Fr,{variant:"outline",size:"icon",onClick:L,children:X.jsx(El,{})}),X.jsx(Fr,{variant:"outline",size:"icon",onClick:R,children:X.jsx(vx,{})}),X.jsx(Fr,{variant:"outline",size:"icon",onClick:E,children:X.jsx(yx,{})})]})})})}function lTe(){U.useState({});const e=$t(O=>O.setViewMode);$t(O=>O.viewMode);const[t,r]=U.useState(),[n,i]=U.useState({}),[s,c]=U.useState([]),{drawRef:a,showDrawActionPopup:d,setShowDrawActionPopup:p}=U.useContext(zi),y=a.current,{current:g}=yg();U.useEffect(()=>{y.changeMode("draw_polygon")},[y]);const v=()=>{y&&y.delete(n.id),e(Ur.NORMAL)},w=O=>{console.log("mode changed",O.mode),r(O.mode)},S=O=>{console.log("selection changed",O);const N=a.current.getSelected();c(N)},C=O=>{console.log("delete event",O,y.getMode()),y.getAll().features.length===0&&y.getMode()==="simple_select"&&y.changeMode("draw_polygon")},M=U.useCallback(O=>{console.log("running plot shape change",O.features),console.log("handling draw change",O),O.features&&O.features.length>0&&i(O.features[0])},[]);U.useEffect(()=>{console.log("shape changed",n)},[n]);const I=()=>{y.deleteAll(),e(Ur.NORMAL)},E=()=>{y.getSelectedIds().length>0&&y.trash()};return U.useEffect(()=>{const O=g.getMap();return O.on("draw.modechange",w),O.on("draw.selectionchange",S),()=>{O.off("draw.modechange",w),O.off("draw.selectionchange",S)}},[a]),U.useEffect(()=>{if(map&&y)return g.on("draw.delete",C),g.on("draw.create",M),g.on("draw.update",M),()=>{g.off("draw.delete",C),g.off("draw.create",M),g.off("draw.update",M)}},[g,y,M]),X.jsx(X.Fragment,{children:X.jsx("div",{className:"absolute top-0 right-0 m-2 ",children:X.jsxs("div",{className:" gap-1 flex flex-col",children:[X.jsx(Fr,{variant:"outline",size:"icon",onClick:I,children:X.jsx(El,{})}),X.jsx(Fr,{variant:"outline",size:"icon",onClick:E,children:X.jsx(vx,{})}),X.jsx(aTe,{trigger:X.jsx(Fr,{variant:"outline",size:"icon",children:X.jsx(yx,{})}),polygon:n,deleteFeature:v})]})})})}function cTe(){U.useState({});const e=$t(E=>E.setViewMode);$t(E=>E.viewMode);const[t,r]=U.useState(),[n,i]=U.useState({}),[s,c]=U.useState([]),{drawRef:a,showDrawActionPopup:d,setShowDrawActionPopup:p}=U.useContext(zi),y=a.current,{current:g}=yg();U.useEffect(()=>{y.changeMode("draw_point")},[y]);const v=()=>{y&&y.delete(n.id),e(Ur.NORMAL)},w=E=>{console.log("mode changed",E.mode),r(E.mode)},S=E=>{console.log("selection changed",E);const O=a.current.getSelected();c(O)},C=U.useCallback(E=>{console.log("running plot shape change",E.features),console.log("handling draw change",E),E.features&&E.features.length>0&&i(E.features[0])},[]);U.useEffect(()=>{console.log("shape changed",n)},[n]);const M=()=>{y.deleteAll(),e(Ur.NORMAL)},I=()=>{y.getSelectedIds(),y.trash()};return U.useEffect(()=>{const E=g.getMap();return E.on("draw.modechange",w),E.on("draw.selectionchange",S),()=>{E.off("draw.modechange",w),E.off("draw.selectionchange",S)}},[a]),U.useEffect(()=>{if(map&&y)return g.on("draw.create",C),g.on("draw.update",C),()=>{g.off("draw.create",C),g.off("draw.update",C)}},[g,y,C]),X.jsx(X.Fragment,{children:X.jsx("div",{className:"absolute top-0 right-0 m-2 ",children:X.jsxs("div",{className:" gap-1 flex flex-col",children:[X.jsx(Fr,{variant:"outline",size:"icon",onClick:M,children:X.jsx(El,{})}),X.jsx(Fr,{variant:"outline",size:"icon",onClick:I,children:X.jsx(vx,{})}),X.jsx(sTe,{trigger:X.jsx(Fr,{variant:"outline",size:"icon",children:X.jsx(Fa,{text:"add station",children:X.jsx(yx,{})})}),feature:n,deleteFeature:v})]})})})}const uTe=()=>{var a;const[e,t]=U.useState(!0),{mapRef:r}=U.useContext(zi),n=$t(d=>d.setViewMode),i=Zn(),s=()=>{console.log("closing modal"),n(Ur.NORMAL),t(!1)},c=d=>{SW(d.name,d.marker_set).then(p=>{console.log("farm created successfully"),zc(i.formatMessage({id:"app.agviewer_map.farm_success_message",defaultMessage:"Farm Has been created successfully"}),{description:`name: ${d.name}`})}),s()};return X.jsx(Fo,{title:i.formatMessage({id:"app.agviewer_map.add_new_farm",defaultMessage:"Add New Farm"}),headerClassName:"m-4",open:e,setOpen:t,onChange:s,portalContainer:r!=null&&r.current?(a=r==null?void 0:r.current)==null?void 0:a.getMap().getContainer():document.body,children:X.jsx("div",{className:"h-[400px] overflow-y-auto",children:X.jsx(hTe,{onClose:s,onSubmit:c})})})};function hTe({onClose:e,onSubmit:t}){const r=U.useRef(),n=Zn(),{markers:i,loading:s}=U.useContext(Us),c=U.useMemo(()=>i.map(C=>({value:C.id,label:(C==null?void 0:C.name)||(C==null?void 0:C.title)||(C==null?void 0:C.label)})),[i]),[a,d]=U.useState(!1),[p,y]=U.useState(""),[g,v]=U.useState([]);let w=U.useMemo(()=>Lc(g,c),[g,c]);const S=C=>{C.preventDefault(),t({name:p,marker_set:g})};return X.jsxs("form",{onSubmit:S,className:"p-4 flex flex-col h-full",ref:r,children:[X.jsx(Gi,{label:n.formatMessage({id:"app.agviewer_map.name",defaultMessage:"Name"}),children:X.jsx(jo,{type:"text",name:"name",className:"w-full sm:max-w-[483px] max-w-[227px]",value:p,onChange:C=>y(C.target.value)})}),X.jsx(Gi,{label:n.formatMessage({id:"app.agviewer_map.markers",defaultMessage:"Markers"}),children:X.jsx(eo,{formRef:r,className:"w-full sm:max-w-[483px] max-w-[227px]",name:"marker_set",value:w,onChange:v,options:c,isMulti:!0,isClearable:!0,isLoading:s,isSearchable:!0,closeMenuOnSelect:!1})}),X.jsxs("div",{className:"mt-5 flex gap-2 mt-auto self-end",children:[X.jsx(Fr,{type:"cancel",variant:"outline",onClick:!a&&e,disabled:a,children:n.formatMessage({id:"app.agviewer_map.cancel",defaultMessage:"Cancel"})}),X.jsx(Fr,{type:"submit",color:"primary",children:n.formatMessage({id:"app.agviewer_map.add_farm",defaultMessage:"Add Farm"})})]})]})}function dTe({style:e,requestHeaders:t,configs:r,markers:n}){var L;const{settings:i}=U.useContext(of),{mapRef:s}=U.useContext(zi),c=U.useRef(),a=_6(),[d,p]=U.useState(a),y=$t(R=>R.viewMode),g=$t(R=>R.mapMode),v=$t(R=>R.cursor),w=$t(R=>R.setRequestHeaders),S=$t(R=>R.setConfigs),C=$t(R=>R.dateRange),M=$t(R=>R.setDateRange),I=$t(R=>R.dateRange2),E=$t(R=>R.setDateRange2),O=U.useCallback(R=>p(R.viewState),[]),[N,D]=U.useState(`${(L=FM.find(R=>R.id===i.basemap.id))==null?void 0:L.url}?key=${r==null?void 0:r.VITE_MAPTILER_ACCESS_KEY}`);return U.useEffect(()=>{var R;D(`${(R=FM.find(Y=>Y.id===i.basemap.id))==null?void 0:R.url}?key=${r==null?void 0:r.VITE_MAPTILER_ACCESS_KEY}`)},[i]),U.useEffect(()=>{w(t)},[t]),U.useEffect(()=>{S(r)},[]),U.useEffect(()=>{console.log("fff dateRange is",C),console.log("fff dateRange2 is",I)},[C,I]),a?X.jsx(IE,{providedMarkers:n,children:X.jsx(ZK,{children:X.jsx($O,{children:X.jsx(QB,{children:X.jsx(dre,{children:X.jsxs("div",{style:{width:"100%",height:"80vh"},className:"flex flex-row",children:[X.jsxs(cE,{id:"myMap",ref:s,initialViewState:a,...d,onMove:O,style:{width:"100%",...e},mapStyle:typeof N=="string"?N:N.toJS(),attributionControl:!1,reuseMaps:!0,preserveDrawingBuffer:!0,cursor:v,children:[X.jsx(jB,{mapRef:s,dateRange:C}),g==La.NORMAL&&X.jsx(vre,{mapRef:s}),X.jsx("div",{className:"absolute top-0 left-0",children:g==La.COMPARISION_VIEW&&X.jsx(k_,{mapRef:s,setDateRange:M,compact:!0})}),X.jsxs("div",{className:"absolute top-0 right-0 m-2",style:{zIndex:2},children:[g===La.NORMAL&&X.jsx(GB,{dateRange:C,mapRef:s}),g!==La.NORMAL&&X.jsx($B,{dateRange:C,mapRef:s,showButton:!1})]}),X.jsx(aAe,{}),y==Ur.EDIT_PLOT&&X.jsx(oTe,{}),y==Ur.ADD_PLOT&&X.jsx(lTe,{}),y==Ur.ADD_MARKER&&X.jsx(cTe,{}),y==Ur.ADD_NEW_FARM&&X.jsx(uTe,{}),X.jsx(mEe,{}),X.jsx(Ire,{}),X.jsx(Nre,{}),X.jsx(qR,{mapRef:s,dateRange:C}),X.jsx(sAe,{}),y===Ur.PICKER&&g!==La.COMPARISION_VIEW&&X.jsx(FB,{})]}),g===La.COMPARISION_VIEW&&X.jsxs(cE,{id:"myMap2",ref:c,initialViewState:a,...d,onMove:O,style:{width:"100%",...e},mapStyle:typeof N=="string"?N:N.toJS(),attributionControl:!1,reuseMaps:!0,preserveDrawingBuffer:!0,cursor:v,children:[X.jsx(jB,{mapRef:c,dateRange:I}),X.jsx("div",{className:"absolute top-0 left-0",children:X.jsx(k_,{mapRef:c,setDateRange:E,compact:!0})}),X.jsx("div",{className:"absolute top-0 right-0 m-2",style:{zIndex:2},children:X.jsx(GB,{dateRange:I,mapRef:c})}),X.jsx(qR,{mapRef:c,dateRange:I}),y===Ur.PICKER&&X.jsx(FB,{})]}),X.jsx(fAe,{})]})})})})})}):X.jsx(Ra,{})}var fTe={},ej={};(function(e){function t(I){"@babel/helpers - typeof";return t=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(E){return typeof E}:function(E){return E&&typeof Symbol=="function"&&E.constructor===Symbol&&E!==Symbol.prototype?"symbol":typeof E},t(I)}Object.defineProperty(e,"__esModule",{value:!0}),e.default=void 0;var r=s(U),n=["dispose","reject","resolve"];function i(I){if(typeof WeakMap!="function")return null;var E=new WeakMap,O=new WeakMap;return(i=function(D){return D?O:E})(I)}function s(I,E){if(I&&I.__esModule)return I;if(I===null||t(I)!=="object"&&typeof I!="function")return{default:I};var O=i(E);if(O&&O.has(I))return O.get(I);var N={},D=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var L in I)if(L!=="default"&&Object.prototype.hasOwnProperty.call(I,L)){var R=D?Object.getOwnPropertyDescriptor(I,L):null;R&&(R.get||R.set)?Object.defineProperty(N,L,R):N[L]=I[L]}return N.default=I,O&&O.set(I,N),N}function c(){return c=Object.assign||function(I){for(var E=1;E<arguments.length;E++){var O=arguments[E];for(var N in O)Object.prototype.hasOwnProperty.call(O,N)&&(I[N]=O[N])}return I},c.apply(this,arguments)}function a(I,E){return v(I)||g(I,E)||p(I,E)||d()}function d(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
|
|
1020
1020
|
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function p(I,E){if(I){if(typeof I=="string")return y(I,E);var O=Object.prototype.toString.call(I).slice(8,-1);if(O==="Object"&&I.constructor&&(O=I.constructor.name),O==="Map"||O==="Set")return Array.from(I);if(O==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(O))return y(I,E)}}function y(I,E){(E==null||E>I.length)&&(E=I.length);for(var O=0,N=new Array(E);O<E;O++)N[O]=I[O];return N}function g(I,E){var O=I==null?null:typeof Symbol<"u"&&I[Symbol.iterator]||I["@@iterator"];if(O!=null){var N=[],D=!0,L=!1,R,Y;try{for(O=O.call(I);!(D=(R=O.next()).done)&&(N.push(R.value),!(E&&N.length===E));D=!0);}catch(ie){L=!0,Y=ie}finally{try{!D&&O.return!=null&&O.return()}finally{if(L)throw Y}}return N}}function v(I){if(Array.isArray(I))return I}function w(I,E){if(I==null)return{};var O=S(I,E),N,D;if(Object.getOwnPropertySymbols){var L=Object.getOwnPropertySymbols(I);for(D=0;D<L.length;D++)N=L[D],!(E.indexOf(N)>=0)&&Object.prototype.propertyIsEnumerable.call(I,N)&&(O[N]=I[N])}return O}function S(I,E){if(I==null)return{};var O={},N=Object.keys(I),D,L;for(L=0;L<N.length;L++)D=N[L],!(E.indexOf(D)>=0)&&(O[D]=I[D]);return O}var C=function(E){return function(O){var N=O.dispose,D=O.reject,L=O.resolve,R=w(O,n),Y=(0,r.useState)(!0),ie=a(Y,2),re=ie[0],V=ie[1],Z=function(){V(!1),N()},W=function(q){V(!1),D(q)},B=function(q){V(!1),L(q)};return r.default.createElement(E,c({cancel:W,dismiss:Z,proceed:B,show:re},R))}},M=C;e.default=M})(ej);var tj={},G0={},cm={},um=Da;if(process.env.NODE_ENV==="production")cm.createRoot=um.createRoot,cm.hydrateRoot=um.hydrateRoot;else{var V0=um.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;cm.createRoot=function(e,t){V0.usingClientEntryPoint=!0;try{return um.createRoot(e,t)}finally{V0.usingClientEntryPoint=!1}},cm.hydrateRoot=function(e,t,r){V0.usingClientEntryPoint=!0;try{return um.hydrateRoot(e,t,r)}finally{V0.usingClientEntryPoint=!1}}}Object.defineProperty(G0,"__esModule",{value:!0}),G0.createDomTreeMounter=yTe;var pTe=gTe(U),mTe=cm;function gTe(e){return e&&e.__esModule?e:{default:e}}function yTe(e){var t={},r={};function n(s,c,a){var d=Math.floor(Math.random()*1073741824).toString(16),p=(a||e||document.body).appendChild(document.createElement("div"));t[d]=p;var y=(0,mTe.createRoot)(p);return y.render(pTe.default.createElement(s,c)),r.mounted&&r.mounted(),d}function i(s){var c=t[s];delete t[s],c&&c.parentNode&&c.parentNode.removeChild(c)}return{mount:n,unmount:i,options:{}}}(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.default=e.createConfirmationCreater=void 0;var t=G0;function r(a,d){var p=Object.keys(a);if(Object.getOwnPropertySymbols){var y=Object.getOwnPropertySymbols(a);d&&(y=y.filter(function(g){return Object.getOwnPropertyDescriptor(a,g).enumerable})),p.push.apply(p,y)}return p}function n(a){for(var d=1;d<arguments.length;d++){var p=arguments[d]!=null?arguments[d]:{};d%2?r(Object(p),!0).forEach(function(y){i(a,y,p[y])}):Object.getOwnPropertyDescriptors?Object.defineProperties(a,Object.getOwnPropertyDescriptors(p)):r(Object(p)).forEach(function(y){Object.defineProperty(a,y,Object.getOwnPropertyDescriptor(p,y))})}return a}function i(a,d,p){return d in a?Object.defineProperty(a,d,{value:p,enumerable:!0,configurable:!0,writable:!0}):a[d]=p,a}var s=function(d){return function(p){var y=arguments.length>1&&arguments[1]!==void 0?arguments[1]:1e3,g=arguments.length>2?arguments[2]:void 0;return function(v){var w,S=new Promise(function(M,I){try{w=d.mount(p,n({reject:I,resolve:M,dispose:C},v),g)}catch(E){throw console.error(E),E}});function C(){setTimeout(function(){d.unmount(w)},y)}return S.then(function(M){return C(),M},function(M){return C(),Promise.reject(M)})}}};e.createConfirmationCreater=s;var c=s((0,t.createDomTreeMounter)());e.default=c})(tj);var W0={};function cC(e){"@babel/helpers - typeof";return cC=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(t){return typeof t}:function(t){return t&&typeof Symbol=="function"&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},cC(e)}Object.defineProperty(W0,"__esModule",{value:!0}),W0.createMountPoint=TTe,W0.createReactTreeMounter=ATe;var hm=bTe(U),vTe=Da;function rj(e){if(typeof WeakMap!="function")return null;var t=new WeakMap,r=new WeakMap;return(rj=function(i){return i?r:t})(e)}function bTe(e,t){if(e&&e.__esModule)return e;if(e===null||cC(e)!=="object"&&typeof e!="function")return{default:e};var r=rj(t);if(r&&r.has(e))return r.get(e);var n={},i=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var s in e)if(s!=="default"&&Object.prototype.hasOwnProperty.call(e,s)){var c=i?Object.getOwnPropertyDescriptor(e,s):null;c&&(c.get||c.set)?Object.defineProperty(n,s,c):n[s]=e[s]}return n.default=e,r&&r.set(e,n),n}function uC(){return uC=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},uC.apply(this,arguments)}function nj(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(i){return Object.getOwnPropertyDescriptor(e,i).enumerable})),r.push.apply(r,n)}return r}function xTe(e){for(var t=1;t<arguments.length;t++){var r=arguments[t]!=null?arguments[t]:{};t%2?nj(Object(r),!0).forEach(function(n){_Te(e,n,r[n])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):nj(Object(r)).forEach(function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(r,n))})}return e}function _Te(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function wTe(e,t){return ETe(e)||MTe(e,t)||CTe(e,t)||STe()}function STe(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
|
|
1021
1021
|
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function CTe(e,t){if(e){if(typeof e=="string")return ij(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);if(r==="Object"&&e.constructor&&(r=e.constructor.name),r==="Map"||r==="Set")return Array.from(e);if(r==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return ij(e,t)}}function ij(e,t){(t==null||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function MTe(e,t){var r=e==null?null:typeof Symbol<"u"&&e[Symbol.iterator]||e["@@iterator"];if(r!=null){var n=[],i=!0,s=!1,c,a;try{for(r=r.call(e);!(i=(c=r.next()).done)&&(n.push(c.value),!(t&&n.length===t));i=!0);}catch(d){s=!0,a=d}finally{try{!i&&r.return!=null&&r.return()}finally{if(s)throw a}}return n}}function ETe(e){if(Array.isArray(e))return e}function ATe(e){var t={},r={};function n(c,a){var d=Math.floor(Math.random()*1073741824).toString(16);return t[d]={Component:c,props:a},r.mounted&&r.mounted(t),d}function i(c){delete t[c],r.mounted&&r.mounted(t)}function s(c){r.mounted=c}return{mount:n,unmount:i,options:{setMountedCallback:s,mountNode:e}}}function TTe(e){return function(){var t=(0,hm.useState)({}),r=wTe(t,2),n=r[0],i=r[1];(0,hm.useEffect)(function(){return e.options.setMountedCallback(function(c){i(xTe({},c))})},[]);var s=hm.default.createElement(hm.default.Fragment,null,Object.keys(n).map(function(c){var a=n[c],d=a.Component,p=a.props;return hm.default.createElement(d,uC({key:c},p))}));return e.options.mountNode&&(s=(0,vTe.createPortal)(s,e.options.mountNode)),s}}(function(e){function t(p){"@babel/helpers - typeof";return t=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(y){return typeof y}:function(y){return y&&typeof Symbol=="function"&&y.constructor===Symbol&&y!==Symbol.prototype?"symbol":typeof y},t(p)}Object.defineProperty(e,"__esModule",{value:!0}),Object.defineProperty(e,"confirmable",{enumerable:!0,get:function(){return r.default}}),Object.defineProperty(e,"createConfirmation",{enumerable:!0,get:function(){return n.default}}),Object.defineProperty(e,"createConfirmationCreater",{enumerable:!0,get:function(){return n.createConfirmationCreater}}),Object.defineProperty(e,"createDomTreeMounter",{enumerable:!0,get:function(){return i.createDomTreeMounter}}),Object.defineProperty(e,"createMountPoint",{enumerable:!0,get:function(){return s.createMountPoint}}),Object.defineProperty(e,"createReactTreeMounter",{enumerable:!0,get:function(){return s.createReactTreeMounter}});var r=d(ej),n=a(tj),i=G0,s=W0;function c(p){if(typeof WeakMap!="function")return null;var y=new WeakMap,g=new WeakMap;return(c=function(w){return w?g:y})(p)}function a(p,y){if(p.__esModule)return p;if(p===null||t(p)!=="object"&&typeof p!="function")return{default:p};var g=c(y);if(g&&g.has(p))return g.get(p);var v={},w=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var S in p)if(S!=="default"&&Object.prototype.hasOwnProperty.call(p,S)){var C=w?Object.getOwnPropertyDescriptor(p,S):null;C&&(C.get||C.set)?Object.defineProperty(v,S,C):v[S]=p[S]}return v.default=p,g&&g.set(p,v),v}function d(p){return p&&p.__esModule?p:{default:p}}})(fTe);const ITe=U.forwardRef(({onClose:e,...t},r)=>X.jsx(Fr,{ref:r,variant:"outline",size:"icon",onClick:e,...t,children:X.jsx(El,{className:"w-5 h-5 action-icon"})})),aj=()=>{const{prompt:e="",isOpen:t=!0,proceed:r,cancel:n}=Cf(),i=()=>{n()};return X.jsx(s_,{open:t,onOpenChange:s=>{s||i()},children:X.jsxs(o_,{children:[X.jsx(my,{className:"fixed inset-0 bg-black opacity-30 z-20"}),X.jsxs(gy,{className:"fixed top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2 bg-white dark:bg-gray-900 p-6 rounded shadow-lg z-20",children:[X.jsx(yy,{className:"text-lg font-bold dark:text-gray-200",children:"Warning"}),X.jsx(vy,{className:"mt-2 text-sm text-gray-600 dark:text-gray-200",children:e}),X.jsxs("div",{className:"mt-4 flex justify-end space-x-2",children:[X.jsx(Fr,{variant:"outline",onClick:n,children:"Cancel"}),X.jsx(Fr,{variant:"destructive",onClick:()=>r(!0),children:"delete"})]}),X.jsx(l_,{asChild:!0,children:X.jsx(ITe,{className:"absolute top-2 right-2"})})]})]})})};aj.propTypes={show:rr.bool,proceed:rr.func,confirmation:rr.string,options:rr.object};const PTe=U.createContext();function OTe({children:e,defaultTheme:t="system",storageKey:r="vite-ui-theme",...n}){const[i,s]=U.useState(()=>localStorage.getItem(r)||t);U.useEffect(()=>{const a=document.documentElement;a.classList.remove("light","dark"),i==="system"&&a&&window.matchMedia("(prefers-color-scheme: dark)").matches,a.classList.add("light")},[i]),U.useEffect(()=>{const a=window.matchMedia("(prefers-color-scheme: dark)"),d=()=>s(a.matches?"dark":"light");return d(),a.addEventListener("change",d),()=>a.removeEventListener("change",d)},[]);const c={theme:"light",setTheme:a=>{localStorage.setItem(r,a),s(a)}};return X.jsx(PTe.Provider,{value:c,...n,children:e})}var kTe=(e,t,r,n,i,s,c,a)=>{let d=document.documentElement,p=["light","dark"];function y(w){(Array.isArray(e)?e:[e]).forEach(S=>{let C=S==="class",M=C&&s?i.map(I=>s[I]||I):i;C?(d.classList.remove(...M),d.classList.add(w)):d.setAttribute(S,w)}),g(w)}function g(w){a&&p.includes(w)&&(d.style.colorScheme=w)}function v(){return window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}if(n)y(n);else try{let w=localStorage.getItem(t)||r,S=c&&w==="system"?v():w;y(S)}catch{}},DTe=Ae.createContext(void 0),LTe={setTheme:e=>{},themes:[]},NTe=()=>{var e;return(e=Ae.useContext(DTe))!=null?e:LTe};Ae.memo(({forcedTheme:e,storageKey:t,attribute:r,enableSystem:n,enableColorScheme:i,defaultTheme:s,value:c,themes:a,nonce:d,scriptProps:p})=>{let y=JSON.stringify([r,t,s,e,a,c,n,i]).slice(1,-1);return Ae.createElement("script",{...p,suppressHydrationWarning:!0,nonce:typeof window>"u"?d:"",dangerouslySetInnerHTML:{__html:`(${kTe.toString()})(${y})`}})});const RTe=({...e})=>{const{theme:t="system"}=NTe();return X.jsx(GK,{theme:t,className:"toaster group",toastOptions:{classNames:{toast:"group toast group-[.toaster]:bg-background group-[.toaster]:text-foreground group-[.toaster]:border-border group-[.toaster]:shadow-lg",description:"group-[.toast]:text-muted-foreground",actionButton:"group-[.toast]:bg-primary group-[.toast]:text-primary-foreground",cancelButton:"group-[.toast]:bg-muted group-[.toast]:text-muted-foreground"}},...e})};function BTe({style:e,requestHeaders:t,configs:r,markers:n}){return X.jsx(QH,{children:X.jsx(OTe,{defaultTheme:"light",children:X.jsx(CA,{delayDuration:200,children:X.jsx(w6,{children:X.jsx(uX,{children:X.jsx(QM,{configs:r,children:X.jsxs(w1,{children:[X.jsx(dTe,{style:e,requestHeaders:t,configs:r,markers:n}),X.jsx(RTe,{richColors:!0}),X.jsx(aj,{})]})})})})})})})}ya.AgvMap=BTe,Object.defineProperty(ya,Symbol.toStringTag,{value:"Module"})});
|