agvmap-react 0.1.4 → 0.1.5

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.
@@ -60746,14 +60746,17 @@ function cMe() {
60746
60746
  type: "image",
60747
60747
  url: te,
60748
60748
  coordinates: we
60749
- }), q.addLayer({
60750
- id: $e,
60751
- type: "raster",
60752
- source: Me,
60753
- paint: {
60754
- "raster-opacity": 1
60755
- }
60756
- });
60749
+ }), q.addLayer(
60750
+ {
60751
+ id: $e,
60752
+ type: "raster",
60753
+ source: Me,
60754
+ paint: {
60755
+ "raster-opacity": 1
60756
+ }
60757
+ },
60758
+ "plots-line-layer"
60759
+ );
60757
60760
  },
60758
60761
  [c]
60759
60762
  ), B = bn(
@@ -60783,8 +60786,8 @@ function cMe() {
60783
60786
  });
60784
60787
  if (!te) throw new Error("plot is not defined");
60785
60788
  console.log("mapp", q), Me && (console.log(), R(Me, te, { map: q }));
60786
- } catch {
60787
- console.log("error in loading ndvi layer");
60789
+ } catch (Me) {
60790
+ console.log("error in loading ndvi layer", Me);
60788
60791
  } finally {
60789
60792
  L(te.properties.id);
60790
60793
  }
@@ -63869,7 +63872,7 @@ const aAe = () => {
63869
63872
  });
63870
63873
  s(b);
63871
63874
  }, [r, e]), cn(() => {
63872
- p && (p != null && p.loaded()) && p.getLayer("plots-line-layer") ? a("plots-line-layer") : a(null);
63875
+ p && (p != null && p.loaded()) && p.getLayer("plots-line-layer") ? (console.log("order setting before id to plots-line-layer"), a("plots-line-layer")) : (console.log("order setting before id to plots-line-layer"), a(null));
63873
63876
  }, [p]);
63874
63877
  const g = bn(
63875
63878
  (b) => {
@@ -985,6 +985,6 @@ function evaluatePixel(samples) {
985
985
  // Return color values with full opacity
986
986
  return imgVals.concat([1]); // RGBA: fully opaque
987
987
  }
988
- }`,H2={};async function B2e(e,{weeksBefore:t=0,accessToken:n,dateRange:r}){if(!n)return console.error("No access token provided"),null;r&&(r.start instanceof Date&&(r.start.setHours(0,0,0,0),r.start=r.start.toISOString()),r.end instanceof Date&&(r.end.setHours(23,59,59),r.end=r.end.toISOString())),r||(r={start:new Date(new Date().setDate(new Date().getDate()-t*7-14)).toISOString(),end:new Date(new Date().setDate(new Date().getDate()-t*7)).toISOString()});const i=`${e.properties.id}-${r.start}`;if(console.log("crop cacheKey",i),H2[i])return console.log("NDVI data found in cache"),H2[i];if(console.log("access Token",n),!BZ(sf(e)))throw new Error("Invalid BBOX");const c="https://services.sentinel-hub.com/api/v1/process",a={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:r.start,to:r.end}}}]},output:{width:512,height:512,responses:[{identifier:"default",format:{type:"image/png"}}]},evalscript:j2e};try{const d=await fetch(c,{method:"POST",headers:{Authorization:`Bearer ${n}`,"Content-Type":"application/json"},body:JSON.stringify(a)});if(!d.ok)throw new Error("Failed to fetch NDVI data");const p=await d.blob();if(!p)return null;const y=URL.createObjectURL(p);return H2[i]=y,y}catch(d){return console.error("Error fetching NDVI data:",d),null}}async function F2e(e,t){console.log("downloading cropped et",t),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 n=`${t.start}/${t.end}`,r=sf(e);if(!r)throw new Error("Invalid BBOX");const i=r.join(","),s="https://d27s6pvwcjpmsu.cloudfront.net/geoserver/ne/wms?"+new URLSearchParams({service:"WMS",version:"1.1.0",request:"GetMap",layers:"ne:et_data",styles:"",bbox:i,width:512,height:512,srs:"EPSG:4326",format:"image/png",transparent:"true",TIME:n});try{const c=await fetch(s);if(!c.ok)throw new Error("Failed to fetch cropped NDVI from GeoServer");const a=await c.blob();return a?URL.createObjectURL(a):null}catch(c){return console.error("Error fetching cropped NDVI:",c),null}}async function z2e(e,t){return new Promise(n=>{const r=new Image;r.onload=function(){const i=document.createElement("canvas"),s=i.getContext("2d");i.width=r.width,i.height=r.height,s.drawImage(r,0,0,r.width,r.height);const c=t.geometry.coordinates[0].map(([a,d])=>$2e(a,d,sf(t),r.width,r.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(),n(i.toDataURL("image/png"))},r.src=e})}function $2e(e,t,n,r,i){const[s,c,a,d]=n,p=(e-s)/(a-s)*r,y=i-(t-c)/(d-c)*i;return[p,y]}async function V2e(e,{rasterLayer:t,dateRange:n,accessToken:r,map:i}){if(console.log("getCroppedRaster rasterLayer",t),t==="ET"||(t==null?void 0:t.value)==="ET"){const s=await F2e(e,n);if(!s)return null;const c=await z2e(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 B2e(e,{accessToken:r,dateRange:n})}function G2e(){var X;const{plots:e,showPlots:t,clickedPlot:n,setClickedPlot:r,weeksBefore:i,showNdviLayer:s}=H.useContext(Po),c=rn(ne=>ne.showCroppedImages),a=rn(ne=>ne.rasterLayer),{isVisible:d,setIsVisible:p,dateRange:y}=H.useContext(Mf),{settings:g}=H.useContext(Gd),b=rn(ne=>ne.setCursor),w=rn(ne=>ne.resetCursor),{drawRef:S,mapRef:C}=H.useContext(ii),M=H.useContext(dy),O=(X=C==null?void 0:C.current)==null?void 0:X.getMap(),T=rn(ne=>ne.viewMode),D=rn(ne=>ne.addLoadingNDVIImage),N=rn(ne=>ne.removeLoadingNDVIImage),k=rn(ne=>ne.isNDVIImageLoading);rn(ne=>ne.setShowCroppedImages);const L=H.useCallback((ne,ae,{map:J})=>{if(console.log("crop adding image to map",ne,ae,J),!J)throw new Error("map is not defined");if(!c||(console.log("plotss",ae),!ae||!ae.geometry||ae.geometry.type!=="Polygon"))return null;const[pe,xe,se,ge]=sf(ae.geometry),Se=[[pe,ge],[se,ge],[se,xe],[pe,xe]],Ae=`croppedImageSource-${ae.properties.id}`,$e=`croppedImageLayer-${ae.properties.id}`;J.getLayer($e)&&J.removeLayer($e),J.getSource(Ae)&&J.removeSource(Ae),J.addSource(Ae,{type:"image",url:ne,coordinates:Se}),J.addLayer({id:$e,type:"raster",source:Ae,paint:{"raster-opacity":1}})},[c]),B=H.useCallback(async(ne,{accessToken:ae,map:J,timeTravel:pe,dateRange:xe,isVisible:se,showCroppedImages:ge})=>{if(console.log("handleCroppedImageDownload started"),console.log("crop download plot",ne),!J)throw new Error("map is not defined");const Se=`croppedImageLayer-${ne.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(k(ne.properties.id))return;D(ne.properties.id);const Ae=await V2e(ne,{rasterLayer:a,dateRange:xe,accessToken:ae});if(!ne)throw new Error("plot is not defined");console.log("mapp",J),Ae&&(console.log(),L(Ae,ne,{map:J}))}catch{console.log("error in loading ndvi layer")}finally{N(ne.properties.id)}},[a,k,D,L,N]),q={id:"plots-line-layer",type:"line",paint:{"line-color":"#e31717","line-width":2}},re={id:"plots-layer",type:"fill",paint:{"fill-color":"#e31717","fill-opacity":0}},ie=H.useCallback(()=>{var J;const ne=(J=S==null?void 0:S.current)==null?void 0:J.getAll();return((ne==null?void 0:ne.features)||[]).length>0},[S]),$=H.useCallback(ne=>{if(ie()){console.log("no popup info"),r(null);return}const ae=O.queryRenderedFeatures(ne.point,{layers:["plots-layer"]});if(ae.length>0){const J=ae[0];console.log("clickedPlot",J),r({lngLat:ne.lngLat,plot:J})}else r(null)},[ie,O,r]),Y=H.useCallback(()=>{b("pointer")},[b,O]),G=H.useCallback(()=>{w()},[b,O]),j=H.useCallback((ne,ae)=>{const[J,pe,xe,se]=ne,[[ge,Se],[Ae,$e]]=ae.toArray();return!(J>Ae||xe<ge||pe>$e||se<Se)},[]),R=H.useCallback(({timeTravel:ne=!1})=>{if(console.log("handleViewportChange start"),!O||T!=="NORMAL"||O.getZoom()<10)return;const J=O.getBounds();e.forEach(pe=>{if(KI(pe.options))return;const xe=sf(pe.options);j(xe,J)&&B(pe.options,{dateRange:y,accessToken:M,map:O,timeTravel:ne,isVisible:d,showCroppedImages:c})}),console.log("handleViewportChange end")},[O,e,M,y,j,T,d,c,a]),Z=H.useMemo(()=>cy(R,500),[R]);return H.useEffect(()=>{console.log("dateRnage changed, crop"),R({timeTravel:!0})},[y,d,c,e,a,g]),H.useEffect(()=>(O&&t&&T!=="PICKER"&&O.on("click","plots-layer",$),()=>{O&&O.off("click","plots-layer",$)}),[$,T,t,O]),H.useEffect(()=>{if(console.log("running useEffect inside plots"),!(!O||T!=="NORMAL"||!t||!c))return console.log("adding viewport change event to map"),O.on("moveend",Z),O.on("zoomend",Z),()=>{console.log("removing viewport change event from map"),Z.cancel(),O.off("moveend",Z),O.off("zoomend",Z)}},[O,t,T,Z,c]),H.useEffect(()=>(O&&T!=="PICKER"&&(O.on("mouseenter","plots-layer",Y),O.on("mouseleave","plots-layer",G)),()=>{O&&T!=="PICKER"&&(O.off("mouseenter","plots-layer",Y),O.off("mouseleave","plots-layer",G))}),[O,Y,G,T]),t?K.jsxs(K.Fragment,{children:[K.jsxs(pM,{id:"plots",type:"geojson",data:{type:"FeatureCollection",features:e.map(ne=>ne==null?void 0:ne.options)},children:[K.jsx(Hb,{...q},"12kkd"),K.jsx(Hb,{...re},"12kmsn")]}),n&&T==Hn.NORMAL&&K.jsx(R2e,{popupInfo:n,onClose:()=>r(null)})]}):null}const X2=function(e,t){const n={drag:[],click:[],mousemove:[],mousedown:[],mouseup:[],mouseout:[],keydown:[],keyup:[],touchstart:[],touchmove:[],touchend:[],tap:[]},r={on(s,c,a){if(n[s]===void 0)throw new Error(`Invalid event type: ${s}`);n[s].push({selector:c,fn:a})},render(s){t.store.featureChanged(s)}},i=function(s,c){const a=n[s];let d=a.length;for(;d--;){const p=a[d];if(p.selector(c)){p.fn.call(r,c)||t.store.render(),t.ui.updateMapClasses();break}}};return e.start.call(r),{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 Z2={},a0={};a0.RADIUS=6378137,a0.FLATTENING=1/298.257223563,a0.POLAR_RADIUS=63567523142e-4;var uN=a0;Z2.geometry=hN,Z2.ring=Y2;function hN(e){var t=0,n;switch(e.type){case"Polygon":return dN(e.coordinates);case"MultiPolygon":for(n=0;n<e.coordinates.length;n++)t+=dN(e.coordinates[n]);return t;case"Point":case"MultiPoint":case"LineString":case"MultiLineString":return 0;case"GeometryCollection":for(n=0;n<e.geometries.length;n++)t+=hN(e.geometries[n]);return t}}function dN(e){var t=0;if(e&&e.length>0){t+=Math.abs(Y2(e[0]));for(var n=1;n<e.length;n++)t-=Math.abs(Y2(e[n]))}return t}function Y2(e){var t,n,r,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],n=e[s],r=e[c],d+=(q2(r[0])-q2(t[0]))*Math.sin(q2(n[1]));d=d*uN.RADIUS*uN.RADIUS/2}return d}function q2(e){return e*Math.PI/180}const xa={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"},ss={HOT:"mapbox-gl-draw-hot",COLD:"mapbox-gl-draw-cold"},Fr={ADD:"add",MOVE:"move",DRAG:"drag",POINTER:"pointer",NONE:"none"},_a={POLYGON:"polygon",LINE:"line_string",POINT:"point"},yn={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"},Gn={DRAW_LINE_STRING:"draw_line_string",DRAW_POLYGON:"draw_polygon",DRAW_POINT:"draw_point",SIMPLE_SELECT:"simple_select",DIRECT_SELECT:"direct_select"},ta={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"},Fp={MOVE:"move",CHANGE_PROPERTIES:"change_properties",CHANGE_COORDINATES:"change_coordinates"},Bi={FEATURE:"feature",MIDPOINT:"midpoint",VERTEX:"vertex"},fi={ACTIVE:"true",INACTIVE:"false"},fN=["scrollZoom","boxZoom","dragRotate","dragPan","keyboard","doubleClickZoom","touchZoomRotate"],W2e=-90,J2=-85,U2e=90,K2=85,pN=Object.freeze(Object.defineProperty({__proto__:null,LAT_MAX:U2e,LAT_MIN:W2e,LAT_RENDERED_MAX:K2,LAT_RENDERED_MIN:J2,LNG_MAX:270,LNG_MIN:-270,activeStates:fi,classes:xa,cursors:Fr,events:ta,geojsonTypes:yn,interactions:fN,meta:Bi,modes:Gn,sources:ss,types:_a,updateActions:Fp},Symbol.toStringTag,{value:"Module"})),mN={Point:0,LineString:1,MultiLineString:1,Polygon:2};function H2e(e,t){const n=mN[e.geometry.type]-mN[t.geometry.type];return n===0&&e.geometry.type===yn.POLYGON?e.area-t.area:n}function gN(e){return e.map(t=>(t.geometry.type===yn.POLYGON&&(t.area=Z2.geometry({type:yn.FEATURE,property:{},geometry:t.geometry})),t)).sort(H2e).map(t=>(delete t.area,t))}function yN(e,t=0){return[[e.point.x-t,e.point.y-t],[e.point.x+t,e.point.y+t]]}function os(e){if(this._items={},this._nums={},this._length=e?e.length:0,!!e)for(let t=0,n=e.length;t<n;t++)this.add(e[t]),e[t]!==void 0&&(typeof e[t]=="string"?this._items[e[t]]=t:this._nums[e[t]]=t)}os.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)},os.prototype.delete=function(e){return this.has(e)===!1?this:(this._length--,delete this._items[e],delete this._nums[e],this)},os.prototype.has=function(e){return typeof e!="string"&&typeof e!="number"?!1:this._items[e]!==void 0||this._nums[e]!==void 0},os.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,n)=>t.v-n.v).map(t=>t.k)},os.prototype.clear=function(){return this._length=0,this._items={},this._nums={},this};const X2e=[Bi.FEATURE,Bi.MIDPOINT,Bi.VERTEX],Yh={click:Z2e,touch:Y2e};function Z2e(e,t,n){return vN(e,t,n,n.options.clickBuffer)}function Y2e(e,t,n){return vN(e,t,n,n.options.touchBuffer)}function vN(e,t,n,r){if(n.map===null)return[];const i=e?yN(e,r):t,s={};n.options.styles&&(s.layers=n.options.styles.map(p=>p.id).filter(p=>n.map.getLayer(p)!=null));const c=n.map.queryRenderedFeatures(i,s).filter(p=>X2e.indexOf(p.properties.meta)!==-1),a=new os,d=[];return c.forEach(p=>{const y=p.properties.id;a.has(y)||(a.add(y),d.push(p))}),gN(d)}function s0(e,t){const n=Yh.click(e,null,t),r={mouse:Fr.NONE};return n[0]&&(r.mouse=n[0].properties.active===fi.ACTIVE?Fr.MOVE:Fr.POINTER,r.feature=n[0].properties.meta),t.events.currentModeName().indexOf("draw")!==-1&&(r.mouse=Fr.ADD),t.ui.queueMapClasses(r),t.ui.updateMapClasses(),n[0]}function Q2(e,t){const n=e.x-t.x,r=e.y-t.y;return Math.sqrt(n*n+r*r)}const q2e=4,J2e=12,K2e=500;function eS(e,t,n={}){const r=n.fineTolerance!=null?n.fineTolerance:q2e,i=n.grossTolerance!=null?n.grossTolerance:J2e,s=n.interval!=null?n.interval:K2e;e.point=e.point||t.point,e.time=e.time||t.time;const c=Q2(e.point,t.point);return c<r||c<i&&t.time-e.time<s}const Q2e=25,eSe=250;function tS(e,t,n={}){const r=n.tolerance!=null?n.tolerance:Q2e,i=n.interval!=null?n.interval:eSe;return e.point=e.point||t.point,e.time=e.time||t.time,Q2(e.point,t.point)<r&&t.time-e.time<i}const tSe=((e,t=21)=>(n=t)=>{let r="",i=n|0;for(;i--;)r+=e[Math.random()*e.length|0];return r})("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",32);function nS(){return tSe()}const na=function(e,t){this.ctx=e,this.properties=t.properties||{},this.coordinates=t.geometry.coordinates,this.id=t.id||nS(),this.type=t.geometry.type};na.prototype.changed=function(){this.ctx.store.featureChanged(this.id)},na.prototype.incomingCoords=function(e){this.setCoordinates(e)},na.prototype.setCoordinates=function(e){this.coordinates=e,this.changed()},na.prototype.getCoordinates=function(){return JSON.parse(JSON.stringify(this.coordinates))},na.prototype.setProperty=function(e,t){this.properties[e]=t},na.prototype.toGeoJSON=function(){return JSON.parse(JSON.stringify({id:this.id,type:yn.FEATURE,properties:this.properties,geometry:{coordinates:this.getCoordinates(),type:this.type}}))},na.prototype.internal=function(e){const t={id:this.id,meta:Bi.FEATURE,"meta:type":this.type,active:fi.INACTIVE,mode:e};if(this.ctx.options.userProperties)for(const n in this.properties)t[`user_${n}`]=this.properties[n];return{type:yn.FEATURE,properties:t,geometry:{coordinates:this.getCoordinates(),type:this.type}}};const Fl=function(e,t){na.call(this,e,t)};Fl.prototype=Object.create(na.prototype),Fl.prototype.isValid=function(){return typeof this.coordinates[0]=="number"&&typeof this.coordinates[1]=="number"},Fl.prototype.updateCoordinate=function(e,t,n){arguments.length===3?this.coordinates=[t,n]:this.coordinates=[e,t],this.changed()},Fl.prototype.getCoordinate=function(){return this.getCoordinates()};const io=function(e,t){na.call(this,e,t)};io.prototype=Object.create(na.prototype),io.prototype.isValid=function(){return this.coordinates.length>1},io.prototype.addCoordinate=function(e,t,n){this.changed();const r=parseInt(e,10);this.coordinates.splice(r,0,[t,n])},io.prototype.getCoordinate=function(e){const t=parseInt(e,10);return JSON.parse(JSON.stringify(this.coordinates[t]))},io.prototype.removeCoordinate=function(e){this.changed(),this.coordinates.splice(parseInt(e,10),1)},io.prototype.updateCoordinate=function(e,t,n){const r=parseInt(e,10);this.coordinates[r]=[t,n],this.changed()};const Da=function(e,t){na.call(this,e,t),this.coordinates=this.coordinates.map(n=>n.slice(0,-1))};Da.prototype=Object.create(na.prototype),Da.prototype.isValid=function(){return this.coordinates.length===0?!1:this.coordinates.every(e=>e.length>2)},Da.prototype.incomingCoords=function(e){this.coordinates=e.map(t=>t.slice(0,-1)),this.changed()},Da.prototype.setCoordinates=function(e){this.coordinates=e,this.changed()},Da.prototype.addCoordinate=function(e,t,n){this.changed();const r=e.split(".").map(s=>parseInt(s,10));this.coordinates[r[0]].splice(r[1],0,[t,n])},Da.prototype.removeCoordinate=function(e){this.changed();const t=e.split(".").map(r=>parseInt(r,10)),n=this.coordinates[t[0]];n&&(n.splice(t[1],1),n.length<3&&this.coordinates.splice(t[0],1))},Da.prototype.getCoordinate=function(e){const t=e.split(".").map(r=>parseInt(r,10)),n=this.coordinates[t[0]];return JSON.parse(JSON.stringify(n[t[1]]))},Da.prototype.getCoordinates=function(){return this.coordinates.map(e=>e.concat([e[0]]))},Da.prototype.updateCoordinate=function(e,t,n){this.changed();const r=e.split("."),i=parseInt(r[0],10),s=parseInt(r[1],10);this.coordinates[i]===void 0&&(this.coordinates[i]=[]),this.coordinates[i][s]=[t,n]};const nSe={MultiPoint:Fl,MultiLineString:io,MultiPolygon:Da},o0=(e,t,n,r,i)=>{const s=n.split("."),c=parseInt(s[0],10),a=s[1]?s.slice(1).join("."):null;return e[c][t](a,r,i)},ra=function(e,t){if(na.call(this,e,t),delete this.coordinates,this.model=nSe[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)};ra.prototype=Object.create(na.prototype),ra.prototype._coordinatesToFeatures=function(e){const t=this.model.bind(this);return e.map(n=>new t(this.ctx,{id:nS(),type:yn.FEATURE,properties:{},geometry:{coordinates:n,type:this.type.replace("Multi","")}}))},ra.prototype.isValid=function(){return this.features.every(e=>e.isValid())},ra.prototype.setCoordinates=function(e){this.features=this._coordinatesToFeatures(e),this.changed()},ra.prototype.getCoordinate=function(e){return o0(this.features,"getCoordinate",e)},ra.prototype.getCoordinates=function(){return JSON.parse(JSON.stringify(this.features.map(e=>e.type===yn.POLYGON?e.getCoordinates():e.coordinates)))},ra.prototype.updateCoordinate=function(e,t,n){o0(this.features,"updateCoordinate",e,t,n),this.changed()},ra.prototype.addCoordinate=function(e,t,n){o0(this.features,"addCoordinate",e,t,n),this.changed()},ra.prototype.removeCoordinate=function(e){o0(this.features,"removeCoordinate",e),this.changed()},ra.prototype.getFeatures=function(){return this.features};function zn(e){this.map=e.map,this.drawConfig=JSON.parse(JSON.stringify(e.options||{})),this._ctx=e}zn.prototype.setSelected=function(e){return this._ctx.store.setSelected(e)},zn.prototype.setSelectedCoordinates=function(e){this._ctx.store.setSelectedCoordinates(e),e.reduce((t,n)=>(t[n.feature_id]===void 0&&(t[n.feature_id]=!0,this._ctx.store.get(n.feature_id).changed()),t),{})},zn.prototype.getSelected=function(){return this._ctx.store.getSelected()},zn.prototype.getSelectedIds=function(){return this._ctx.store.getSelectedIds()},zn.prototype.isSelected=function(e){return this._ctx.store.isSelected(e)},zn.prototype.getFeature=function(e){return this._ctx.store.get(e)},zn.prototype.select=function(e){return this._ctx.store.select(e)},zn.prototype.deselect=function(e){return this._ctx.store.deselect(e)},zn.prototype.deleteFeature=function(e,t={}){return this._ctx.store.delete(e,t)},zn.prototype.addFeature=function(e,t={}){return this._ctx.store.add(e,t)},zn.prototype.clearSelectedFeatures=function(){return this._ctx.store.clearSelected()},zn.prototype.clearSelectedCoordinates=function(){return this._ctx.store.clearSelectedCoordinates()},zn.prototype.setActionableState=function(e={}){const t={trash:e.trash||!1,combineFeatures:e.combineFeatures||!1,uncombineFeatures:e.uncombineFeatures||!1};return this._ctx.events.actionable(t)},zn.prototype.changeMode=function(e,t={},n={}){return this._ctx.events.changeMode(e,t,n)},zn.prototype.fire=function(e,t){return this._ctx.events.fire(e,t)},zn.prototype.updateUIClasses=function(e){return this._ctx.ui.queueMapClasses(e)},zn.prototype.activateUIButton=function(e){return this._ctx.ui.setActiveButton(e)},zn.prototype.featuresAt=function(e,t,n="click"){if(n!=="click"&&n!=="touch")throw new Error("invalid buffer type");return Yh[n](e,t,this._ctx)},zn.prototype.newFeature=function(e){const t=e.geometry.type;return t===yn.POINT?new Fl(this._ctx,e):t===yn.LINE_STRING?new io(this._ctx,e):t===yn.POLYGON?new Da(this._ctx,e):new ra(this._ctx,e)},zn.prototype.isInstanceOf=function(e,t){if(e===yn.POINT)return t instanceof Fl;if(e===yn.LINE_STRING)return t instanceof io;if(e===yn.POLYGON)return t instanceof Da;if(e==="MultiFeature")return t instanceof ra;throw new Error(`Unknown feature class: ${e}`)},zn.prototype.doRender=function(e){return this._ctx.store.featureChanged(e)},zn.prototype.onSetup=function(){},zn.prototype.onDrag=function(){},zn.prototype.onClick=function(){},zn.prototype.onMouseMove=function(){},zn.prototype.onMouseDown=function(){},zn.prototype.onMouseUp=function(){},zn.prototype.onMouseOut=function(){},zn.prototype.onKeyUp=function(){},zn.prototype.onKeyDown=function(){},zn.prototype.onTouchStart=function(){},zn.prototype.onTouchMove=function(){},zn.prototype.onTouchEnd=function(){},zn.prototype.onTap=function(){},zn.prototype.onStop=function(){},zn.prototype.onTrash=function(){},zn.prototype.onCombineFeature=function(){},zn.prototype.onUncombineFeature=function(){},zn.prototype.toDisplayFeatures=function(){throw new Error("You must overwrite toDisplayFeatures")};const bN={drag:"onDrag",click:"onClick",mousemove:"onMouseMove",mousedown:"onMouseDown",mouseup:"onMouseUp",mouseout:"onMouseOut",keyup:"onKeyUp",keydown:"onKeyDown",touchstart:"onTouchStart",touchmove:"onTouchMove",touchend:"onTouchEnd",tap:"onTap"},rSe=Object.keys(bN);function iSe(e){const t=Object.keys(e);return function(n,r={}){let i={};const s=t.reduce((a,d)=>(a[d]=e[d],a),new zn(n));function c(a){return d=>s[a](i,d)}return{start(){i=s.onSetup(r),rSe.forEach(a=>{const d=bN[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 aSe(e){const t=Object.keys(e.options.modes).reduce((b,w)=>(b[w]=iSe(e.options.modes[w]),b),{});let n={},r={};const i={};let s=null,c=null;i.drag=function(b,w){w({point:b.point,time:new Date().getTime()})?(e.ui.queueMapClasses({mouse:Fr.DRAG}),c.drag(b)):b.originalEvent.stopPropagation()},i.mousedrag=function(b){i.drag(b,w=>!eS(n,w))},i.touchdrag=function(b){i.drag(b,w=>!tS(r,w))},i.mousemove=function(b){if((b.originalEvent.buttons!==void 0?b.originalEvent.buttons:b.originalEvent.which)===1)return i.mousedrag(b);const S=s0(b,e);b.featureTarget=S,c.mousemove(b)},i.mousedown=function(b){n={time:new Date().getTime(),point:b.point};const w=s0(b,e);b.featureTarget=w,c.mousedown(b)},i.mouseup=function(b){const w=s0(b,e);b.featureTarget=w,eS(n,{point:b.point,time:new Date().getTime()})?c.click(b):c.mouseup(b)},i.mouseout=function(b){c.mouseout(b)},i.touchstart=function(b){if(!e.options.touchEnabled)return;r={time:new Date().getTime(),point:b.point};const w=Yh.touch(b,null,e)[0];b.featureTarget=w,c.touchstart(b)},i.touchmove=function(b){if(e.options.touchEnabled)return c.touchmove(b),i.touchdrag(b)},i.touchend=function(b){if(b.originalEvent.preventDefault(),!e.options.touchEnabled)return;const w=Yh.touch(b,null,e)[0];b.featureTarget=w,tS(r,{time:new Date().getTime(),point:b.point})?c.tap(b):c.touchend(b)};const a=b=>!(b===8||b===46||b>=48&&b<=57);i.keydown=function(b){(b.srcElement||b.target).classList.contains(xa.CANVAS)&&((b.keyCode===8||b.keyCode===46)&&e.options.controls.trash?(b.preventDefault(),c.trash()):a(b.keyCode)?c.keydown(b):b.keyCode===49&&e.options.controls.point?d(Gn.DRAW_POINT):b.keyCode===50&&e.options.controls.line_string?d(Gn.DRAW_LINE_STRING):b.keyCode===51&&e.options.controls.polygon&&d(Gn.DRAW_POLYGON))},i.keyup=function(b){a(b.keyCode)&&c.keyup(b)},i.zoomend=function(){e.store.changeZoom()},i.data=function(b){if(b.dataType==="style"){const{setup:w,map:S,options:C,store:M}=e;C.styles.some(T=>S.getLayer(T.id))||(w.addLayers(),M.setDirty(),M.render())}};function d(b,w,S={}){c.stop();const C=t[b];if(C===void 0)throw new Error(`${b} is not valid`);s=b;const M=C(e,w);c=X2(M,e),S.silent||e.map.fire(ta.MODE_CHANGE,{mode:b}),e.store.setDirty(),e.store.render()}const p={trash:!1,combineFeatures:!1,uncombineFeatures:!1};function y(b){let w=!1;Object.keys(b).forEach(S=>{if(p[S]===void 0)throw new Error("Invalid action type");p[S]!==b[S]&&(w=!0),p[S]=b[S]}),w&&e.map.fire(ta.ACTIONABLE,{actions:p})}return{start(){s=e.options.defaultMode,c=X2(t[s](e),e)},changeMode:d,actionable:y,currentModeName(){return s},currentModeRender(b,w){return c.render(b,w)},fire(b,w){e.map&&e.map.fire(b,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(b){c.trash(b)},combineFeatures(){c.combineFeatures()},uncombineFeatures(){c.uncombineFeatures()},getMode(){return s}}}function zp(e){return[].concat(e).filter(t=>t!==void 0)}function sSe(){const e=this;if(!(e.ctx.map&&e.ctx.map.getSource(ss.HOT)!==void 0))return d();const n=e.ctx.events.currentModeName();e.ctx.ui.queueMapClasses({mode:n});let r=[],i=[];e.isDirty?i=e.getAllIds():(r=e.getChangedIds().filter(p=>e.get(p)!==void 0),i=e.sources.hot.filter(p=>p.properties.id&&r.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 r.indexOf(y)===-1});const c=s!==e.sources.cold.length||i.length>0;r.forEach(p=>a(p,"hot")),i.forEach(p=>a(p,"cold"));function a(p,y){const b=e.get(p).internal(n);e.ctx.events.currentModeRender(b,w=>{w.properties.mode=n,e.sources[y].push(w)})}c&&e.ctx.map.getSource(ss.COLD).setData({type:yn.FEATURE_COLLECTION,features:e.sources.cold}),e.ctx.map.getSource(ss.HOT).setData({type:yn.FEATURE_COLLECTION,features:e.sources.hot}),d();function d(){e.isDirty=!1,e.clearChangedIds()}}function kr(e){this._features={},this._featureIds=new os,this._selectedFeatureIds=new os,this._selectedCoordinates=[],this._changedFeatureIds=new os,this._emitSelectionChange=!1,this._mapInitialConfig={},this.ctx=e,this.sources={hot:[],cold:[]};let t;this.render=()=>{t||(t=requestAnimationFrame(()=>{t=null,sSe.call(this),this._emitSelectionChange&&(this.ctx.events.fire(ta.SELECTION_CHANGE,{features:this.getSelected().map(n=>n.toGeoJSON()),points:this.getSelectedCoordinates().map(n=>({type:yn.FEATURE,properties:{},geometry:{type:yn.POINT,coordinates:n.coordinates}}))}),this._emitSelectionChange=!1),this.ctx.events.fire(ta.RENDER,{})}))},this.isDirty=!1}kr.prototype.createRenderBatch=function(){const e=this.render;let t=0;return this.render=function(){t++},()=>{this.render=e,t>0&&this.render()}},kr.prototype.setDirty=function(){return this.isDirty=!0,this},kr.prototype.featureCreated=function(e,t={}){if(this._changedFeatureIds.add(e),(t.silent!=null?t.silent:this.ctx.options.suppressAPIEvents)!==!0){const r=this.get(e);this.ctx.events.fire(ta.CREATE,{features:[r.toGeoJSON()]})}return this},kr.prototype.featureChanged=function(e,t={}){return this._changedFeatureIds.add(e),(t.silent!=null?t.silent:this.ctx.options.suppressAPIEvents)!==!0&&this.ctx.events.fire(ta.UPDATE,{action:t.action?t.action:Fp.CHANGE_COORDINATES,features:[this.get(e).toGeoJSON()]}),this},kr.prototype.getChangedIds=function(){return this._changedFeatureIds.values()},kr.prototype.clearChangedIds=function(){return this._changedFeatureIds.clear(),this},kr.prototype.getAllIds=function(){return this._featureIds.values()},kr.prototype.add=function(e,t={}){return this._features[e.id]=e,this._featureIds.add(e.id),this.featureCreated(e.id,{silent:t.silent}),this},kr.prototype.delete=function(e,t={}){const n=[];return zp(e).forEach(r=>{this._featureIds.has(r)&&(this._featureIds.delete(r),this._selectedFeatureIds.delete(r),t.silent||n.indexOf(this._features[r])===-1&&n.push(this._features[r].toGeoJSON()),delete this._features[r],this.isDirty=!0)}),n.length&&this.ctx.events.fire(ta.DELETE,{features:n}),xN(this,t),this},kr.prototype.get=function(e){return this._features[e]},kr.prototype.getAll=function(){return Object.keys(this._features).map(e=>this._features[e])},kr.prototype.select=function(e,t={}){return zp(e).forEach(n=>{this._selectedFeatureIds.has(n)||(this._selectedFeatureIds.add(n),this._changedFeatureIds.add(n),t.silent||(this._emitSelectionChange=!0))}),this},kr.prototype.deselect=function(e,t={}){return zp(e).forEach(n=>{this._selectedFeatureIds.has(n)&&(this._selectedFeatureIds.delete(n),this._changedFeatureIds.add(n),t.silent||(this._emitSelectionChange=!0))}),xN(this,t),this},kr.prototype.clearSelected=function(e={}){return this.deselect(this._selectedFeatureIds.values(),{silent:e.silent}),this},kr.prototype.setSelected=function(e,t={}){return e=zp(e),this.deselect(this._selectedFeatureIds.values().filter(n=>e.indexOf(n)===-1),{silent:t.silent}),this.select(e.filter(n=>!this._selectedFeatureIds.has(n)),{silent:t.silent}),this},kr.prototype.setSelectedCoordinates=function(e){return this._selectedCoordinates=e,this._emitSelectionChange=!0,this},kr.prototype.clearSelectedCoordinates=function(){return this._selectedCoordinates=[],this._emitSelectionChange=!0,this},kr.prototype.getSelectedIds=function(){return this._selectedFeatureIds.values()},kr.prototype.getSelected=function(){return this.getSelectedIds().map(e=>this.get(e))},kr.prototype.getSelectedCoordinates=function(){return this._selectedCoordinates.map(t=>({coordinates:this.get(t.feature_id).getCoordinate(t.coord_path)}))},kr.prototype.isSelected=function(e){return this._selectedFeatureIds.has(e)},kr.prototype.setFeatureProperty=function(e,t,n,r={}){this.get(e).setProperty(t,n),this.featureChanged(e,{silent:r.silent,action:Fp.CHANGE_PROPERTIES})};function xN(e,t={}){const n=e._selectedCoordinates.filter(r=>e._selectedFeatureIds.has(r.feature_id));e._selectedCoordinates.length!==n.length&&!t.silent&&(e._emitSelectionChange=!0),e._selectedCoordinates=n}kr.prototype.storeMapConfig=function(){fN.forEach(e=>{this.ctx.map[e]&&(this._mapInitialConfig[e]=this.ctx.map[e].isEnabled())})},kr.prototype.restoreMapConfig=function(){Object.keys(this._mapInitialConfig).forEach(e=>{this._mapInitialConfig[e]?this.ctx.map[e].enable():this.ctx.map[e].disable()})},kr.prototype.getInitialConfigValue=function(e){return this._mapInitialConfig[e]!==void 0?this._mapInitialConfig[e]:!0};const oSe=["mode","feature","mouse"];function lSe(e){const t={};let n=null,r={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=[];oSe.forEach(C=>{i[C]!==r[C]&&(w.push(`${C}-${r[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),r=Object.assign(r,i)}function d(w,S={}){const C=document.createElement("button");return C.className=`${xa.CONTROL_BUTTON} ${S.className}`,C.setAttribute("title",S.title),S.container.appendChild(C),C.addEventListener("click",M=>{if(M.preventDefault(),M.stopPropagation(),M.target===n){p(),S.onDeactivate();return}y(w),S.onActivate()},!0),C}function p(){n&&(n.classList.remove(xa.ACTIVE_BUTTON),n=null)}function y(w){p();const S=t[w];S&&S&&w!=="trash"&&(S.classList.add(xa.ACTIVE_BUTTON),n=S)}function g(){const w=e.options.controls,S=document.createElement("div");return S.className=`${xa.CONTROL_GROUP} ${xa.CONTROL_BASE}`,w&&(w[_a.LINE]&&(t[_a.LINE]=d(_a.LINE,{container:S,className:xa.CONTROL_BUTTON_LINE,title:`LineString tool ${e.options.keybindings?"(l)":""}`,onActivate:()=>e.events.changeMode(Gn.DRAW_LINE_STRING),onDeactivate:()=>e.events.trash()})),w[_a.POLYGON]&&(t[_a.POLYGON]=d(_a.POLYGON,{container:S,className:xa.CONTROL_BUTTON_POLYGON,title:`Polygon tool ${e.options.keybindings?"(p)":""}`,onActivate:()=>e.events.changeMode(Gn.DRAW_POLYGON),onDeactivate:()=>e.events.trash()})),w[_a.POINT]&&(t[_a.POINT]=d(_a.POINT,{container:S,className:xa.CONTROL_BUTTON_POINT,title:`Marker tool ${e.options.keybindings?"(m)":""}`,onActivate:()=>e.events.changeMode(Gn.DRAW_POINT),onDeactivate:()=>e.events.trash()})),w.trash&&(t.trash=d("trash",{container:S,className:xa.CONTROL_BUTTON_TRASH,title:"Delete",onActivate:()=>{e.events.trash()}})),w.combine_features&&(t.combine_features=d("combineFeatures",{container:S,className:xa.CONTROL_BUTTON_COMBINE_FEATURES,title:"Combine",onActivate:()=>{e.events.combineFeatures()}})),w.uncombine_features&&(t.uncombine_features=d("uncombineFeatures",{container:S,className:xa.CONTROL_BUTTON_UNCOMBINE_FEATURES,title:"Uncombine",onActivate:()=>{e.events.uncombineFeatures()}}))),S}function b(){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:b}}function cSe(e){let t=null,n=null;const r={onRemove(){return e.map.off("load",r.connect),clearInterval(n),r.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",r.connect),clearInterval(n),r.addLayers(),e.store.storeMapConfig(),e.events.addEventListeners()},onAdd(i){if(e.map=i,e.events=aSe(e),e.ui=lSe(e),e.container=i.getContainer(),e.store=new kr(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()?r.connect():(i.on("load",r.connect),n=setInterval(()=>{i.loaded()&&r.connect()},16)),e.events.start(),t},addLayers(){e.map.addSource(ss.COLD,{data:{type:yn.FEATURE_COLLECTION,features:[]},type:"geojson"}),e.map.addSource(ss.HOT,{data:{type:yn.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(ss.COLD)&&e.map.removeSource(ss.COLD),e.map.getSource(ss.HOT)&&e.map.removeSource(ss.HOT)}};return e.setup=r,r}const rS="#3bb2d0",$p="#fbb03b",_N="#fff",wN=[{id:"gl-draw-polygon-fill",type:"fill",filter:["all",["==","$type","Polygon"]],paint:{"fill-color":["case",["==",["get","active"],"true"],$p,rS],"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"],$p,rS],"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":_N}},{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"],$p,rS]}},{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":_N}},{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":$p}},{id:"gl-draw-midpoint",type:"circle",filter:["all",["==","meta","midpoint"]],paint:{"circle-radius":3,"circle-color":$p}}];function l0(e){return function(t){const n=t.featureTarget;return!n||!n.properties?!1:n.properties.meta===e}}function SN(e){return!e.originalEvent||!e.originalEvent.shiftKey?!1:e.originalEvent.button===0}function Uc(e){return!e.featureTarget||!e.featureTarget.properties?!1:e.featureTarget.properties.active===fi.ACTIVE&&e.featureTarget.properties.meta===Bi.FEATURE}function iS(e){return!e.featureTarget||!e.featureTarget.properties?!1:e.featureTarget.properties.active===fi.INACTIVE&&e.featureTarget.properties.meta===Bi.FEATURE}function c0(e){return e.featureTarget===void 0}function aS(e){return!e.featureTarget||!e.featureTarget.properties?!1:e.featureTarget.properties.meta===Bi.FEATURE}function Vp(e){const t=e.featureTarget;return!t||!t.properties?!1:t.properties.meta===Bi.VERTEX}function u0(e){return e.originalEvent?e.originalEvent.shiftKey===!0:!1}function h0(e){return e.keyCode===27}function d0(e){return e.keyCode===13}function uSe(){return!0}const hSe=Object.freeze(Object.defineProperty({__proto__:null,isActiveFeature:Uc,isEnterKey:d0,isEscapeKey:h0,isFeature:aS,isInactiveFeature:iS,isOfMetaType:l0,isShiftDown:u0,isShiftMousedown:SN,isTrue:uSe,isVertex:Vp,noTarget:c0},Symbol.toStringTag,{value:"Module"}));function zl(e,t){this.x=e,this.y=t}zl.prototype={clone(){return new zl(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,n=e.y-this.y;return t*t+n*n},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,n=e[2]*this.x+e[3]*this.y;return this.x=t,this.y=n,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),n=Math.sin(e),r=t*this.x-n*this.y,i=n*this.x+t*this.y;return this.x=r,this.y=i,this},_rotateAround(e,t){const n=Math.cos(e),r=Math.sin(e),i=t.x+n*(this.x-t.x)-r*(this.y-t.y),s=t.y+r*(this.x-t.x)+n*(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:zl},zl.convert=function(e){if(e instanceof zl)return e;if(Array.isArray(e))return new zl(+e[0],+e[1]);if(e.x!==void 0&&e.y!==void 0)return new zl(+e.x,+e.y);throw new Error("Expected [x, y] or {x, y} point format")};function sS(e,t){const n=t.getBoundingClientRect();return new zl(e.clientX-n.left-(t.clientLeft||0),e.clientY-n.top-(t.clientTop||0))}function qh(e,t,n,r){return{type:yn.FEATURE,properties:{meta:Bi.VERTEX,parent:e,coord_path:n,active:r?fi.ACTIVE:fi.INACTIVE},geometry:{type:yn.POINT,coordinates:t}}}function CN(e,t,n){const r=t.geometry.coordinates,i=n.geometry.coordinates;if(r[1]>K2||r[1]<J2||i[1]>K2||i[1]<J2)return null;const s={lng:(r[0]+i[0])/2,lat:(r[1]+i[1])/2};return{type:yn.FEATURE,properties:{meta:Bi.MIDPOINT,parent:e,lng:s.lng,lat:s.lat,coord_path:n.properties.coord_path},geometry:{type:yn.POINT,coordinates:[s.lng,s.lat]}}}function f0(e,t={},n=null){const{type:r,coordinates:i}=e.geometry,s=e.properties&&e.properties.id;let c=[];r===yn.POINT?c.push(qh(s,i,n,d(n))):r===yn.POLYGON?i.forEach((y,g)=>{a(y,n!==null?`${n}.${g}`:String(g))}):r===yn.LINE_STRING?a(i,n):r.indexOf(yn.MULTI_PREFIX)===0&&p();function a(y,g){let b="",w=null;y.forEach((S,C)=>{const M=g!=null?`${g}.${C}`:String(C),O=qh(s,S,M,d(M));if(t.midpoints&&w){const D=CN(s,w,O);D&&c.push(D)}w=O;const T=JSON.stringify(S);b!==T&&c.push(O),C===0&&(b=T)})}function d(y){return t.selectedPaths?t.selectedPaths.indexOf(y)!==-1:!1}function p(){const y=r.replace(yn.MULTI_PREFIX,"");i.forEach((g,b)=>{const w={type:yn.FEATURE,properties:e.properties,geometry:{type:y,coordinates:g}};c=c.concat(f0(w,t,b))})}return c}const As={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:p0,LAT_MAX:m0,LAT_RENDERED_MIN:MN,LAT_RENDERED_MAX:AN,LNG_MIN:EN,LNG_MAX:TN}=pN;function dSe(e){const t={Point:0,LineString:1,Polygon:2,MultiPoint:1,MultiLineString:2,MultiPolygon:3}[e.geometry.type],n=[e.geometry.coordinates].flat(t),r=n.map(a=>a[0]),i=n.map(a=>a[1]),s=a=>Math.min.apply(null,a),c=a=>Math.max.apply(null,a);return[s(r),s(i),c(r),c(i)]}function oS(e,t){let n=p0,r=m0,i=p0,s=m0,c=TN,a=EN;e.forEach(p=>{const y=dSe(p),g=y[1],b=y[3],w=y[0],S=y[2];g>n&&(n=g),b<r&&(r=b),b>i&&(i=b),g<s&&(s=g),w<c&&(c=w),S>a&&(a=S)});const d=t;return n+d.lat>AN&&(d.lat=AN-n),i+d.lat>m0&&(d.lat=m0-i),r+d.lat<MN&&(d.lat=MN-r),s+d.lat<p0&&(d.lat=p0-s),c+d.lng<=EN&&(d.lng+=Math.ceil(Math.abs(d.lng)/360)*360),a+d.lng>=TN&&(d.lng-=Math.ceil(Math.abs(d.lng)/360)*360),d}function lS(e,t){const n=oS(e.map(r=>r.toGeoJSON()),t);e.forEach(r=>{const i=r.getCoordinates(),s=p=>{const y={lng:p[0]+n.lng,lat:p[1]+n.lat};return[y.lng,y.lat]},c=p=>p.map(y=>s(y)),a=p=>p.map(y=>c(y));let d;r.type===yn.POINT?d=s(i):r.type===yn.LINE_STRING||r.type===yn.MULTI_POINT?d=i.map(s):r.type===yn.POLYGON||r.type===yn.MULTI_LINE_STRING?d=i.map(c):r.type===yn.MULTI_POLYGON&&(d=i.map(a)),r.incomingCoords(d)})}const Cr={};Cr.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(n=>this.getFeature(n)!==void 0)),this.fireActionable(),this.setActionableState({combineFeatures:!0,uncombineFeatures:!0,trash:!0}),t},Cr.fireUpdate=function(){this.fire(ta.UPDATE,{action:Fp.MOVE,features:this.getSelected().map(e=>e.toGeoJSON())})},Cr.fireActionable=function(){const e=this.getSelected(),t=e.filter(s=>this.isInstanceOf("MultiFeature",s));let n=!1;if(e.length>1){n=!0;const s=e[0].type.replace("Multi","");e.forEach(c=>{c.type.replace("Multi","")!==s&&(n=!1)})}const r=t.length>0,i=e.length>0;this.setActionableState({combineFeatures:n,uncombineFeatures:r,trash:i})},Cr.getUniqueIds=function(e){return e.length?e.map(n=>n.properties.id).filter(n=>n!==void 0).reduce((n,r)=>(n.add(r),n),new os).values():[]},Cr.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},Cr.onStop=function(){As.enable(this)},Cr.onMouseMove=function(e,t){return aS(t)&&e.dragMoving&&this.fireUpdate(),this.stopExtendedInteractions(e),!0},Cr.onMouseOut=function(e){return e.dragMoving?this.fireUpdate():!0},Cr.onTap=Cr.onClick=function(e,t){if(c0(t))return this.clickAnywhere(e,t);if(l0(Bi.VERTEX)(t))return this.clickOnVertex(e,t);if(aS(t))return this.clickOnFeature(e,t)},Cr.clickAnywhere=function(e){const t=this.getSelectedIds();t.length&&(this.clearSelectedFeatures(),t.forEach(n=>this.doRender(n))),As.enable(this),this.stopExtendedInteractions(e)},Cr.clickOnVertex=function(e,t){this.changeMode(Gn.DIRECT_SELECT,{featureId:t.featureTarget.properties.parent,coordPath:t.featureTarget.properties.coord_path,startPos:t.lngLat}),this.updateUIClasses({mouse:Fr.MOVE})},Cr.startOnActiveFeature=function(e,t){this.stopExtendedInteractions(e),this.map.dragPan.disable(),this.doRender(t.featureTarget.properties.id),e.canDragMove=!0,e.dragMoveLocation=t.lngLat},Cr.clickOnFeature=function(e,t){As.disable(this),this.stopExtendedInteractions(e);const n=u0(t),r=this.getSelectedIds(),i=t.featureTarget.properties.id,s=this.isSelected(i);if(!n&&s&&this.getFeature(i).type!==yn.POINT)return this.changeMode(Gn.DIRECT_SELECT,{featureId:i});s&&n?(this.deselect(i),this.updateUIClasses({mouse:Fr.POINTER}),r.length===1&&As.enable(this)):!s&&n?(this.select(i),this.updateUIClasses({mouse:Fr.MOVE})):!s&&!n&&(r.forEach(c=>this.doRender(c)),this.setSelected(i),this.updateUIClasses({mouse:Fr.MOVE})),this.doRender(i)},Cr.onMouseDown=function(e,t){if(e.initialDragPanState=this.map.dragPan.isEnabled(),Uc(t))return this.startOnActiveFeature(e,t);if(this.drawConfig.boxSelect&&SN(t))return this.startBoxSelect(e,t)},Cr.startBoxSelect=function(e,t){this.stopExtendedInteractions(e),this.map.dragPan.disable(),e.boxSelectStartLocation=sS(t.originalEvent,this.map.getContainer()),e.canBoxSelect=!0},Cr.onTouchStart=function(e,t){if(Uc(t))return this.startOnActiveFeature(e,t)},Cr.onDrag=function(e,t){if(e.canDragMove)return this.dragMove(e,t);if(this.drawConfig.boxSelect&&e.canBoxSelect)return this.whileBoxSelect(e,t)},Cr.whileBoxSelect=function(e,t){e.boxSelecting=!0,this.updateUIClasses({mouse:Fr.ADD}),e.boxSelectElement||(e.boxSelectElement=document.createElement("div"),e.boxSelectElement.classList.add(xa.BOX_SELECT),this.map.getContainer().appendChild(e.boxSelectElement));const n=sS(t.originalEvent,this.map.getContainer()),r=Math.min(e.boxSelectStartLocation.x,n.x),i=Math.max(e.boxSelectStartLocation.x,n.x),s=Math.min(e.boxSelectStartLocation.y,n.y),c=Math.max(e.boxSelectStartLocation.y,n.y),a=`translate(${r}px, ${s}px)`;e.boxSelectElement.style.transform=a,e.boxSelectElement.style.WebkitTransform=a,e.boxSelectElement.style.width=`${i-r}px`,e.boxSelectElement.style.height=`${c-s}px`},Cr.dragMove=function(e,t){e.dragMoving=!0,t.originalEvent.stopPropagation();const n={lng:t.lngLat.lng-e.dragMoveLocation.lng,lat:t.lngLat.lat-e.dragMoveLocation.lat};lS(this.getSelected(),n),e.dragMoveLocation=t.lngLat},Cr.onTouchEnd=Cr.onMouseUp=function(e,t){if(e.dragMoving)this.fireUpdate();else if(e.boxSelecting){const n=[e.boxSelectStartLocation,sS(t.originalEvent,this.map.getContainer())],r=this.featuresAt(null,n,"click"),i=this.getUniqueIds(r).filter(s=>!this.isSelected(s));i.length&&(this.select(i),i.forEach(s=>this.doRender(s)),this.updateUIClasses({mouse:Fr.MOVE}))}this.stopExtendedInteractions(e)},Cr.toDisplayFeatures=function(e,t,n){t.properties.active=this.isSelected(t.properties.id)?fi.ACTIVE:fi.INACTIVE,n(t),this.fireActionable(),!(t.properties.active!==fi.ACTIVE||t.geometry.type===yn.POINT)&&f0(t).forEach(n)},Cr.onTrash=function(){this.deleteFeature(this.getSelectedIds()),this.fireActionable()},Cr.onCombineFeatures=function(){const e=this.getSelected();if(e.length===0||e.length<2)return;const t=[],n=[],r=e[0].type.replace("Multi","");for(let i=0;i<e.length;i++){const s=e[i];if(s.type.replace("Multi","")!==r)return;s.type.includes("Multi")?s.getCoordinates().forEach(c=>{t.push(c)}):t.push(s.getCoordinates()),n.push(s.toGeoJSON())}if(n.length>1){const i=this.newFeature({type:yn.FEATURE,properties:n[0].properties,geometry:{type:`Multi${r}`,coordinates:t}});this.addFeature(i),this.deleteFeature(this.getSelectedIds(),{silent:!0}),this.setSelected([i.id]),this.fire(ta.COMBINE_FEATURES,{createdFeatures:[i.toGeoJSON()],deletedFeatures:n})}this.fireActionable()},Cr.onUncombineFeatures=function(){const e=this.getSelected();if(e.length===0)return;const t=[],n=[];for(let r=0;r<e.length;r++){const i=e[r];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}),n.push(i.toGeoJSON()))}t.length>1&&this.fire(ta.UNCOMBINE_FEATURES,{createdFeatures:t,deletedFeatures:n}),this.fireActionable()};const IN=l0(Bi.VERTEX),PN=l0(Bi.MIDPOINT),Mr={};Mr.fireUpdate=function(){this.fire(ta.UPDATE,{action:Fp.CHANGE_COORDINATES,features:this.getSelected().map(e=>e.toGeoJSON())})},Mr.fireActionable=function(e){this.setActionableState({combineFeatures:!1,uncombineFeatures:!1,trash:e.selectedCoordPaths.length>0})},Mr.startDragging=function(e,t){e.initialDragPanState=this.map.dragPan.isEnabled(),this.map.dragPan.disable(),e.canDragMove=!0,e.dragMoveLocation=t.lngLat},Mr.stopDragging=function(e){e.canDragMove&&e.initialDragPanState===!0&&this.map.dragPan.enable(),e.dragMoving=!1,e.canDragMove=!1,e.dragMoveLocation=null},Mr.onVertex=function(e,t){this.startDragging(e,t);const n=t.featureTarget.properties,r=e.selectedCoordPaths.indexOf(n.coord_path);!u0(t)&&r===-1?e.selectedCoordPaths=[n.coord_path]:u0(t)&&r===-1&&e.selectedCoordPaths.push(n.coord_path);const i=this.pathsToCoordinates(e.featureId,e.selectedCoordPaths);this.setSelectedCoordinates(i)},Mr.onMidpoint=function(e,t){this.startDragging(e,t);const n=t.featureTarget.properties;e.feature.addCoordinate(n.coord_path,n.lng,n.lat),this.fireUpdate(),e.selectedCoordPaths=[n.coord_path]},Mr.pathsToCoordinates=function(e,t){return t.map(n=>({feature_id:e,coord_path:n}))},Mr.onFeature=function(e,t){e.selectedCoordPaths.length===0?this.startDragging(e,t):this.stopDragging(e)},Mr.dragFeature=function(e,t,n){lS(this.getSelected(),n),e.dragMoveLocation=t.lngLat},Mr.dragVertex=function(e,t,n){const r=e.selectedCoordPaths.map(c=>e.feature.getCoordinate(c)),i=r.map(c=>({type:yn.FEATURE,properties:{},geometry:{type:yn.POINT,coordinates:c}})),s=oS(i,n);for(let c=0;c<r.length;c++){const a=r[c];e.feature.updateCoordinate(e.selectedCoordPaths[c],a[0]+s.lng,a[1]+s.lat)}},Mr.clickNoTarget=function(){this.changeMode(Gn.SIMPLE_SELECT)},Mr.clickInactive=function(){this.changeMode(Gn.SIMPLE_SELECT)},Mr.clickActiveFeature=function(e){e.selectedCoordPaths=[],this.clearSelectedCoordinates(),e.feature.changed()},Mr.onSetup=function(e){const t=e.featureId,n=this.getFeature(t);if(!n)throw new Error("You must provide a featureId to enter direct_select mode");if(n.type===yn.POINT)throw new TypeError("direct_select mode doesn't handle point features");const r={featureId:t,feature:n,dragMoveLocation:e.startPos||null,dragMoving:!1,canDragMove:!1,selectedCoordPaths:e.coordPath?[e.coordPath]:[]};return this.setSelectedCoordinates(this.pathsToCoordinates(t,r.selectedCoordPaths)),this.setSelected(t),As.disable(this),this.setActionableState({trash:!0}),r},Mr.onStop=function(){As.enable(this),this.clearSelectedCoordinates()},Mr.toDisplayFeatures=function(e,t,n){e.featureId===t.properties.id?(t.properties.active=fi.ACTIVE,n(t),f0(t,{map:this.map,midpoints:!0,selectedPaths:e.selectedCoordPaths}).forEach(n)):(t.properties.active=fi.INACTIVE,n(t)),this.fireActionable(e)},Mr.onTrash=function(e){e.selectedCoordPaths.sort((t,n)=>n.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(Gn.SIMPLE_SELECT,{}))},Mr.onMouseMove=function(e,t){const n=Uc(t),r=IN(t),i=PN(t),s=e.selectedCoordPaths.length===0;return n&&s?this.updateUIClasses({mouse:Fr.MOVE}):r&&!s?this.updateUIClasses({mouse:Fr.MOVE}):this.updateUIClasses({mouse:Fr.NONE}),(r||n||i)&&e.dragMoving&&this.fireUpdate(),this.stopDragging(e),!0},Mr.onMouseOut=function(e){return e.dragMoving&&this.fireUpdate(),!0},Mr.onTouchStart=Mr.onMouseDown=function(e,t){if(IN(t))return this.onVertex(e,t);if(Uc(t))return this.onFeature(e,t);if(PN(t))return this.onMidpoint(e,t)},Mr.onDrag=function(e,t){if(e.canDragMove!==!0)return;e.dragMoving=!0,t.originalEvent.stopPropagation();const n={lng:t.lngLat.lng-e.dragMoveLocation.lng,lat:t.lngLat.lat-e.dragMoveLocation.lat};e.selectedCoordPaths.length>0?this.dragVertex(e,t,n):this.dragFeature(e,t,n),e.dragMoveLocation=t.lngLat},Mr.onClick=function(e,t){if(c0(t))return this.clickNoTarget(e,t);if(Uc(t))return this.clickActiveFeature(e,t);if(iS(t))return this.clickInactive(e,t);this.stopDragging(e)},Mr.onTap=function(e,t){if(c0(t))return this.clickNoTarget(e,t);if(Uc(t))return this.clickActiveFeature(e,t);if(iS(t))return this.clickInactive(e,t)},Mr.onTouchEnd=Mr.onMouseUp=function(e){e.dragMoving&&this.fireUpdate(),this.stopDragging(e)};const ao={};ao.onSetup=function(){const e=this.newFeature({type:yn.FEATURE,properties:{},geometry:{type:yn.POINT,coordinates:[]}});return this.addFeature(e),this.clearSelectedFeatures(),this.updateUIClasses({mouse:Fr.ADD}),this.activateUIButton(_a.POINT),this.setActionableState({trash:!0}),{point:e}},ao.stopDrawingAndRemove=function(e){this.deleteFeature([e.point.id],{silent:!0}),this.changeMode(Gn.SIMPLE_SELECT)},ao.onTap=ao.onClick=function(e,t){this.updateUIClasses({mouse:Fr.MOVE}),e.point.updateCoordinate("",t.lngLat.lng,t.lngLat.lat),this.fire(ta.CREATE,{features:[e.point.toGeoJSON()]}),this.changeMode(Gn.SIMPLE_SELECT,{featureIds:[e.point.id]})},ao.onStop=function(e){this.activateUIButton(),e.point.getCoordinate().length||this.deleteFeature([e.point.id],{silent:!0})},ao.toDisplayFeatures=function(e,t,n){const r=t.properties.id===e.point.id;if(t.properties.active=r?fi.ACTIVE:fi.INACTIVE,!r)return n(t)},ao.onTrash=ao.stopDrawingAndRemove,ao.onKeyUp=function(e,t){if(h0(t)||d0(t))return this.stopDrawingAndRemove(e,t)};function g0(e,t){return e.lngLat?e.lngLat.lng===t[0]&&e.lngLat.lat===t[1]:!1}const Es={};Es.onSetup=function(){const e=this.newFeature({type:yn.FEATURE,properties:{},geometry:{type:yn.POLYGON,coordinates:[[]]}});return this.addFeature(e),this.clearSelectedFeatures(),As.disable(this),this.updateUIClasses({mouse:Fr.ADD}),this.activateUIButton(_a.POLYGON),this.setActionableState({trash:!0}),{polygon:e,currentVertexPosition:0}},Es.clickAnywhere=function(e,t){if(e.currentVertexPosition>0&&g0(t,e.polygon.coordinates[0][e.currentVertexPosition-1]))return this.changeMode(Gn.SIMPLE_SELECT,{featureIds:[e.polygon.id]});this.updateUIClasses({mouse:Fr.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)},Es.clickOnVertex=function(e){return this.changeMode(Gn.SIMPLE_SELECT,{featureIds:[e.polygon.id]})},Es.onMouseMove=function(e,t){e.polygon.updateCoordinate(`0.${e.currentVertexPosition}`,t.lngLat.lng,t.lngLat.lat),Vp(t)&&this.updateUIClasses({mouse:Fr.POINTER})},Es.onTap=Es.onClick=function(e,t){return Vp(t)?this.clickOnVertex(e,t):this.clickAnywhere(e,t)},Es.onKeyUp=function(e,t){h0(t)?(this.deleteFeature([e.polygon.id],{silent:!0}),this.changeMode(Gn.SIMPLE_SELECT)):d0(t)&&this.changeMode(Gn.SIMPLE_SELECT,{featureIds:[e.polygon.id]})},Es.onStop=function(e){this.updateUIClasses({mouse:Fr.NONE}),As.enable(this),this.activateUIButton(),this.getFeature(e.polygon.id)!==void 0&&(e.polygon.removeCoordinate(`0.${e.currentVertexPosition}`),e.polygon.isValid()?this.fire(ta.CREATE,{features:[e.polygon.toGeoJSON()]}):(this.deleteFeature([e.polygon.id],{silent:!0}),this.changeMode(Gn.SIMPLE_SELECT,{},{silent:!0})))},Es.toDisplayFeatures=function(e,t,n){const r=t.properties.id===e.polygon.id;if(t.properties.active=r?fi.ACTIVE:fi.INACTIVE,!r)return n(t);if(t.geometry.coordinates.length===0)return;const i=t.geometry.coordinates[0].length;if(!(i<3)){if(t.properties.meta=Bi.FEATURE,n(qh(e.polygon.id,t.geometry.coordinates[0][0],"0.0",!1)),i>3){const s=t.geometry.coordinates[0].length-3;n(qh(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(n({type:yn.FEATURE,properties:t.properties,geometry:{coordinates:s,type:yn.LINE_STRING}}),i===3)return}return n(t)}},Es.onTrash=function(e){this.deleteFeature([e.polygon.id],{silent:!0}),this.changeMode(Gn.SIMPLE_SELECT)};const Ts={};Ts.onSetup=function(e){e=e||{};const t=e.featureId;let n,r,i="forward";if(t){if(n=this.getFeature(t),!n)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=n.coordinates.length-1;if(n.coordinates[c][0]===s[0]&&n.coordinates[c][1]===s[1])r=c+1,n.addCoordinate(r,...n.coordinates[c]);else if(n.coordinates[0][0]===s[0]&&n.coordinates[0][1]===s[1])i="backwards",r=0,n.addCoordinate(r,...n.coordinates[0]);else throw new Error("`from` should match the point at either the start or the end of the provided LineString")}else n=this.newFeature({type:yn.FEATURE,properties:{},geometry:{type:yn.LINE_STRING,coordinates:[]}}),r=0,this.addFeature(n);return this.clearSelectedFeatures(),As.disable(this),this.updateUIClasses({mouse:Fr.ADD}),this.activateUIButton(_a.LINE),this.setActionableState({trash:!0}),{line:n,currentVertexPosition:r,direction:i}},Ts.clickAnywhere=function(e,t){if(e.currentVertexPosition>0&&g0(t,e.line.coordinates[e.currentVertexPosition-1])||e.direction==="backwards"&&g0(t,e.line.coordinates[e.currentVertexPosition+1]))return this.changeMode(Gn.SIMPLE_SELECT,{featureIds:[e.line.id]});this.updateUIClasses({mouse:Fr.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)},Ts.clickOnVertex=function(e){return this.changeMode(Gn.SIMPLE_SELECT,{featureIds:[e.line.id]})},Ts.onMouseMove=function(e,t){e.line.updateCoordinate(e.currentVertexPosition,t.lngLat.lng,t.lngLat.lat),Vp(t)&&this.updateUIClasses({mouse:Fr.POINTER})},Ts.onTap=Ts.onClick=function(e,t){if(Vp(t))return this.clickOnVertex(e,t);this.clickAnywhere(e,t)},Ts.onKeyUp=function(e,t){d0(t)?this.changeMode(Gn.SIMPLE_SELECT,{featureIds:[e.line.id]}):h0(t)&&(this.deleteFeature([e.line.id],{silent:!0}),this.changeMode(Gn.SIMPLE_SELECT))},Ts.onStop=function(e){As.enable(this),this.activateUIButton(),this.getFeature(e.line.id)!==void 0&&(e.line.removeCoordinate(`${e.currentVertexPosition}`),e.line.isValid()?this.fire(ta.CREATE,{features:[e.line.toGeoJSON()]}):(this.deleteFeature([e.line.id],{silent:!0}),this.changeMode(Gn.SIMPLE_SELECT,{},{silent:!0})))},Ts.onTrash=function(e){this.deleteFeature([e.line.id],{silent:!0}),this.changeMode(Gn.SIMPLE_SELECT)},Ts.toDisplayFeatures=function(e,t,n){const r=t.properties.id===e.line.id;if(t.properties.active=r?fi.ACTIVE:fi.INACTIVE,!r)return n(t);t.geometry.coordinates.length<2||(t.properties.meta=Bi.FEATURE,n(qh(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)),n(t))};const ON={simple_select:Cr,direct_select:Mr,draw_point:ao,draw_polygon:Es,draw_line_string:Ts},fSe={defaultMode:Gn.SIMPLE_SELECT,keybindings:!0,touchEnabled:!0,clickBuffer:2,touchBuffer:25,boxSelect:!0,displayControlsDefault:!0,styles:wN,modes:ON,controls:{},userProperties:!1,suppressAPIEvents:!0},pSe={point:!0,line_string:!0,polygon:!0,trash:!0,combine_features:!0,uncombine_features:!0},mSe={point:!1,line_string:!1,polygon:!1,trash:!1,combine_features:!1,uncombine_features:!1};function kN(e,t){return e.map(n=>n.source?n:Object.assign({},n,{id:`${n.id}.${t}`,source:t==="hot"?ss.HOT:ss.COLD}))}function gSe(e={}){let t=Object.assign({},e);return e.controls||(t.controls={}),e.displayControlsDefault===!1?t.controls=Object.assign({},mSe,e.controls):t.controls=Object.assign({},pSe,e.controls),t=Object.assign({},fSe,t),t.styles=kN(t.styles,"cold").concat(kN(t.styles,"hot")),t}var ySe=bSe,vSe={Point:"geometry",MultiPoint:"geometry",LineString:"geometry",MultiLineString:"geometry",Polygon:"geometry",MultiPolygon:"geometry",GeometryCollection:"geometry",Feature:"feature",FeatureCollection:"featurecollection"};function bSe(e){if(!e||!e.type)return null;var t=vSe[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 xSe=Jn(ySe);function DN(e,t){return e.length!==t.length?!1:JSON.stringify(e.map(n=>n).sort())===JSON.stringify(t.map(n=>n).sort())}const _Se={Polygon:Da,LineString:io,Point:Fl,MultiPolygon:ra,MultiLineString:ra,MultiPoint:ra};function wSe(e,t){t.modes=Gn;const n=e.options.suppressAPIEvents!==void 0?!!e.options.suppressAPIEvents:!0;return t.getFeatureIdsAt=function(r){return Yh.click({point:r},null,e).map(s=>s.properties.id)},t.getSelectedIds=function(){return e.store.getSelectedIds()},t.getSelected=function(){return{type:yn.FEATURE_COLLECTION,features:e.store.getSelectedIds().map(r=>e.store.get(r)).map(r=>r.toGeoJSON())}},t.getSelectedPoints=function(){return{type:yn.FEATURE_COLLECTION,features:e.store.getSelectedCoordinates().map(r=>({type:yn.FEATURE,properties:{},geometry:{type:yn.POINT,coordinates:r.coordinates}}))}},t.set=function(r){if(r.type===void 0||r.type!==yn.FEATURE_COLLECTION||!Array.isArray(r.features))throw new Error("Invalid FeatureCollection");const i=e.store.createRenderBatch();let s=e.store.getAllIds().slice();const c=t.add(r),a=new os(c);return s=s.filter(d=>!a.has(d)),s.length&&t.delete(s),i(),c},t.add=function(r){const s=JSON.parse(JSON.stringify(xSe(r))).features.map(c=>{if(c.id=c.id||nS(),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=_Se[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:n})}else{const a=e.store.get(c.id),d=a.properties;a.properties=c.properties,hI(d,c.properties)||e.store.featureChanged(a.id,{silent:n}),hI(a.getCoordinates(),c.geometry.coordinates)||a.incomingCoords(c.geometry.coordinates)}return c.id});return e.store.render(),s},t.get=function(r){const i=e.store.get(r);if(i)return i.toGeoJSON()},t.getAll=function(){return{type:yn.FEATURE_COLLECTION,features:e.store.getAll().map(r=>r.toGeoJSON())}},t.delete=function(r){return e.store.delete(r,{silent:n}),t.getMode()===Gn.DIRECT_SELECT&&!e.store.getSelectedIds().length?e.events.changeMode(Gn.SIMPLE_SELECT,void 0,{silent:n}):e.store.render(),t},t.deleteAll=function(){return e.store.delete(e.store.getAllIds(),{silent:n}),t.getMode()===Gn.DIRECT_SELECT?e.events.changeMode(Gn.SIMPLE_SELECT,void 0,{silent:n}):e.store.render(),t},t.changeMode=function(r,i={}){return r===Gn.SIMPLE_SELECT&&t.getMode()===Gn.SIMPLE_SELECT?(DN(i.featureIds||[],e.store.getSelectedIds())||(e.store.setSelected(i.featureIds,{silent:n}),e.store.render()),t):(r===Gn.DIRECT_SELECT&&t.getMode()===Gn.DIRECT_SELECT&&i.featureId===e.store.getSelectedIds()[0]||e.events.changeMode(r,i,{silent:n}),t)},t.getMode=function(){return e.events.getMode()},t.trash=function(){return e.events.trash({silent:n}),t},t.combineFeatures=function(){return e.events.combineFeatures({silent:n}),t},t.uncombineFeatures=function(){return e.events.uncombineFeatures({silent:n}),t},t.setFeatureProperty=function(r,i,s){return e.store.setFeatureProperty(r,i,s,{silent:n}),t},t}const SSe=Object.freeze(Object.defineProperty({__proto__:null,CommonSelectors:hSe,ModeHandler:X2,StringSet:os,constrainFeatureMovement:oS,createMidPoint:CN,createSupplementaryPoints:f0,createVertex:qh,doubleClickZoom:As,euclideanDistance:Q2,featuresAt:Yh,getFeatureAtAndSetCursors:s0,isClick:eS,isEventAtCoordinates:g0,isTap:tS,mapEventToBoundingBox:yN,moveFeatures:lS,sortFeatures:gN,stringSetsAreEqual:DN,theme:wN,toDenseArray:zp},Symbol.toStringTag,{value:"Module"})),CSe=function(e,t){e=gSe(e);const n={options:e};t=wSe(n,t),n.api=t;const r=cSe(n);return t.onAdd=r.onAdd,t.onRemove=r.onRemove,t.types=_a,t.options=e,t};function Jh(e){CSe(e,this)}Jh.modes=ON,Jh.constants=pN,Jh.lib=SSe;const MSe=({polygon:e,deleteFeature:t,trigger:n})=>{var C;const[r,i]=H.useState(!1),{mapRef:s}=H.useContext(ii),{addNewPlot:c}=H.useContext(Po);H.useState(null);const[a,d]=H.useState([]),[p,y]=H.useState(!1),[g,b]=H.useState(!1),w=()=>{i(!1),t()},S=M=>{console.log("handlePlotCreation data",M),b(!0),c(M).then(()=>{t(),Sc.success("Plot created successfully")}).catch(O=>{Sc.error("Could not create the plot")}).finally(()=>{b(!1),w()})};return H.useEffect(()=>{y(!0),Ng().then(M=>{d(M)}).finally(()=>{y(!1)})},[]),K.jsx(To,{trigger:n||K.jsx(Vn,{color:"primary",children:"Add New Plot"}),title:"Add New Plot",headerClassName:"m-4",open:r,setOpen:i,portalContainer:s!=null&&s.current?(C=s==null?void 0:s.current)==null?void 0:C.getMap().getContainer():document.body,children:K.jsx(xo,{children:K.jsx("div",{className:"h-[400px] overflow-y-auto",children:K.jsx(aP,{initialValues:{options:e},onSubmit:S,className:"p-4",submitButtonText:"Create Plot"})})})})},ASe=({feature:e,deleteFeature:t,trigger:n})=>{var p,y;const[r,i]=H.useState(!1);H.useContext(ii);const{addNewMarker:s}=H.useContext(Ns),c={longitude:(p=e==null?void 0:e.geometry)==null?void 0:p.coordinates[0],latitude:(y=e==null?void 0:e.geometry)==null?void 0:y.coordinates[1]};console.log("feature",e);const a=()=>{t(),i(!1)},d=g=>{s(g),t(),a()};return console.log("initialValues",c),K.jsx(To,{trigger:n||K.jsxs(yo,{color:"primary",children:[K.jsx(xG,{})," Add New Marker"]}),title:"Add New Marker",headerClassName:"m-4",description:"add a new marker to the map",open:r,setOpen:i,onClose:a,children:K.jsx(xo,{children:K.jsx(yT,{initialValues:c,onSubmit:d,onCancel:a})})})};function ESe(e){return vc({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 TSe(){const[e,t]=H.useState({});rn(C=>C.setViewMode),rn(C=>C.viewMode);const[n,r]=H.useState(),[i,s]=H.useState([]),{drawRef:c,mapRef:a,showDrawActionPopup:d,setShowDrawActionPopup:p}=H.useContext(ii),y=Jh.constants;y.classes.CONTROL_BASE="maplibregl-ctrl",y.classes.CONTROL_PREFIX="maplibregl-ctrl-",y.classes.CONTROL_GROUP="maplibregl-ctrl-group";const g=H.useCallback(C=>{console.log("onCreate"),t(M=>{const O={...M};for(const T of C.features)O[T.id]=T;return O})},[]),b=g;Eu(()=>{const C=new Jh({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 c.current=C,C},({map:C})=>{C.on("draw.create",g),C.on("draw.update",b)},({map:C})=>{C.off("draw.create",g),C.off("draw.update",b)},{position:"top-right"});const w=C=>{console.log("mode changed",C.mode),r(C.mode)},S=C=>{console.log("selection changed",C);const M=c.current.getSelected();s(M),p(M.features.length>0)};return H.useEffect(()=>{const C=a.current.getMap();return C.on("draw.modechange",w),C.on("draw.selectionchange",S),()=>{C.off("draw.modechange",w),C.off("draw.selectionchange",S)}},[c]),null}const ISe=()=>{const e=rn(r=>r.viewMode),t=rn(r=>r.cursorCords),n=rn(r=>r.hoveredValue);return K.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:[K.jsxs("span",{children:["mode: ",e]}),K.jsxs("span",{children:[n&&K.jsxs("span",{children:[K.jsxs("span",{children:[n.label,":",(n==null?void 0:n.value)&&n.value]}),K.jsx("div",{style:{width:10,height:10,backgroundColor:n.color,display:"inline-block"}})]})," ",K.jsx("span",{children:`${t[0].toFixed(6)}, ${t[1].toFixed(6)}`})]})]})};var cS="Tabs",[PSe,wEe]=_o(cS,[pg]),LN=pg(),[OSe,uS]=PSe(cS),NN=Ne.forwardRef((e,t)=>{const{__scopeTabs:n,value:r,onValueChange:i,defaultValue:s,orientation:c="horizontal",dir:a,activationMode:d="automatic",...p}=e,y=xx(a),[g,b]=Nu({prop:r,onChange:i,defaultProp:s});return K.jsx(OSe,{scope:n,baseId:mc(),value:g,onValueChange:b,orientation:c,dir:y,activationMode:d,children:K.jsx(Ar.div,{dir:y,"data-orientation":c,...p,ref:t})})});NN.displayName=cS;var RN="TabsList",jN=Ne.forwardRef((e,t)=>{const{__scopeTabs:n,loop:r=!0,...i}=e,s=uS(RN,n),c=LN(n);return K.jsx(NA,{asChild:!0,...c,orientation:s.orientation,dir:s.dir,loop:r,children:K.jsx(Ar.div,{role:"tablist","aria-orientation":s.orientation,...i,ref:t})})});jN.displayName=RN;var BN="TabsTrigger",FN=Ne.forwardRef((e,t)=>{const{__scopeTabs:n,value:r,disabled:i=!1,...s}=e,c=uS(BN,n),a=LN(n),d=VN(c.baseId,r),p=GN(c.baseId,r),y=r===c.value;return K.jsx(RA,{asChild:!0,...a,focusable:!i,active:y,children:K.jsx(Ar.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:nr(e.onMouseDown,g=>{!i&&g.button===0&&g.ctrlKey===!1?c.onValueChange(r):g.preventDefault()}),onKeyDown:nr(e.onKeyDown,g=>{[" ","Enter"].includes(g.key)&&c.onValueChange(r)}),onFocus:nr(e.onFocus,()=>{const g=c.activationMode!=="manual";!y&&!i&&g&&c.onValueChange(r)})})})});FN.displayName=BN;var zN="TabsContent",$N=Ne.forwardRef((e,t)=>{const{__scopeTabs:n,value:r,forceMount:i,children:s,...c}=e,a=uS(zN,n),d=VN(a.baseId,r),p=GN(a.baseId,r),y=r===a.value,g=Ne.useRef(y);return Ne.useEffect(()=>{const b=requestAnimationFrame(()=>g.current=!1);return()=>cancelAnimationFrame(b)},[]),K.jsx(Fs,{present:i||y,children:({present:b})=>K.jsx(Ar.div,{"data-state":y?"active":"inactive","data-orientation":a.orientation,role:"tabpanel","aria-labelledby":d,hidden:!b,id:p,tabIndex:0,...c,ref:t,style:{...e.style,animationDuration:g.current?"0s":void 0},children:b&&s})})});$N.displayName=zN;function VN(e,t){return`${e}-trigger-${t}`}function GN(e,t){return`${e}-content-${t}`}var kSe=NN,WN=jN,UN=FN,HN=$N;const DSe=kSe,XN=Ne.forwardRef(({className:e,...t},n)=>K.jsx(WN,{ref:n,className:Nn("inline-flex h-10 items-center justify-center rounded-md bg-muted p-1 text-muted-foreground",e),...t}));XN.displayName=WN.displayName;const hS=Ne.forwardRef(({className:e,...t},n)=>K.jsx(UN,{ref:n,className:Nn("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}));hS.displayName=UN.displayName;const ZN=Ne.forwardRef(({className:e,...t},n)=>K.jsx(HN,{ref:n,className:Nn("mt-2 ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",e),...t}));ZN.displayName=HN.displayName;function YN({value:e,children:t}){return K.jsx(ZN,{value:e,children:t})}tn.arrayOf(tn.shape({id:tn.string.isRequired,title:tn.string.isRequired,icon:tn.node,content:tn.node.isRequired,tooltipText:tn.string})).isRequired,tn.string.isRequired,tn.func,tn.func;function LSe(e){return vc({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 NSe(){const{mapRef:e}=H.useContext(ii),t=rn(b=>b.pickerData),n=rn(b=>b.setPickerData),r=rn(b=>b.rasterLayer),[i,s]=H.useState(null),{dateRange:c}=H.useContext(Mf),[a,d]=H.useState(!1),[p,y]=H.useState(null);function g(b){d(!0),s(null);const w=t.coordinates,S=e.current.getMap(),C=S.getBounds(),M=S.project(w),O=S.getCanvas(),T={width:O.width,height:O.height},D=[C.getWest(),C.getSouth(),C.getEast(),C.getNorth()].join(","),N="https://d27s6pvwcjpmsu.cloudfront.net/geoserver/ne/wms",k=new URLSearchParams({service:"WMS",version:"1.1.1",request:"GetFeatureInfo",layers:"ne:et_data",query_layers:"ne:et_data",bbox:D,width:T.width,height:T.height,srs:"EPSG:4326",time:c.start.toISOString().split("T")[0],info_format:"application/json",x:Math.floor(M.x),y:Math.floor(M.y)}),L=`${N}?${k.toString()}`;return fetch(L).then(B=>{if(!B.ok)throw new Error(`HTTP error! status: ${B.status}`);return console.log("response is",B),B.json()}).then(B=>{var q,re,ie,$,Y;console.log("Received coverage data for point:",w),console.log("Data:",B,typeof B),((q=B==null?void 0:B.features)==null?void 0:q.length)>0&&(console.log((ie=(re=B==null?void 0:B.features[0])==null?void 0:re.properties)==null?void 0:ie.GRAY_INDEX),s((Y=($=B==null?void 0:B.features[0])==null?void 0:$.properties)==null?void 0:Y.GRAY_INDEX))}).catch(B=>(console.error("There was a problem with the fetch operation:",B.message),s("could not fetch data"),y("could not load ET value at point"),null)).finally(()=>{d(!1)})}return H.useEffect(()=>{t&&r.value==="ET"&&g()},[t,r,c]),t?K.jsx(K.Fragment,{children:K.jsx(To,{open:!0,setOpen:()=>n(null),title:"Area Details",headerClassName:"m-4",children:K.jsxs(DSe,{className:"flex flex-col w-full h-full overflow-y-hidden",defaultValue:"point",children:[K.jsxs(XN,{className:"grid w-full grid-cols-2","aria-label":"Manage your account",children:[K.jsxs(hS,{value:"point",tooltipText:"Point",children:[K.jsx(LSe,{className:"cursor-pointer"}),"  ",K.jsx("span",{children:"Point"})]}),(t==null?void 0:t.plot)&&K.jsxs(hS,{value:"plot",tooltipText:"Plot",children:[K.jsx(ESe,{className:"cursor-pointer"})," ",K.jsx("span",{children:"Plot"})]})]}),K.jsx("br",{}),K.jsxs(YN,{value:"point",children:[r.value==="3_NDVI"&&K.jsx(U2,{point:t.coordinates}),a?K.jsx(fs,{}):p?K.jsx("div",{className:"text-red ",children:"Could not load ET value"}):i&&K.jsxs("div",{className:"flex items-center justify-between w-full gap-2 rounded-md bg-zinc-100 dark:bg-zinc-800 p-2 ",children:[K.jsx("h4",{className:"scroll-m-20 text-xs font-medium tracking-tight",children:"ET value at this point"}),K.jsx("div",{className:"flex items-center space-x-2",children:K.jsx("span",{className:"text-xs text-gray-700 dark:text-gray-200 font-bold",children:i.toFixed(3)})})]})]}),(t==null?void 0:t.plot)&&K.jsx(YN,{value:"plot",children:K.jsx(U2,{plot:t.plot})})]})})}):null}(yR=rn.getState().configs)==null||yR.VITE_SENTINAL_HUB_WMTS_ID;function qN({layer:e,dateRange:t}){var a;const r=`https://services.sentinel-hub.com/ogc/wmts/${(a=rn.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=Zm.find(d=>d.value===e);return s&&(s!=null&&s.url)?`${s.url}&TIME=${i}`:`${r}&LAYER=${e}&TIME=${i}`}const RSe=()=>{const{dateRange:e,isVisible:t}=H.useContext(Mf),n=rn(b=>b.showCroppedImages),r=rn(b=>b.rasterLayer),[i,s]=H.useState(qN({layer:r.value,dateRange:{...e}})),[c,a]=H.useState(null),d=rn(b=>b.rasterOpacity),{current:p}=Tu(),y=p.getMap();H.useEffect(()=>{console.log("dateRange in useEffect layerUrl",e);const b=qN({layer:r.value,dateRange:{...e}});s(b)},[r,e]),H.useEffect(()=>{p&&(p!=null&&p.loaded())&&p.getLayer("plots-line-layer")?a("plots-line-layer"):a(null)},[p]);const g=H.useCallback(b=>{if(console.log("handleLayerOrder"),y.getLayer("plots-line-layer")&&y.getLayer("raster-layer")){const w=y.getLayersOrder();w.indexOf("plots-line-layer")<w.indexOf("raster-layer")&&(console.log("reordering layers"),y.moveLayer("raster-layer","plots-line-layer"))}},[p]);return H.useEffect(()=>(y&&y.on("styledata",g),()=>{y&&y.off("styledata",g)}),[p]),!t||!i||n?null:K.jsxs(K.Fragment,{children:[K.jsx(pM,{id:"raster-source",type:"raster",tiles:[i],tileSize:256,minzoom:10,maxzoom:21,children:K.jsx(Hb,{id:"raster-layer",type:"raster",source:"raster-source",paint:{"raster-opacity":d/100},beforeId:c||void 0})}),K.jsx(NSe,{})]})},jSe=[{color:"#004400",label:" (0.5 to 1.0)"},{color:"#0f540a",label:" (0.4 to 0.5)"},{color:"#216011",label:" (0.35 to 0.4)"},{color:"#306d1c",label:" (0.3 to 0.35)"},{color:"#3f7c23",label:" (0.25 to 0.3)"},{color:"#4f892d",label:" (0.2 to 0.25)"},{color:"#609635",label:" (0.15 to 0.2)"},{color:"#70a33f",label:" (0.1 to 0.15)"},{color:"#7fb247",label:" (0.05 to 0.1)"},{color:"#91bf51",label:" (0.025 to 0.05)"},{color:"#a3cc59",label:" (0.0 to 0.025)"},{color:"#bcb76b",label:" (-0.1 to 0.0)"},{color:"#ccc682",label:" (-0.2 to -0.1)"},{color:"#ddd89b",label:" (-0.25 to -0.2)"},{color:"#ede8b5",label:" (-0.3 to -0.25)"},{color:"#fff9cc",label:" (-0.35 to -0.3)"},{color:"#eaeaea",label:" (-0.4 to -0.35)"},{color:"#dbdbdb",label:" (-0.5 to -0.4)"},{color:"#bfbfbf",label:" (-0.6 to -0.5)"},{color:"#c0c0c0",label:" (-0.7 to -0.6)"},{color:"#0c0c0c",label:" (-1.0 to -0.7)"}],BSe=[{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"}],FSe=[{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"}],zSe=[{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"}],$Se=[{color:"#00008B",label:"Very Low (0.001)"},{color:"#0000FF",label:"Low (3)"},{color:"#00FF00",label:"Moderate (6)"},{color:"#FFA500",label:"High (9)"},{color:"#FF0000",label:"Very High (12)"}],VSe=()=>{const e=rn(i=>i.rasterLayer),t=rn(i=>i.pixelColor);console.log("colorLegend rasterLayer",e);let n;switch(e==null?void 0:e.value){case"3_NDVI":n=jSe;break;case"AGRICULTURE":n=BSe;break;case"2_FALSE_COLOR":n=FSe;break;case"5-MOISTURE-INDEX1":n=zSe;break;case"ET":n=$Se}if(!n)return null;const r=n.find(i=>i.color==t);return console.log("item",r),K.jsxs("div",{className:"legend",children:[K.jsx("h4",{children:e==null?void 0:e.value}),n.map((i,s)=>K.jsxs("div",{className:"legend-item",children:[K.jsx("span",{className:"legend-color",style:{backgroundColor:i.color}}),K.jsx("span",{children:i.label})]},s))]})};function JN(e){const[t,n,r]=e,i=Math.round(t).toString(16).padStart(2,"0"),s=Math.round(n).toString(16).padStart(2,"0"),c=Math.round(r).toString(16).padStart(2,"0");return`#${i}${s}${c}`}function GSe(e,t){return e==="NDVI_RAW"?{label:"NDVI",value:(t[1]/127.5-1).toFixed(2),color:JN(t)}:{label:"color",value:null,color:JN(t)}}function WSe(){const{current:e}=Tu(),t=e.getMap();H.useRef(null);const n=rn(M=>M.viewMode),r=rn(M=>M.toggleNormalPickerMode),i=rn(M=>M.toNormalMode),s=rn(M=>M.setPickerData),c=rn(M=>M.setCursorCords),a=rn(M=>M.setHoveredValue),d=rn(M=>M.rasterLayer),p=rn(M=>M.setCursor),y=rn(M=>M.resetCursor),g=rn(M=>M.rasterOpacity),b=rn(M=>M.setRasterOpacity),w=H.useCallback(()=>{console.log("back to currentOpacity",g),b(100)},[g,b]),S=M=>{t&&(n==="PICKER"?t.setPaintProperty("raster-layer","raster-opacity",1):w()),r()};H.useEffect(()=>{const M=O=>{O.key==="Escape"&&(w(),i())};return n==="PICKER"&&window.addEventListener("keydown",M),()=>{window.removeEventListener("keydown",M)}},[i,g,t,w,n]);const C=H.useCallback(M=>{let O={coordinates:M.lngLat};if(t.getLayer("plots-layer")){const T=t.queryRenderedFeatures(M.point,{layers:["plots-layer"]});T.length>0&&(O.plot=T[0])}console.log("setting picker data",O),s(O)},[t,s]);return H.useEffect(()=>(t&&n==="PICKER"&&t.on("click",C),()=>{t&&t.off("click",C)}),[t,n,s]),H.useEffect(()=>{const M=O=>{const{lng:T,lat:D}=O.lngLat;c([T,D])};return t&&t.on("mousemove",M),()=>{t&&t.off("mousemove",M)}},[t,c,n]),H.useEffect(()=>{const O=cy(T=>{const D=t.getCanvas(),N=t.painter.context.gl;if(!N){console.error("WebGL context is not available.");return}const k=new Uint8Array(4),L=window.devicePixelRatio||1,B=Math.floor(T.point.x*L),q=Math.floor(D.height-T.point.y*L);if(B<0||q<0||B>=D.width||q>=D.height){console.warn("Mouse is outside the canvas bounds");return}N.readPixels(B,q,1,1,N.RGBA,N.UNSIGNED_BYTE,k);const re=GSe(d==null?void 0:d.value,k);a(re)},100);return t&&n==="PICKER"&&(t!=null&&t.loaded)&&(console.log("Adding pixel event listener"),t.on("mousemove",O)),()=>{t&&t.off("mousemove",O)}},[t,n,a,d]),H.useEffect(()=>{n==="PICKER"?p("crosshair"):y()},[n]),K.jsx(Vn,{variant:"outline",size:"icon",title:"Activate picker mode","aria-label":"Activate picker mode",onClick:S,className:` ${n===Hn.PICKER?" bg-gray-200 dark:bg-gray-600":""}`,children:K.jsx(AF,{})})}function USe(){const{current:e}=Tu(),[t,n]=H.useState(!1);H.useRef(null);const{settings:r,setSettings:i}=H.useContext(Gd),[s,c]=H.useState(!1),a=rn(g=>g.setViewMode),d=rn(g=>g.viewMode),p=H.useCallback(()=>{n(g=>!g),i(g=>({...g,basemap:{...g.basemap,id:g.basemap.id==="basic"?"satellite":"basic"}}))},[i]),y=H.useCallback(()=>{if(!e)return;const g=e.getContainer();console.log("mapContainer",g),document.fullscreenElement?(document.exitFullscreen(),c(!1)):g.requestFullscreen?g.requestFullscreen():g.mozRequestFullScreen?g.mozRequestFullScreen():g.webkitRequestFullscreen?g.webkitRequestFullscreen():g.msRequestFullscreen&&g.msRequestFullscreen(),c(!0)},[e]);return d===Hn.ADD_PLOT||d===Hn.ADD_MARKER||d===Hn.EDIT_PLOT||d===Hn.EDIT_MARKER?null:K.jsx(K.Fragment,{children:K.jsxs("div",{className:" gap-1 flex flex-col",children:[e&&K.jsx(Vn,{variant:"outline",size:"icon","aria-label":"Change view mode",title:"Change view mode",onClick:p,children:r.basemap.id==="basic"?K.jsx(EF,{}):K.jsx(xF,{})}),K.jsx(Vn,{variant:"outline",size:"icon",onClick:y,children:s?K.jsx(wF,{}):K.jsx(_F,{})}),K.jsx(WSe,{}),K.jsx(Vn,{variant:"outline",size:"icon",title:"add new plot",onClick:()=>a(Hn.ADD_PLOT),children:K.jsx(bF,{})}),K.jsx(Vn,{variant:"outline",size:"icon",title:"add new station",onClick:()=>a(Hn.ADD_MARKER),children:K.jsx(MF,{})}),K.jsx(Vn,{variant:"outline",size:"icon",title:"add new farm",onClick:()=>a(d===Hn.ADD_NEW_FARM?Hn.NORMAL:Hn.ADD_NEW_FARM),children:K.jsx(TF,{})})]})})}const dS=768;function HSe(){const[e,t]=Ne.useState(void 0);return Ne.useEffect(()=>{const n=window.matchMedia(`(max-width: ${dS-1}px)`),r=()=>{t(window.innerWidth<dS)};return n.addEventListener("change",r),t(window.innerWidth<dS),()=>n.removeEventListener("change",r)},[]),!!e}const KN=Ne.forwardRef(({className:e,type:t,...n},r)=>K.jsx("input",{type:t,className:Nn("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:r,...n}));KN.displayName="Input";var XSe="Separator",QN="horizontal",ZSe=["horizontal","vertical"],eR=Ne.forwardRef((e,t)=>{const{decorative:n,orientation:r=QN,...i}=e,s=YSe(r)?r:QN,a=n?{role:"none"}:{"aria-orientation":s==="vertical"?s:void 0,role:"separator"};return K.jsx(Ar.div,{"data-orientation":s,...a,...i,ref:t})});eR.displayName=XSe;function YSe(e){return ZSe.includes(e)}var tR=eR;const nR=Ne.forwardRef(({className:e,orientation:t="horizontal",decorative:n=!0,...r},i)=>K.jsx(tR,{ref:i,decorative:n,orientation:t,className:Nn("shrink-0 bg-border",t==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",e),...r}));nR.displayName=tR.displayName;const qSe=d1,JSe=f1,rR=Ne.forwardRef(({className:e,...t},n)=>K.jsx(Wg,{className:Nn("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:n}));rR.displayName=Wg.displayName;const KSe=qx("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"}}),iR=Ne.forwardRef(({side:e="right",className:t,children:n,...r},i)=>K.jsxs(JSe,{children:[K.jsx(rR,{}),K.jsxs(Ug,{ref:i,className:Nn(KSe({side:e}),t),...r,children:[n,K.jsxs(p1,{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:[K.jsx(ml,{className:"h-4 w-4"}),K.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));iR.displayName=Ug.displayName;const QSe=Ne.forwardRef(({className:e,...t},n)=>K.jsx(Hg,{ref:n,className:Nn("text-lg font-semibold text-foreground",e),...t}));QSe.displayName=Hg.displayName;const eCe=Ne.forwardRef(({className:e,...t},n)=>K.jsx(Xg,{ref:n,className:Nn("text-sm text-muted-foreground",e),...t}));eCe.displayName=Xg.displayName;function aR({className:e,...t}){return K.jsx("div",{className:Nn("animate-pulse rounded-md bg-muted",e),...t})}const tCe=EA,nCe=TA,rCe=IA,sR=Ne.forwardRef(({className:e,sideOffset:t=4,...n},r)=>K.jsx(bx,{ref:r,sideOffset:t,className:Nn("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),...n}));sR.displayName=bx.displayName;const iCe="sidebar:state",aCe=60*60*24*7,sCe="16rem",oCe="18rem",lCe="3rem",cCe="b",oR=Ne.createContext(null);function y0(){const e=Ne.useContext(oR);if(!e)throw new Error("useSidebar must be used within a SidebarProvider.");return e}const lR=Ne.forwardRef(({defaultOpen:e=!0,open:t,onOpenChange:n,className:r,style:i,children:s,...c},a)=>{const d=HSe(),[p,y]=Ne.useState(!1),[g,b]=Ne.useState(e),w=t??g,S=Ne.useCallback(T=>{const D=typeof T=="function"?T(w):T;n?n(D):b(D),document.cookie=`${iCe}=${D}; path=/; max-age=${aCe}`},[n,w]),C=Ne.useCallback(()=>d?y(T=>!T):S(T=>!T),[d,S,y]);Ne.useEffect(()=>{const T=D=>{D.key===cCe&&(D.metaKey||D.ctrlKey)&&(D.preventDefault(),C())};return window.addEventListener("keydown",T),()=>window.removeEventListener("keydown",T)},[C]);const M=w?"expanded":"collapsed",O=Ne.useMemo(()=>({state:M,open:w,setOpen:S,isMobile:d,openMobile:p,setOpenMobile:y,toggleSidebar:C}),[M,w,S,d,p,y,C]);return K.jsx(oR.Provider,{value:O,children:K.jsx(tCe,{delayDuration:0,children:K.jsx("div",{style:{"--sidebar-width":sCe,"--sidebar-width-icon":lCe,...i},className:Nn("group/sidebar-wrapper flex min-h-svh w-full has-[[data-variant=inset]]:bg-sidebar",r),ref:a,...c,children:s})})})});lR.displayName="SidebarProvider";const uCe=Ne.forwardRef(({side:e="left",variant:t="sidebar",collapsible:n="offcanvas",className:r,children:i,...s},c)=>{const{isMobile:a,state:d,openMobile:p,setOpenMobile:y}=y0();return n==="none"?K.jsx("div",{className:Nn("flex w-[--sidebar-width] flex-col bg-sidebar text-sidebar-foreground",r),ref:c,...s,children:i}):a?K.jsx(qSe,{open:p,onOpenChange:y,...s,children:K.jsx(iR,{"data-sidebar":"sidebar","data-mobile":"true",className:"w-[--sidebar-width] bg-sidebar p-0 text-sidebar-foreground [&>button]:hidden",style:{"--sidebar-width":oCe},side:e,children:K.jsx("div",{className:"flex h-full w-full flex-col",children:i})})}):K.jsxs("div",{ref:c,className:"group peer hidden md:block text-sidebar-foreground","data-state":d,"data-collapsible":d==="collapsed"?n:"","data-variant":t,"data-side":e,children:[K.jsx("div",{className:Nn("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]")}),K.jsx("div",{className:Nn("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",r),...s,children:K.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})})]})});uCe.displayName="Sidebar";const hCe=Ne.forwardRef(({className:e,onClick:t,...n},r)=>{const{toggleSidebar:i}=y0();return K.jsxs(Vn,{ref:r,"data-sidebar":"trigger",variant:"ghost",size:"icon",className:Nn("h-7 w-7",e),onClick:s=>{t==null||t(s),i()},...n,children:[K.jsx(CF,{}),K.jsx("span",{className:"sr-only",children:"Toggle Sidebar"})]})});hCe.displayName="SidebarTrigger";const dCe=Ne.forwardRef(({className:e,...t},n)=>{const{toggleSidebar:r}=y0();return K.jsx("button",{ref:n,"data-sidebar":"rail","aria-label":"Toggle Sidebar",tabIndex:-1,onClick:r,title:"Toggle Sidebar",className:Nn("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})});dCe.displayName="SidebarRail";const fCe=Ne.forwardRef(({className:e,...t},n)=>K.jsx("main",{ref:n,className:Nn("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}));fCe.displayName="SidebarInset";const pCe=Ne.forwardRef(({className:e,...t},n)=>K.jsx(KN,{ref:n,"data-sidebar":"input",className:Nn("h-8 w-full bg-background shadow-none focus-visible:ring-2 focus-visible:ring-sidebar-ring",e),...t}));pCe.displayName="SidebarInput";const mCe=Ne.forwardRef(({className:e,...t},n)=>K.jsx("div",{ref:n,"data-sidebar":"header",className:Nn("flex flex-col gap-2 p-2",e),...t}));mCe.displayName="SidebarHeader";const gCe=Ne.forwardRef(({className:e,...t},n)=>K.jsx("div",{ref:n,"data-sidebar":"footer",className:Nn("flex flex-col gap-2 p-2",e),...t}));gCe.displayName="SidebarFooter";const yCe=Ne.forwardRef(({className:e,...t},n)=>K.jsx(nR,{ref:n,"data-sidebar":"separator",className:Nn("mx-2 w-auto bg-sidebar-border",e),...t}));yCe.displayName="SidebarSeparator";const vCe=Ne.forwardRef(({className:e,...t},n)=>K.jsx("div",{ref:n,"data-sidebar":"content",className:Nn("flex min-h-0 flex-1 flex-col gap-2 overflow-auto group-data-[collapsible=icon]:overflow-hidden",e),...t}));vCe.displayName="SidebarContent";const bCe=Ne.forwardRef(({className:e,...t},n)=>K.jsx("div",{ref:n,"data-sidebar":"group",className:Nn("relative flex w-full min-w-0 flex-col p-2",e),...t}));bCe.displayName="SidebarGroup";const xCe=Ne.forwardRef(({className:e,asChild:t=!1,...n},r)=>{const i=t?Ya:"div";return K.jsx(i,{ref:r,"data-sidebar":"group-label",className:Nn("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),...n})});xCe.displayName="SidebarGroupLabel";const _Ce=Ne.forwardRef(({className:e,asChild:t=!1,...n},r)=>{const i=t?Ya:"button";return K.jsx(i,{ref:r,"data-sidebar":"group-action",className:Nn("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),...n})});_Ce.displayName="SidebarGroupAction";const wCe=Ne.forwardRef(({className:e,...t},n)=>K.jsx("div",{ref:n,"data-sidebar":"group-content",className:Nn("w-full text-sm",e),...t}));wCe.displayName="SidebarGroupContent";const SCe=Ne.forwardRef(({className:e,...t},n)=>K.jsx("ul",{ref:n,"data-sidebar":"menu",className:Nn("flex w-full min-w-0 flex-col gap-1",e),...t}));SCe.displayName="SidebarMenu";const CCe=Ne.forwardRef(({className:e,...t},n)=>K.jsx("li",{ref:n,"data-sidebar":"menu-item",className:Nn("group/menu-item relative",e),...t}));CCe.displayName="SidebarMenuItem";const MCe=qx("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"}}),ACe=Ne.forwardRef(({asChild:e=!1,isActive:t=!1,variant:n="default",size:r="default",tooltip:i,className:s,...c},a)=>{const d=e?Ya:"button",{isMobile:p,state:y}=y0(),g=K.jsx(d,{ref:a,"data-sidebar":"menu-button","data-size":r,"data-active":t,className:Nn(MCe({variant:n,size:r}),s),...c});return i?(typeof i=="string"&&(i={children:i}),K.jsxs(nCe,{children:[K.jsx(rCe,{asChild:!0,children:g}),K.jsx(sR,{side:"right",align:"center",hidden:y!=="collapsed"||p,...i})]})):g});ACe.displayName="SidebarMenuButton";const ECe=Ne.forwardRef(({className:e,asChild:t=!1,showOnHover:n=!1,...r},i)=>{const s=t?Ya:"button";return K.jsx(s,{ref:i,"data-sidebar":"menu-action",className:Nn("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",n&&"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),...r})});ECe.displayName="SidebarMenuAction";const TCe=Ne.forwardRef(({className:e,...t},n)=>K.jsx("div",{ref:n,"data-sidebar":"menu-badge",className:Nn("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}));TCe.displayName="SidebarMenuBadge";const ICe=Ne.forwardRef(({className:e,showIcon:t=!1,...n},r)=>{const i=Ne.useMemo(()=>`${Math.floor(Math.random()*40)+50}%`,[]);return K.jsxs("div",{ref:r,"data-sidebar":"menu-skeleton",className:Nn("rounded-md h-8 flex gap-2 px-2 items-center",e),...n,children:[t&&K.jsx(aR,{className:"size-4 rounded-md","data-sidebar":"menu-skeleton-icon"}),K.jsx(aR,{className:"h-4 flex-1 max-w-[--skeleton-width]","data-sidebar":"menu-skeleton-text",style:{"--skeleton-width":i}})]})});ICe.displayName="SidebarMenuSkeleton";const PCe=Ne.forwardRef(({className:e,...t},n)=>K.jsx("ul",{ref:n,"data-sidebar":"menu-sub",className:Nn("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}));PCe.displayName="SidebarMenuSub";const OCe=Ne.forwardRef(({...e},t)=>K.jsx("li",{ref:t,...e}));OCe.displayName="SidebarMenuSubItem";const kCe=Ne.forwardRef(({asChild:e=!1,size:t="md",isActive:n,className:r,...i},s)=>{const c=e?Ya:"a";return K.jsx(c,{ref:s,"data-sidebar":"menu-sub-button","data-size":t,"data-active":n,className:Nn("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",r),...i})});kCe.displayName="SidebarMenuSubButton";function DCe(){const[e,t]=H.useState({}),n=rn(q=>q.setViewMode),r=rn(q=>q.viewMode),[i,s]=H.useState(),{editingPlot:c,handlePlotUpdate:a}=H.useContext(Po),[d,p]=H.useState(c==null?void 0:c.options),[y,g]=H.useState([]),{drawRef:b,showDrawActionPopup:w,setShowDrawActionPopup:S}=H.useContext(ii),C=b.current,{current:M}=Tu(),O=Jh.constants;O.classes.CONTROL_BASE="maplibregl-ctrl",O.classes.CONTROL_PREFIX="maplibregl-ctrl-",O.classes.CONTROL_GROUP="maplibregl-ctrl-group",H.useCallback(q=>{console.log("onCreate"),t(re=>{const ie={...re};for(const $ of q.features)ie[$.id]=$;return ie})},[]),H.useCallback(q=>{r in[Hn.EDIT_PLOT,Hn.EDIT_MARKER]&&n(Hn.NORMAL),t(re=>{const ie={...re};for(const $ of q.features)delete ie[$.id];return ie})},[]);const T=q=>{console.log("event features",q.features),console.log("editing plot",c),d&&a({...c,options:d}).then(()=>{console.log("mode",q.mode),C.deleteAll(),n(Hn.NORMAL)}).catch(re=>{console.error("error updating plot",re)})};H.useEffect(()=>{console.log("editingPlot changed",c)},[c]);const D=q=>{console.log("mode changed",q.mode),s(q.mode)},N=q=>{console.log("selection changed",q);const re=b.current.getSelected();g(re)},k=H.useCallback(q=>{console.log("handling draw change",q),q.features&&q.features.length>0?p(q.features[0]):p(null)},[c,a]),L=()=>{C.deleteAll(),n(Hn.NORMAL)},B=()=>{C.getSelectedIds(),C.trash()};return H.useEffect(()=>{const q=M.getMap();return q.on("draw.modechange",D),q.on("draw.selectionchange",N),()=>{q.off("draw.modechange",D),q.off("draw.selectionchange",N)}},[b]),H.useEffect(()=>{if(map&&C)return M.on("draw.update",k),()=>{M.off("draw.update",k)}},[M,C,k]),K.jsx(K.Fragment,{children:K.jsx("div",{className:"absolute top-0 right-0 m-2 ",children:K.jsxs("div",{className:" gap-1 flex flex-col",children:[K.jsx(Vn,{variant:"outline",size:"icon",onClick:L,children:K.jsx(ml,{})}),K.jsx(Vn,{variant:"outline",size:"icon",onClick:B,children:K.jsx(Zb,{})}),K.jsx(Vn,{variant:"outline",size:"icon",onClick:T,children:K.jsx(Xb,{})})]})})})}function LCe(){H.useState({});const e=rn(D=>D.setViewMode);rn(D=>D.viewMode);const[t,n]=H.useState(),[r,i]=H.useState({}),[s,c]=H.useState([]),{drawRef:a,showDrawActionPopup:d,setShowDrawActionPopup:p}=H.useContext(ii),y=a.current,{current:g}=Tu();H.useEffect(()=>{y.changeMode("draw_polygon")},[y]);const b=()=>{y&&y.delete(r.id),e(Hn.NORMAL)},w=D=>{console.log("mode changed",D.mode),n(D.mode)},S=D=>{console.log("selection changed",D);const N=a.current.getSelected();c(N)},C=D=>{console.log("delete event",D,y.getMode()),y.getAll().features.length===0&&y.getMode()==="simple_select"&&y.changeMode("draw_polygon")},M=H.useCallback(D=>{console.log("running plot shape change",D.features),console.log("handling draw change",D),D.features&&D.features.length>0&&i(D.features[0])},[]);H.useEffect(()=>{console.log("shape changed",r)},[r]);const O=()=>{y.deleteAll(),e(Hn.NORMAL)},T=()=>{y.getSelectedIds().length>0&&y.trash()};return H.useEffect(()=>{const D=g.getMap();return D.on("draw.modechange",w),D.on("draw.selectionchange",S),()=>{D.off("draw.modechange",w),D.off("draw.selectionchange",S)}},[a]),H.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]),K.jsx(K.Fragment,{children:K.jsx("div",{className:"absolute top-0 right-0 m-2 ",children:K.jsxs("div",{className:" gap-1 flex flex-col",children:[K.jsx(Vn,{variant:"outline",size:"icon",onClick:O,children:K.jsx(ml,{})}),K.jsx(Vn,{variant:"outline",size:"icon",onClick:T,children:K.jsx(Zb,{})}),K.jsx(MSe,{trigger:K.jsx(Vn,{variant:"outline",size:"icon",children:K.jsx(Xb,{})}),polygon:r,deleteFeature:b})]})})})}function NCe(){H.useState({});const e=rn(T=>T.setViewMode);rn(T=>T.viewMode);const[t,n]=H.useState(),[r,i]=H.useState({}),[s,c]=H.useState([]),{drawRef:a,showDrawActionPopup:d,setShowDrawActionPopup:p}=H.useContext(ii),y=a.current,{current:g}=Tu();H.useEffect(()=>{y.changeMode("draw_point")},[y]);const b=()=>{y&&y.delete(r.id),e(Hn.NORMAL)},w=T=>{console.log("mode changed",T.mode),n(T.mode)},S=T=>{console.log("selection changed",T);const D=a.current.getSelected();c(D)},C=H.useCallback(T=>{console.log("running plot shape change",T.features),console.log("handling draw change",T),T.features&&T.features.length>0&&i(T.features[0])},[]);H.useEffect(()=>{console.log("shape changed",r)},[r]);const M=()=>{y.deleteAll(),e(Hn.NORMAL)},O=()=>{y.getSelectedIds(),y.trash()};return H.useEffect(()=>{const T=g.getMap();return T.on("draw.modechange",w),T.on("draw.selectionchange",S),()=>{T.off("draw.modechange",w),T.off("draw.selectionchange",S)}},[a]),H.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]),K.jsx(K.Fragment,{children:K.jsx("div",{className:"absolute top-0 right-0 m-2 ",children:K.jsxs("div",{className:" gap-1 flex flex-col",children:[K.jsx(Vn,{variant:"outline",size:"icon",onClick:M,children:K.jsx(ml,{})}),K.jsx(Vn,{variant:"outline",size:"icon",onClick:O,children:K.jsx(Zb,{})}),K.jsx(ASe,{trigger:K.jsx(Vn,{variant:"outline",size:"icon",children:K.jsx(gs,{text:"add station",children:K.jsx(Xb,{})})}),feature:r,deleteFeature:b})]})})})}const RCe=()=>{var c;const[e,t]=H.useState(!0),{mapRef:n}=H.useContext(ii),r=rn(a=>a.setViewMode),i=()=>{console.log("closing modal"),r(Hn.NORMAL),t(!1)},s=a=>{wG(a.name,a.marker_set).then(d=>{console.log("farm created successfully"),Sc("Farm Has been created",{description:`name: ${a.name}`})}),i()};return K.jsx(To,{title:"Add New Farm",headerClassName:"m-4",open:e,setOpen:t,onChange:i,portalContainer:n!=null&&n.current?(c=n==null?void 0:n.current)==null?void 0:c.getMap().getContainer():document.body,children:K.jsx("div",{className:"h-[400px] overflow-y-auto",children:K.jsx(jCe,{onClose:i,onSubmit:s})})})};function jCe({onClose:e,onSubmit:t}){const n=H.useRef(),{markers:r,loading:i}=H.useContext(Ns),s=H.useMemo(()=>r.map(S=>({value:S.id,label:(S==null?void 0:S.name)||(S==null?void 0:S.title)||(S==null?void 0:S.label)})),[r]),[c,a]=H.useState(!1),[d,p]=H.useState(""),[y,g]=H.useState([]);let b=H.useMemo(()=>bc(y,s),[y,s]);const w=S=>{S.preventDefault(),t({name:d,marker_set:y})};return K.jsxs("form",{onSubmit:w,className:"p-4 flex flex-col h-full",ref:n,children:[K.jsx(Ri,{label:"Name:",children:K.jsx(Eo,{type:"text",name:"name",className:"w-full sm:max-w-[483px] max-w-[227px]",value:d,onChange:S=>p(S.target.value)})}),K.jsx(Ri,{label:"Markers:",children:K.jsx(Gs,{formRef:n,className:"w-full sm:max-w-[483px] max-w-[227px]",name:"marker_set",value:b,onChange:g,options:s,isMulti:!0,isClearable:!0,isLoading:i,isSearchable:!0,closeMenuOnSelect:!1})}),K.jsxs("div",{className:"mt-5 flex gap-2 mt-auto self-end",children:[K.jsx(Vn,{type:"cancel",variant:"outline",onClick:!c&&e,disabled:c,children:"Cancel"}),K.jsx(Vn,{type:"submit",color:"primary",children:"Add Farm"})]})]})}function BCe({style:e,requestHeaders:t,configs:n}){const{mapStyle:r,mapRef:i}=H.useContext(ii),s=PB(),c=rn(y=>y.viewMode),a=rn(y=>y.cursor),d=rn(y=>y.setRequestHeaders),p=rn(y=>y.setConfigs);return H.useEffect(()=>{d(t)},[t]),H.useEffect(()=>{p(n)},[]),s?K.jsx(lR,{children:K.jsx(gK,{children:K.jsxs(dF,{id:"myMap",ref:i,initialViewState:s,style:{width:"100%",height:"80vh",...e},mapStyle:typeof r=="string"?r:r.toJS(),attributionControl:!1,reuseMaps:!0,preserveDrawingBuffer:!0,cursor:a,children:[K.jsx(RSe,{}),K.jsx(BK,{}),K.jsx("div",{className:"absolute top-0 left-0"}),K.jsx("div",{className:"absolute top-0 right-0 m-2",style:{zIndex:2},children:K.jsx(USe,{})}),K.jsx(TSe,{}),c==Hn.EDIT_PLOT&&K.jsx(DCe,{}),c==Hn.ADD_PLOT&&K.jsx(LCe,{}),c==Hn.ADD_MARKER&&K.jsx(NCe,{}),c==Hn.ADD_NEW_FARM&&K.jsx(RCe,{}),K.jsx(L2e,{}),K.jsx(YK,{}),K.jsx(eQ,{}),K.jsx(G2e,{}),K.jsx(ISe,{}),c===Hn.PICKER&&K.jsx(VSe,{})]})})}):K.jsx(fs,{})}var FCe={},cR={};(function(e){function t(O){"@babel/helpers - typeof";return t=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},t(O)}Object.defineProperty(e,"__esModule",{value:!0}),e.default=void 0;var n=s(H),r=["dispose","reject","resolve"];function i(O){if(typeof WeakMap!="function")return null;var T=new WeakMap,D=new WeakMap;return(i=function(k){return k?D:T})(O)}function s(O,T){if(O&&O.__esModule)return O;if(O===null||t(O)!=="object"&&typeof O!="function")return{default:O};var D=i(T);if(D&&D.has(O))return D.get(O);var N={},k=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var L in O)if(L!=="default"&&Object.prototype.hasOwnProperty.call(O,L)){var B=k?Object.getOwnPropertyDescriptor(O,L):null;B&&(B.get||B.set)?Object.defineProperty(N,L,B):N[L]=O[L]}return N.default=O,D&&D.set(O,N),N}function c(){return c=Object.assign||function(O){for(var T=1;T<arguments.length;T++){var D=arguments[T];for(var N in D)Object.prototype.hasOwnProperty.call(D,N)&&(O[N]=D[N])}return O},c.apply(this,arguments)}function a(O,T){return b(O)||g(O,T)||p(O,T)||d()}function d(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
988
+ }`,H2={};async function B2e(e,{weeksBefore:t=0,accessToken:n,dateRange:r}){if(!n)return console.error("No access token provided"),null;r&&(r.start instanceof Date&&(r.start.setHours(0,0,0,0),r.start=r.start.toISOString()),r.end instanceof Date&&(r.end.setHours(23,59,59),r.end=r.end.toISOString())),r||(r={start:new Date(new Date().setDate(new Date().getDate()-t*7-14)).toISOString(),end:new Date(new Date().setDate(new Date().getDate()-t*7)).toISOString()});const i=`${e.properties.id}-${r.start}`;if(console.log("crop cacheKey",i),H2[i])return console.log("NDVI data found in cache"),H2[i];if(console.log("access Token",n),!BZ(sf(e)))throw new Error("Invalid BBOX");const c="https://services.sentinel-hub.com/api/v1/process",a={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:r.start,to:r.end}}}]},output:{width:512,height:512,responses:[{identifier:"default",format:{type:"image/png"}}]},evalscript:j2e};try{const d=await fetch(c,{method:"POST",headers:{Authorization:`Bearer ${n}`,"Content-Type":"application/json"},body:JSON.stringify(a)});if(!d.ok)throw new Error("Failed to fetch NDVI data");const p=await d.blob();if(!p)return null;const y=URL.createObjectURL(p);return H2[i]=y,y}catch(d){return console.error("Error fetching NDVI data:",d),null}}async function F2e(e,t){console.log("downloading cropped et",t),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 n=`${t.start}/${t.end}`,r=sf(e);if(!r)throw new Error("Invalid BBOX");const i=r.join(","),s="https://d27s6pvwcjpmsu.cloudfront.net/geoserver/ne/wms?"+new URLSearchParams({service:"WMS",version:"1.1.0",request:"GetMap",layers:"ne:et_data",styles:"",bbox:i,width:512,height:512,srs:"EPSG:4326",format:"image/png",transparent:"true",TIME:n});try{const c=await fetch(s);if(!c.ok)throw new Error("Failed to fetch cropped NDVI from GeoServer");const a=await c.blob();return a?URL.createObjectURL(a):null}catch(c){return console.error("Error fetching cropped NDVI:",c),null}}async function z2e(e,t){return new Promise(n=>{const r=new Image;r.onload=function(){const i=document.createElement("canvas"),s=i.getContext("2d");i.width=r.width,i.height=r.height,s.drawImage(r,0,0,r.width,r.height);const c=t.geometry.coordinates[0].map(([a,d])=>$2e(a,d,sf(t),r.width,r.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(),n(i.toDataURL("image/png"))},r.src=e})}function $2e(e,t,n,r,i){const[s,c,a,d]=n,p=(e-s)/(a-s)*r,y=i-(t-c)/(d-c)*i;return[p,y]}async function V2e(e,{rasterLayer:t,dateRange:n,accessToken:r,map:i}){if(console.log("getCroppedRaster rasterLayer",t),t==="ET"||(t==null?void 0:t.value)==="ET"){const s=await F2e(e,n);if(!s)return null;const c=await z2e(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 B2e(e,{accessToken:r,dateRange:n})}function G2e(){var X;const{plots:e,showPlots:t,clickedPlot:n,setClickedPlot:r,weeksBefore:i,showNdviLayer:s}=H.useContext(Po),c=rn(ne=>ne.showCroppedImages),a=rn(ne=>ne.rasterLayer),{isVisible:d,setIsVisible:p,dateRange:y}=H.useContext(Mf),{settings:g}=H.useContext(Gd),b=rn(ne=>ne.setCursor),w=rn(ne=>ne.resetCursor),{drawRef:S,mapRef:C}=H.useContext(ii),M=H.useContext(dy),O=(X=C==null?void 0:C.current)==null?void 0:X.getMap(),T=rn(ne=>ne.viewMode),D=rn(ne=>ne.addLoadingNDVIImage),N=rn(ne=>ne.removeLoadingNDVIImage),k=rn(ne=>ne.isNDVIImageLoading);rn(ne=>ne.setShowCroppedImages);const L=H.useCallback((ne,ae,{map:J})=>{if(console.log("crop adding image to map",ne,ae,J),!J)throw new Error("map is not defined");if(!c||(console.log("plotss",ae),!ae||!ae.geometry||ae.geometry.type!=="Polygon"))return null;const[pe,xe,se,ge]=sf(ae.geometry),Se=[[pe,ge],[se,ge],[se,xe],[pe,xe]],Ae=`croppedImageSource-${ae.properties.id}`,$e=`croppedImageLayer-${ae.properties.id}`;J.getLayer($e)&&J.removeLayer($e),J.getSource(Ae)&&J.removeSource(Ae),J.addSource(Ae,{type:"image",url:ne,coordinates:Se}),J.addLayer({id:$e,type:"raster",source:Ae,paint:{"raster-opacity":1}},"plots-line-layer")},[c]),B=H.useCallback(async(ne,{accessToken:ae,map:J,timeTravel:pe,dateRange:xe,isVisible:se,showCroppedImages:ge})=>{if(console.log("handleCroppedImageDownload started"),console.log("crop download plot",ne),!J)throw new Error("map is not defined");const Se=`croppedImageLayer-${ne.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(k(ne.properties.id))return;D(ne.properties.id);const Ae=await V2e(ne,{rasterLayer:a,dateRange:xe,accessToken:ae});if(!ne)throw new Error("plot is not defined");console.log("mapp",J),Ae&&(console.log(),L(Ae,ne,{map:J}))}catch(Ae){console.log("error in loading ndvi layer",Ae)}finally{N(ne.properties.id)}},[a,k,D,L,N]),q={id:"plots-line-layer",type:"line",paint:{"line-color":"#e31717","line-width":2}},re={id:"plots-layer",type:"fill",paint:{"fill-color":"#e31717","fill-opacity":0}},ie=H.useCallback(()=>{var J;const ne=(J=S==null?void 0:S.current)==null?void 0:J.getAll();return((ne==null?void 0:ne.features)||[]).length>0},[S]),$=H.useCallback(ne=>{if(ie()){console.log("no popup info"),r(null);return}const ae=O.queryRenderedFeatures(ne.point,{layers:["plots-layer"]});if(ae.length>0){const J=ae[0];console.log("clickedPlot",J),r({lngLat:ne.lngLat,plot:J})}else r(null)},[ie,O,r]),Y=H.useCallback(()=>{b("pointer")},[b,O]),G=H.useCallback(()=>{w()},[b,O]),j=H.useCallback((ne,ae)=>{const[J,pe,xe,se]=ne,[[ge,Se],[Ae,$e]]=ae.toArray();return!(J>Ae||xe<ge||pe>$e||se<Se)},[]),R=H.useCallback(({timeTravel:ne=!1})=>{if(console.log("handleViewportChange start"),!O||T!=="NORMAL"||O.getZoom()<10)return;const J=O.getBounds();e.forEach(pe=>{if(KI(pe.options))return;const xe=sf(pe.options);j(xe,J)&&B(pe.options,{dateRange:y,accessToken:M,map:O,timeTravel:ne,isVisible:d,showCroppedImages:c})}),console.log("handleViewportChange end")},[O,e,M,y,j,T,d,c,a]),Z=H.useMemo(()=>cy(R,500),[R]);return H.useEffect(()=>{console.log("dateRnage changed, crop"),R({timeTravel:!0})},[y,d,c,e,a,g]),H.useEffect(()=>(O&&t&&T!=="PICKER"&&O.on("click","plots-layer",$),()=>{O&&O.off("click","plots-layer",$)}),[$,T,t,O]),H.useEffect(()=>{if(console.log("running useEffect inside plots"),!(!O||T!=="NORMAL"||!t||!c))return console.log("adding viewport change event to map"),O.on("moveend",Z),O.on("zoomend",Z),()=>{console.log("removing viewport change event from map"),Z.cancel(),O.off("moveend",Z),O.off("zoomend",Z)}},[O,t,T,Z,c]),H.useEffect(()=>(O&&T!=="PICKER"&&(O.on("mouseenter","plots-layer",Y),O.on("mouseleave","plots-layer",G)),()=>{O&&T!=="PICKER"&&(O.off("mouseenter","plots-layer",Y),O.off("mouseleave","plots-layer",G))}),[O,Y,G,T]),t?K.jsxs(K.Fragment,{children:[K.jsxs(pM,{id:"plots",type:"geojson",data:{type:"FeatureCollection",features:e.map(ne=>ne==null?void 0:ne.options)},children:[K.jsx(Hb,{...q},"12kkd"),K.jsx(Hb,{...re},"12kmsn")]}),n&&T==Hn.NORMAL&&K.jsx(R2e,{popupInfo:n,onClose:()=>r(null)})]}):null}const X2=function(e,t){const n={drag:[],click:[],mousemove:[],mousedown:[],mouseup:[],mouseout:[],keydown:[],keyup:[],touchstart:[],touchmove:[],touchend:[],tap:[]},r={on(s,c,a){if(n[s]===void 0)throw new Error(`Invalid event type: ${s}`);n[s].push({selector:c,fn:a})},render(s){t.store.featureChanged(s)}},i=function(s,c){const a=n[s];let d=a.length;for(;d--;){const p=a[d];if(p.selector(c)){p.fn.call(r,c)||t.store.render(),t.ui.updateMapClasses();break}}};return e.start.call(r),{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 Z2={},a0={};a0.RADIUS=6378137,a0.FLATTENING=1/298.257223563,a0.POLAR_RADIUS=63567523142e-4;var uN=a0;Z2.geometry=hN,Z2.ring=Y2;function hN(e){var t=0,n;switch(e.type){case"Polygon":return dN(e.coordinates);case"MultiPolygon":for(n=0;n<e.coordinates.length;n++)t+=dN(e.coordinates[n]);return t;case"Point":case"MultiPoint":case"LineString":case"MultiLineString":return 0;case"GeometryCollection":for(n=0;n<e.geometries.length;n++)t+=hN(e.geometries[n]);return t}}function dN(e){var t=0;if(e&&e.length>0){t+=Math.abs(Y2(e[0]));for(var n=1;n<e.length;n++)t-=Math.abs(Y2(e[n]))}return t}function Y2(e){var t,n,r,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],n=e[s],r=e[c],d+=(q2(r[0])-q2(t[0]))*Math.sin(q2(n[1]));d=d*uN.RADIUS*uN.RADIUS/2}return d}function q2(e){return e*Math.PI/180}const xa={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"},ss={HOT:"mapbox-gl-draw-hot",COLD:"mapbox-gl-draw-cold"},Fr={ADD:"add",MOVE:"move",DRAG:"drag",POINTER:"pointer",NONE:"none"},_a={POLYGON:"polygon",LINE:"line_string",POINT:"point"},yn={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"},Gn={DRAW_LINE_STRING:"draw_line_string",DRAW_POLYGON:"draw_polygon",DRAW_POINT:"draw_point",SIMPLE_SELECT:"simple_select",DIRECT_SELECT:"direct_select"},ta={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"},Fp={MOVE:"move",CHANGE_PROPERTIES:"change_properties",CHANGE_COORDINATES:"change_coordinates"},Bi={FEATURE:"feature",MIDPOINT:"midpoint",VERTEX:"vertex"},fi={ACTIVE:"true",INACTIVE:"false"},fN=["scrollZoom","boxZoom","dragRotate","dragPan","keyboard","doubleClickZoom","touchZoomRotate"],W2e=-90,J2=-85,U2e=90,K2=85,pN=Object.freeze(Object.defineProperty({__proto__:null,LAT_MAX:U2e,LAT_MIN:W2e,LAT_RENDERED_MAX:K2,LAT_RENDERED_MIN:J2,LNG_MAX:270,LNG_MIN:-270,activeStates:fi,classes:xa,cursors:Fr,events:ta,geojsonTypes:yn,interactions:fN,meta:Bi,modes:Gn,sources:ss,types:_a,updateActions:Fp},Symbol.toStringTag,{value:"Module"})),mN={Point:0,LineString:1,MultiLineString:1,Polygon:2};function H2e(e,t){const n=mN[e.geometry.type]-mN[t.geometry.type];return n===0&&e.geometry.type===yn.POLYGON?e.area-t.area:n}function gN(e){return e.map(t=>(t.geometry.type===yn.POLYGON&&(t.area=Z2.geometry({type:yn.FEATURE,property:{},geometry:t.geometry})),t)).sort(H2e).map(t=>(delete t.area,t))}function yN(e,t=0){return[[e.point.x-t,e.point.y-t],[e.point.x+t,e.point.y+t]]}function os(e){if(this._items={},this._nums={},this._length=e?e.length:0,!!e)for(let t=0,n=e.length;t<n;t++)this.add(e[t]),e[t]!==void 0&&(typeof e[t]=="string"?this._items[e[t]]=t:this._nums[e[t]]=t)}os.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)},os.prototype.delete=function(e){return this.has(e)===!1?this:(this._length--,delete this._items[e],delete this._nums[e],this)},os.prototype.has=function(e){return typeof e!="string"&&typeof e!="number"?!1:this._items[e]!==void 0||this._nums[e]!==void 0},os.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,n)=>t.v-n.v).map(t=>t.k)},os.prototype.clear=function(){return this._length=0,this._items={},this._nums={},this};const X2e=[Bi.FEATURE,Bi.MIDPOINT,Bi.VERTEX],Yh={click:Z2e,touch:Y2e};function Z2e(e,t,n){return vN(e,t,n,n.options.clickBuffer)}function Y2e(e,t,n){return vN(e,t,n,n.options.touchBuffer)}function vN(e,t,n,r){if(n.map===null)return[];const i=e?yN(e,r):t,s={};n.options.styles&&(s.layers=n.options.styles.map(p=>p.id).filter(p=>n.map.getLayer(p)!=null));const c=n.map.queryRenderedFeatures(i,s).filter(p=>X2e.indexOf(p.properties.meta)!==-1),a=new os,d=[];return c.forEach(p=>{const y=p.properties.id;a.has(y)||(a.add(y),d.push(p))}),gN(d)}function s0(e,t){const n=Yh.click(e,null,t),r={mouse:Fr.NONE};return n[0]&&(r.mouse=n[0].properties.active===fi.ACTIVE?Fr.MOVE:Fr.POINTER,r.feature=n[0].properties.meta),t.events.currentModeName().indexOf("draw")!==-1&&(r.mouse=Fr.ADD),t.ui.queueMapClasses(r),t.ui.updateMapClasses(),n[0]}function Q2(e,t){const n=e.x-t.x,r=e.y-t.y;return Math.sqrt(n*n+r*r)}const q2e=4,J2e=12,K2e=500;function eS(e,t,n={}){const r=n.fineTolerance!=null?n.fineTolerance:q2e,i=n.grossTolerance!=null?n.grossTolerance:J2e,s=n.interval!=null?n.interval:K2e;e.point=e.point||t.point,e.time=e.time||t.time;const c=Q2(e.point,t.point);return c<r||c<i&&t.time-e.time<s}const Q2e=25,eSe=250;function tS(e,t,n={}){const r=n.tolerance!=null?n.tolerance:Q2e,i=n.interval!=null?n.interval:eSe;return e.point=e.point||t.point,e.time=e.time||t.time,Q2(e.point,t.point)<r&&t.time-e.time<i}const tSe=((e,t=21)=>(n=t)=>{let r="",i=n|0;for(;i--;)r+=e[Math.random()*e.length|0];return r})("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",32);function nS(){return tSe()}const na=function(e,t){this.ctx=e,this.properties=t.properties||{},this.coordinates=t.geometry.coordinates,this.id=t.id||nS(),this.type=t.geometry.type};na.prototype.changed=function(){this.ctx.store.featureChanged(this.id)},na.prototype.incomingCoords=function(e){this.setCoordinates(e)},na.prototype.setCoordinates=function(e){this.coordinates=e,this.changed()},na.prototype.getCoordinates=function(){return JSON.parse(JSON.stringify(this.coordinates))},na.prototype.setProperty=function(e,t){this.properties[e]=t},na.prototype.toGeoJSON=function(){return JSON.parse(JSON.stringify({id:this.id,type:yn.FEATURE,properties:this.properties,geometry:{coordinates:this.getCoordinates(),type:this.type}}))},na.prototype.internal=function(e){const t={id:this.id,meta:Bi.FEATURE,"meta:type":this.type,active:fi.INACTIVE,mode:e};if(this.ctx.options.userProperties)for(const n in this.properties)t[`user_${n}`]=this.properties[n];return{type:yn.FEATURE,properties:t,geometry:{coordinates:this.getCoordinates(),type:this.type}}};const Fl=function(e,t){na.call(this,e,t)};Fl.prototype=Object.create(na.prototype),Fl.prototype.isValid=function(){return typeof this.coordinates[0]=="number"&&typeof this.coordinates[1]=="number"},Fl.prototype.updateCoordinate=function(e,t,n){arguments.length===3?this.coordinates=[t,n]:this.coordinates=[e,t],this.changed()},Fl.prototype.getCoordinate=function(){return this.getCoordinates()};const io=function(e,t){na.call(this,e,t)};io.prototype=Object.create(na.prototype),io.prototype.isValid=function(){return this.coordinates.length>1},io.prototype.addCoordinate=function(e,t,n){this.changed();const r=parseInt(e,10);this.coordinates.splice(r,0,[t,n])},io.prototype.getCoordinate=function(e){const t=parseInt(e,10);return JSON.parse(JSON.stringify(this.coordinates[t]))},io.prototype.removeCoordinate=function(e){this.changed(),this.coordinates.splice(parseInt(e,10),1)},io.prototype.updateCoordinate=function(e,t,n){const r=parseInt(e,10);this.coordinates[r]=[t,n],this.changed()};const Da=function(e,t){na.call(this,e,t),this.coordinates=this.coordinates.map(n=>n.slice(0,-1))};Da.prototype=Object.create(na.prototype),Da.prototype.isValid=function(){return this.coordinates.length===0?!1:this.coordinates.every(e=>e.length>2)},Da.prototype.incomingCoords=function(e){this.coordinates=e.map(t=>t.slice(0,-1)),this.changed()},Da.prototype.setCoordinates=function(e){this.coordinates=e,this.changed()},Da.prototype.addCoordinate=function(e,t,n){this.changed();const r=e.split(".").map(s=>parseInt(s,10));this.coordinates[r[0]].splice(r[1],0,[t,n])},Da.prototype.removeCoordinate=function(e){this.changed();const t=e.split(".").map(r=>parseInt(r,10)),n=this.coordinates[t[0]];n&&(n.splice(t[1],1),n.length<3&&this.coordinates.splice(t[0],1))},Da.prototype.getCoordinate=function(e){const t=e.split(".").map(r=>parseInt(r,10)),n=this.coordinates[t[0]];return JSON.parse(JSON.stringify(n[t[1]]))},Da.prototype.getCoordinates=function(){return this.coordinates.map(e=>e.concat([e[0]]))},Da.prototype.updateCoordinate=function(e,t,n){this.changed();const r=e.split("."),i=parseInt(r[0],10),s=parseInt(r[1],10);this.coordinates[i]===void 0&&(this.coordinates[i]=[]),this.coordinates[i][s]=[t,n]};const nSe={MultiPoint:Fl,MultiLineString:io,MultiPolygon:Da},o0=(e,t,n,r,i)=>{const s=n.split("."),c=parseInt(s[0],10),a=s[1]?s.slice(1).join("."):null;return e[c][t](a,r,i)},ra=function(e,t){if(na.call(this,e,t),delete this.coordinates,this.model=nSe[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)};ra.prototype=Object.create(na.prototype),ra.prototype._coordinatesToFeatures=function(e){const t=this.model.bind(this);return e.map(n=>new t(this.ctx,{id:nS(),type:yn.FEATURE,properties:{},geometry:{coordinates:n,type:this.type.replace("Multi","")}}))},ra.prototype.isValid=function(){return this.features.every(e=>e.isValid())},ra.prototype.setCoordinates=function(e){this.features=this._coordinatesToFeatures(e),this.changed()},ra.prototype.getCoordinate=function(e){return o0(this.features,"getCoordinate",e)},ra.prototype.getCoordinates=function(){return JSON.parse(JSON.stringify(this.features.map(e=>e.type===yn.POLYGON?e.getCoordinates():e.coordinates)))},ra.prototype.updateCoordinate=function(e,t,n){o0(this.features,"updateCoordinate",e,t,n),this.changed()},ra.prototype.addCoordinate=function(e,t,n){o0(this.features,"addCoordinate",e,t,n),this.changed()},ra.prototype.removeCoordinate=function(e){o0(this.features,"removeCoordinate",e),this.changed()},ra.prototype.getFeatures=function(){return this.features};function zn(e){this.map=e.map,this.drawConfig=JSON.parse(JSON.stringify(e.options||{})),this._ctx=e}zn.prototype.setSelected=function(e){return this._ctx.store.setSelected(e)},zn.prototype.setSelectedCoordinates=function(e){this._ctx.store.setSelectedCoordinates(e),e.reduce((t,n)=>(t[n.feature_id]===void 0&&(t[n.feature_id]=!0,this._ctx.store.get(n.feature_id).changed()),t),{})},zn.prototype.getSelected=function(){return this._ctx.store.getSelected()},zn.prototype.getSelectedIds=function(){return this._ctx.store.getSelectedIds()},zn.prototype.isSelected=function(e){return this._ctx.store.isSelected(e)},zn.prototype.getFeature=function(e){return this._ctx.store.get(e)},zn.prototype.select=function(e){return this._ctx.store.select(e)},zn.prototype.deselect=function(e){return this._ctx.store.deselect(e)},zn.prototype.deleteFeature=function(e,t={}){return this._ctx.store.delete(e,t)},zn.prototype.addFeature=function(e,t={}){return this._ctx.store.add(e,t)},zn.prototype.clearSelectedFeatures=function(){return this._ctx.store.clearSelected()},zn.prototype.clearSelectedCoordinates=function(){return this._ctx.store.clearSelectedCoordinates()},zn.prototype.setActionableState=function(e={}){const t={trash:e.trash||!1,combineFeatures:e.combineFeatures||!1,uncombineFeatures:e.uncombineFeatures||!1};return this._ctx.events.actionable(t)},zn.prototype.changeMode=function(e,t={},n={}){return this._ctx.events.changeMode(e,t,n)},zn.prototype.fire=function(e,t){return this._ctx.events.fire(e,t)},zn.prototype.updateUIClasses=function(e){return this._ctx.ui.queueMapClasses(e)},zn.prototype.activateUIButton=function(e){return this._ctx.ui.setActiveButton(e)},zn.prototype.featuresAt=function(e,t,n="click"){if(n!=="click"&&n!=="touch")throw new Error("invalid buffer type");return Yh[n](e,t,this._ctx)},zn.prototype.newFeature=function(e){const t=e.geometry.type;return t===yn.POINT?new Fl(this._ctx,e):t===yn.LINE_STRING?new io(this._ctx,e):t===yn.POLYGON?new Da(this._ctx,e):new ra(this._ctx,e)},zn.prototype.isInstanceOf=function(e,t){if(e===yn.POINT)return t instanceof Fl;if(e===yn.LINE_STRING)return t instanceof io;if(e===yn.POLYGON)return t instanceof Da;if(e==="MultiFeature")return t instanceof ra;throw new Error(`Unknown feature class: ${e}`)},zn.prototype.doRender=function(e){return this._ctx.store.featureChanged(e)},zn.prototype.onSetup=function(){},zn.prototype.onDrag=function(){},zn.prototype.onClick=function(){},zn.prototype.onMouseMove=function(){},zn.prototype.onMouseDown=function(){},zn.prototype.onMouseUp=function(){},zn.prototype.onMouseOut=function(){},zn.prototype.onKeyUp=function(){},zn.prototype.onKeyDown=function(){},zn.prototype.onTouchStart=function(){},zn.prototype.onTouchMove=function(){},zn.prototype.onTouchEnd=function(){},zn.prototype.onTap=function(){},zn.prototype.onStop=function(){},zn.prototype.onTrash=function(){},zn.prototype.onCombineFeature=function(){},zn.prototype.onUncombineFeature=function(){},zn.prototype.toDisplayFeatures=function(){throw new Error("You must overwrite toDisplayFeatures")};const bN={drag:"onDrag",click:"onClick",mousemove:"onMouseMove",mousedown:"onMouseDown",mouseup:"onMouseUp",mouseout:"onMouseOut",keyup:"onKeyUp",keydown:"onKeyDown",touchstart:"onTouchStart",touchmove:"onTouchMove",touchend:"onTouchEnd",tap:"onTap"},rSe=Object.keys(bN);function iSe(e){const t=Object.keys(e);return function(n,r={}){let i={};const s=t.reduce((a,d)=>(a[d]=e[d],a),new zn(n));function c(a){return d=>s[a](i,d)}return{start(){i=s.onSetup(r),rSe.forEach(a=>{const d=bN[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 aSe(e){const t=Object.keys(e.options.modes).reduce((b,w)=>(b[w]=iSe(e.options.modes[w]),b),{});let n={},r={};const i={};let s=null,c=null;i.drag=function(b,w){w({point:b.point,time:new Date().getTime()})?(e.ui.queueMapClasses({mouse:Fr.DRAG}),c.drag(b)):b.originalEvent.stopPropagation()},i.mousedrag=function(b){i.drag(b,w=>!eS(n,w))},i.touchdrag=function(b){i.drag(b,w=>!tS(r,w))},i.mousemove=function(b){if((b.originalEvent.buttons!==void 0?b.originalEvent.buttons:b.originalEvent.which)===1)return i.mousedrag(b);const S=s0(b,e);b.featureTarget=S,c.mousemove(b)},i.mousedown=function(b){n={time:new Date().getTime(),point:b.point};const w=s0(b,e);b.featureTarget=w,c.mousedown(b)},i.mouseup=function(b){const w=s0(b,e);b.featureTarget=w,eS(n,{point:b.point,time:new Date().getTime()})?c.click(b):c.mouseup(b)},i.mouseout=function(b){c.mouseout(b)},i.touchstart=function(b){if(!e.options.touchEnabled)return;r={time:new Date().getTime(),point:b.point};const w=Yh.touch(b,null,e)[0];b.featureTarget=w,c.touchstart(b)},i.touchmove=function(b){if(e.options.touchEnabled)return c.touchmove(b),i.touchdrag(b)},i.touchend=function(b){if(b.originalEvent.preventDefault(),!e.options.touchEnabled)return;const w=Yh.touch(b,null,e)[0];b.featureTarget=w,tS(r,{time:new Date().getTime(),point:b.point})?c.tap(b):c.touchend(b)};const a=b=>!(b===8||b===46||b>=48&&b<=57);i.keydown=function(b){(b.srcElement||b.target).classList.contains(xa.CANVAS)&&((b.keyCode===8||b.keyCode===46)&&e.options.controls.trash?(b.preventDefault(),c.trash()):a(b.keyCode)?c.keydown(b):b.keyCode===49&&e.options.controls.point?d(Gn.DRAW_POINT):b.keyCode===50&&e.options.controls.line_string?d(Gn.DRAW_LINE_STRING):b.keyCode===51&&e.options.controls.polygon&&d(Gn.DRAW_POLYGON))},i.keyup=function(b){a(b.keyCode)&&c.keyup(b)},i.zoomend=function(){e.store.changeZoom()},i.data=function(b){if(b.dataType==="style"){const{setup:w,map:S,options:C,store:M}=e;C.styles.some(T=>S.getLayer(T.id))||(w.addLayers(),M.setDirty(),M.render())}};function d(b,w,S={}){c.stop();const C=t[b];if(C===void 0)throw new Error(`${b} is not valid`);s=b;const M=C(e,w);c=X2(M,e),S.silent||e.map.fire(ta.MODE_CHANGE,{mode:b}),e.store.setDirty(),e.store.render()}const p={trash:!1,combineFeatures:!1,uncombineFeatures:!1};function y(b){let w=!1;Object.keys(b).forEach(S=>{if(p[S]===void 0)throw new Error("Invalid action type");p[S]!==b[S]&&(w=!0),p[S]=b[S]}),w&&e.map.fire(ta.ACTIONABLE,{actions:p})}return{start(){s=e.options.defaultMode,c=X2(t[s](e),e)},changeMode:d,actionable:y,currentModeName(){return s},currentModeRender(b,w){return c.render(b,w)},fire(b,w){e.map&&e.map.fire(b,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(b){c.trash(b)},combineFeatures(){c.combineFeatures()},uncombineFeatures(){c.uncombineFeatures()},getMode(){return s}}}function zp(e){return[].concat(e).filter(t=>t!==void 0)}function sSe(){const e=this;if(!(e.ctx.map&&e.ctx.map.getSource(ss.HOT)!==void 0))return d();const n=e.ctx.events.currentModeName();e.ctx.ui.queueMapClasses({mode:n});let r=[],i=[];e.isDirty?i=e.getAllIds():(r=e.getChangedIds().filter(p=>e.get(p)!==void 0),i=e.sources.hot.filter(p=>p.properties.id&&r.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 r.indexOf(y)===-1});const c=s!==e.sources.cold.length||i.length>0;r.forEach(p=>a(p,"hot")),i.forEach(p=>a(p,"cold"));function a(p,y){const b=e.get(p).internal(n);e.ctx.events.currentModeRender(b,w=>{w.properties.mode=n,e.sources[y].push(w)})}c&&e.ctx.map.getSource(ss.COLD).setData({type:yn.FEATURE_COLLECTION,features:e.sources.cold}),e.ctx.map.getSource(ss.HOT).setData({type:yn.FEATURE_COLLECTION,features:e.sources.hot}),d();function d(){e.isDirty=!1,e.clearChangedIds()}}function kr(e){this._features={},this._featureIds=new os,this._selectedFeatureIds=new os,this._selectedCoordinates=[],this._changedFeatureIds=new os,this._emitSelectionChange=!1,this._mapInitialConfig={},this.ctx=e,this.sources={hot:[],cold:[]};let t;this.render=()=>{t||(t=requestAnimationFrame(()=>{t=null,sSe.call(this),this._emitSelectionChange&&(this.ctx.events.fire(ta.SELECTION_CHANGE,{features:this.getSelected().map(n=>n.toGeoJSON()),points:this.getSelectedCoordinates().map(n=>({type:yn.FEATURE,properties:{},geometry:{type:yn.POINT,coordinates:n.coordinates}}))}),this._emitSelectionChange=!1),this.ctx.events.fire(ta.RENDER,{})}))},this.isDirty=!1}kr.prototype.createRenderBatch=function(){const e=this.render;let t=0;return this.render=function(){t++},()=>{this.render=e,t>0&&this.render()}},kr.prototype.setDirty=function(){return this.isDirty=!0,this},kr.prototype.featureCreated=function(e,t={}){if(this._changedFeatureIds.add(e),(t.silent!=null?t.silent:this.ctx.options.suppressAPIEvents)!==!0){const r=this.get(e);this.ctx.events.fire(ta.CREATE,{features:[r.toGeoJSON()]})}return this},kr.prototype.featureChanged=function(e,t={}){return this._changedFeatureIds.add(e),(t.silent!=null?t.silent:this.ctx.options.suppressAPIEvents)!==!0&&this.ctx.events.fire(ta.UPDATE,{action:t.action?t.action:Fp.CHANGE_COORDINATES,features:[this.get(e).toGeoJSON()]}),this},kr.prototype.getChangedIds=function(){return this._changedFeatureIds.values()},kr.prototype.clearChangedIds=function(){return this._changedFeatureIds.clear(),this},kr.prototype.getAllIds=function(){return this._featureIds.values()},kr.prototype.add=function(e,t={}){return this._features[e.id]=e,this._featureIds.add(e.id),this.featureCreated(e.id,{silent:t.silent}),this},kr.prototype.delete=function(e,t={}){const n=[];return zp(e).forEach(r=>{this._featureIds.has(r)&&(this._featureIds.delete(r),this._selectedFeatureIds.delete(r),t.silent||n.indexOf(this._features[r])===-1&&n.push(this._features[r].toGeoJSON()),delete this._features[r],this.isDirty=!0)}),n.length&&this.ctx.events.fire(ta.DELETE,{features:n}),xN(this,t),this},kr.prototype.get=function(e){return this._features[e]},kr.prototype.getAll=function(){return Object.keys(this._features).map(e=>this._features[e])},kr.prototype.select=function(e,t={}){return zp(e).forEach(n=>{this._selectedFeatureIds.has(n)||(this._selectedFeatureIds.add(n),this._changedFeatureIds.add(n),t.silent||(this._emitSelectionChange=!0))}),this},kr.prototype.deselect=function(e,t={}){return zp(e).forEach(n=>{this._selectedFeatureIds.has(n)&&(this._selectedFeatureIds.delete(n),this._changedFeatureIds.add(n),t.silent||(this._emitSelectionChange=!0))}),xN(this,t),this},kr.prototype.clearSelected=function(e={}){return this.deselect(this._selectedFeatureIds.values(),{silent:e.silent}),this},kr.prototype.setSelected=function(e,t={}){return e=zp(e),this.deselect(this._selectedFeatureIds.values().filter(n=>e.indexOf(n)===-1),{silent:t.silent}),this.select(e.filter(n=>!this._selectedFeatureIds.has(n)),{silent:t.silent}),this},kr.prototype.setSelectedCoordinates=function(e){return this._selectedCoordinates=e,this._emitSelectionChange=!0,this},kr.prototype.clearSelectedCoordinates=function(){return this._selectedCoordinates=[],this._emitSelectionChange=!0,this},kr.prototype.getSelectedIds=function(){return this._selectedFeatureIds.values()},kr.prototype.getSelected=function(){return this.getSelectedIds().map(e=>this.get(e))},kr.prototype.getSelectedCoordinates=function(){return this._selectedCoordinates.map(t=>({coordinates:this.get(t.feature_id).getCoordinate(t.coord_path)}))},kr.prototype.isSelected=function(e){return this._selectedFeatureIds.has(e)},kr.prototype.setFeatureProperty=function(e,t,n,r={}){this.get(e).setProperty(t,n),this.featureChanged(e,{silent:r.silent,action:Fp.CHANGE_PROPERTIES})};function xN(e,t={}){const n=e._selectedCoordinates.filter(r=>e._selectedFeatureIds.has(r.feature_id));e._selectedCoordinates.length!==n.length&&!t.silent&&(e._emitSelectionChange=!0),e._selectedCoordinates=n}kr.prototype.storeMapConfig=function(){fN.forEach(e=>{this.ctx.map[e]&&(this._mapInitialConfig[e]=this.ctx.map[e].isEnabled())})},kr.prototype.restoreMapConfig=function(){Object.keys(this._mapInitialConfig).forEach(e=>{this._mapInitialConfig[e]?this.ctx.map[e].enable():this.ctx.map[e].disable()})},kr.prototype.getInitialConfigValue=function(e){return this._mapInitialConfig[e]!==void 0?this._mapInitialConfig[e]:!0};const oSe=["mode","feature","mouse"];function lSe(e){const t={};let n=null,r={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=[];oSe.forEach(C=>{i[C]!==r[C]&&(w.push(`${C}-${r[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),r=Object.assign(r,i)}function d(w,S={}){const C=document.createElement("button");return C.className=`${xa.CONTROL_BUTTON} ${S.className}`,C.setAttribute("title",S.title),S.container.appendChild(C),C.addEventListener("click",M=>{if(M.preventDefault(),M.stopPropagation(),M.target===n){p(),S.onDeactivate();return}y(w),S.onActivate()},!0),C}function p(){n&&(n.classList.remove(xa.ACTIVE_BUTTON),n=null)}function y(w){p();const S=t[w];S&&S&&w!=="trash"&&(S.classList.add(xa.ACTIVE_BUTTON),n=S)}function g(){const w=e.options.controls,S=document.createElement("div");return S.className=`${xa.CONTROL_GROUP} ${xa.CONTROL_BASE}`,w&&(w[_a.LINE]&&(t[_a.LINE]=d(_a.LINE,{container:S,className:xa.CONTROL_BUTTON_LINE,title:`LineString tool ${e.options.keybindings?"(l)":""}`,onActivate:()=>e.events.changeMode(Gn.DRAW_LINE_STRING),onDeactivate:()=>e.events.trash()})),w[_a.POLYGON]&&(t[_a.POLYGON]=d(_a.POLYGON,{container:S,className:xa.CONTROL_BUTTON_POLYGON,title:`Polygon tool ${e.options.keybindings?"(p)":""}`,onActivate:()=>e.events.changeMode(Gn.DRAW_POLYGON),onDeactivate:()=>e.events.trash()})),w[_a.POINT]&&(t[_a.POINT]=d(_a.POINT,{container:S,className:xa.CONTROL_BUTTON_POINT,title:`Marker tool ${e.options.keybindings?"(m)":""}`,onActivate:()=>e.events.changeMode(Gn.DRAW_POINT),onDeactivate:()=>e.events.trash()})),w.trash&&(t.trash=d("trash",{container:S,className:xa.CONTROL_BUTTON_TRASH,title:"Delete",onActivate:()=>{e.events.trash()}})),w.combine_features&&(t.combine_features=d("combineFeatures",{container:S,className:xa.CONTROL_BUTTON_COMBINE_FEATURES,title:"Combine",onActivate:()=>{e.events.combineFeatures()}})),w.uncombine_features&&(t.uncombine_features=d("uncombineFeatures",{container:S,className:xa.CONTROL_BUTTON_UNCOMBINE_FEATURES,title:"Uncombine",onActivate:()=>{e.events.uncombineFeatures()}}))),S}function b(){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:b}}function cSe(e){let t=null,n=null;const r={onRemove(){return e.map.off("load",r.connect),clearInterval(n),r.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",r.connect),clearInterval(n),r.addLayers(),e.store.storeMapConfig(),e.events.addEventListeners()},onAdd(i){if(e.map=i,e.events=aSe(e),e.ui=lSe(e),e.container=i.getContainer(),e.store=new kr(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()?r.connect():(i.on("load",r.connect),n=setInterval(()=>{i.loaded()&&r.connect()},16)),e.events.start(),t},addLayers(){e.map.addSource(ss.COLD,{data:{type:yn.FEATURE_COLLECTION,features:[]},type:"geojson"}),e.map.addSource(ss.HOT,{data:{type:yn.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(ss.COLD)&&e.map.removeSource(ss.COLD),e.map.getSource(ss.HOT)&&e.map.removeSource(ss.HOT)}};return e.setup=r,r}const rS="#3bb2d0",$p="#fbb03b",_N="#fff",wN=[{id:"gl-draw-polygon-fill",type:"fill",filter:["all",["==","$type","Polygon"]],paint:{"fill-color":["case",["==",["get","active"],"true"],$p,rS],"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"],$p,rS],"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":_N}},{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"],$p,rS]}},{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":_N}},{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":$p}},{id:"gl-draw-midpoint",type:"circle",filter:["all",["==","meta","midpoint"]],paint:{"circle-radius":3,"circle-color":$p}}];function l0(e){return function(t){const n=t.featureTarget;return!n||!n.properties?!1:n.properties.meta===e}}function SN(e){return!e.originalEvent||!e.originalEvent.shiftKey?!1:e.originalEvent.button===0}function Uc(e){return!e.featureTarget||!e.featureTarget.properties?!1:e.featureTarget.properties.active===fi.ACTIVE&&e.featureTarget.properties.meta===Bi.FEATURE}function iS(e){return!e.featureTarget||!e.featureTarget.properties?!1:e.featureTarget.properties.active===fi.INACTIVE&&e.featureTarget.properties.meta===Bi.FEATURE}function c0(e){return e.featureTarget===void 0}function aS(e){return!e.featureTarget||!e.featureTarget.properties?!1:e.featureTarget.properties.meta===Bi.FEATURE}function Vp(e){const t=e.featureTarget;return!t||!t.properties?!1:t.properties.meta===Bi.VERTEX}function u0(e){return e.originalEvent?e.originalEvent.shiftKey===!0:!1}function h0(e){return e.keyCode===27}function d0(e){return e.keyCode===13}function uSe(){return!0}const hSe=Object.freeze(Object.defineProperty({__proto__:null,isActiveFeature:Uc,isEnterKey:d0,isEscapeKey:h0,isFeature:aS,isInactiveFeature:iS,isOfMetaType:l0,isShiftDown:u0,isShiftMousedown:SN,isTrue:uSe,isVertex:Vp,noTarget:c0},Symbol.toStringTag,{value:"Module"}));function zl(e,t){this.x=e,this.y=t}zl.prototype={clone(){return new zl(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,n=e.y-this.y;return t*t+n*n},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,n=e[2]*this.x+e[3]*this.y;return this.x=t,this.y=n,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),n=Math.sin(e),r=t*this.x-n*this.y,i=n*this.x+t*this.y;return this.x=r,this.y=i,this},_rotateAround(e,t){const n=Math.cos(e),r=Math.sin(e),i=t.x+n*(this.x-t.x)-r*(this.y-t.y),s=t.y+r*(this.x-t.x)+n*(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:zl},zl.convert=function(e){if(e instanceof zl)return e;if(Array.isArray(e))return new zl(+e[0],+e[1]);if(e.x!==void 0&&e.y!==void 0)return new zl(+e.x,+e.y);throw new Error("Expected [x, y] or {x, y} point format")};function sS(e,t){const n=t.getBoundingClientRect();return new zl(e.clientX-n.left-(t.clientLeft||0),e.clientY-n.top-(t.clientTop||0))}function qh(e,t,n,r){return{type:yn.FEATURE,properties:{meta:Bi.VERTEX,parent:e,coord_path:n,active:r?fi.ACTIVE:fi.INACTIVE},geometry:{type:yn.POINT,coordinates:t}}}function CN(e,t,n){const r=t.geometry.coordinates,i=n.geometry.coordinates;if(r[1]>K2||r[1]<J2||i[1]>K2||i[1]<J2)return null;const s={lng:(r[0]+i[0])/2,lat:(r[1]+i[1])/2};return{type:yn.FEATURE,properties:{meta:Bi.MIDPOINT,parent:e,lng:s.lng,lat:s.lat,coord_path:n.properties.coord_path},geometry:{type:yn.POINT,coordinates:[s.lng,s.lat]}}}function f0(e,t={},n=null){const{type:r,coordinates:i}=e.geometry,s=e.properties&&e.properties.id;let c=[];r===yn.POINT?c.push(qh(s,i,n,d(n))):r===yn.POLYGON?i.forEach((y,g)=>{a(y,n!==null?`${n}.${g}`:String(g))}):r===yn.LINE_STRING?a(i,n):r.indexOf(yn.MULTI_PREFIX)===0&&p();function a(y,g){let b="",w=null;y.forEach((S,C)=>{const M=g!=null?`${g}.${C}`:String(C),O=qh(s,S,M,d(M));if(t.midpoints&&w){const D=CN(s,w,O);D&&c.push(D)}w=O;const T=JSON.stringify(S);b!==T&&c.push(O),C===0&&(b=T)})}function d(y){return t.selectedPaths?t.selectedPaths.indexOf(y)!==-1:!1}function p(){const y=r.replace(yn.MULTI_PREFIX,"");i.forEach((g,b)=>{const w={type:yn.FEATURE,properties:e.properties,geometry:{type:y,coordinates:g}};c=c.concat(f0(w,t,b))})}return c}const As={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:p0,LAT_MAX:m0,LAT_RENDERED_MIN:MN,LAT_RENDERED_MAX:AN,LNG_MIN:EN,LNG_MAX:TN}=pN;function dSe(e){const t={Point:0,LineString:1,Polygon:2,MultiPoint:1,MultiLineString:2,MultiPolygon:3}[e.geometry.type],n=[e.geometry.coordinates].flat(t),r=n.map(a=>a[0]),i=n.map(a=>a[1]),s=a=>Math.min.apply(null,a),c=a=>Math.max.apply(null,a);return[s(r),s(i),c(r),c(i)]}function oS(e,t){let n=p0,r=m0,i=p0,s=m0,c=TN,a=EN;e.forEach(p=>{const y=dSe(p),g=y[1],b=y[3],w=y[0],S=y[2];g>n&&(n=g),b<r&&(r=b),b>i&&(i=b),g<s&&(s=g),w<c&&(c=w),S>a&&(a=S)});const d=t;return n+d.lat>AN&&(d.lat=AN-n),i+d.lat>m0&&(d.lat=m0-i),r+d.lat<MN&&(d.lat=MN-r),s+d.lat<p0&&(d.lat=p0-s),c+d.lng<=EN&&(d.lng+=Math.ceil(Math.abs(d.lng)/360)*360),a+d.lng>=TN&&(d.lng-=Math.ceil(Math.abs(d.lng)/360)*360),d}function lS(e,t){const n=oS(e.map(r=>r.toGeoJSON()),t);e.forEach(r=>{const i=r.getCoordinates(),s=p=>{const y={lng:p[0]+n.lng,lat:p[1]+n.lat};return[y.lng,y.lat]},c=p=>p.map(y=>s(y)),a=p=>p.map(y=>c(y));let d;r.type===yn.POINT?d=s(i):r.type===yn.LINE_STRING||r.type===yn.MULTI_POINT?d=i.map(s):r.type===yn.POLYGON||r.type===yn.MULTI_LINE_STRING?d=i.map(c):r.type===yn.MULTI_POLYGON&&(d=i.map(a)),r.incomingCoords(d)})}const Cr={};Cr.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(n=>this.getFeature(n)!==void 0)),this.fireActionable(),this.setActionableState({combineFeatures:!0,uncombineFeatures:!0,trash:!0}),t},Cr.fireUpdate=function(){this.fire(ta.UPDATE,{action:Fp.MOVE,features:this.getSelected().map(e=>e.toGeoJSON())})},Cr.fireActionable=function(){const e=this.getSelected(),t=e.filter(s=>this.isInstanceOf("MultiFeature",s));let n=!1;if(e.length>1){n=!0;const s=e[0].type.replace("Multi","");e.forEach(c=>{c.type.replace("Multi","")!==s&&(n=!1)})}const r=t.length>0,i=e.length>0;this.setActionableState({combineFeatures:n,uncombineFeatures:r,trash:i})},Cr.getUniqueIds=function(e){return e.length?e.map(n=>n.properties.id).filter(n=>n!==void 0).reduce((n,r)=>(n.add(r),n),new os).values():[]},Cr.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},Cr.onStop=function(){As.enable(this)},Cr.onMouseMove=function(e,t){return aS(t)&&e.dragMoving&&this.fireUpdate(),this.stopExtendedInteractions(e),!0},Cr.onMouseOut=function(e){return e.dragMoving?this.fireUpdate():!0},Cr.onTap=Cr.onClick=function(e,t){if(c0(t))return this.clickAnywhere(e,t);if(l0(Bi.VERTEX)(t))return this.clickOnVertex(e,t);if(aS(t))return this.clickOnFeature(e,t)},Cr.clickAnywhere=function(e){const t=this.getSelectedIds();t.length&&(this.clearSelectedFeatures(),t.forEach(n=>this.doRender(n))),As.enable(this),this.stopExtendedInteractions(e)},Cr.clickOnVertex=function(e,t){this.changeMode(Gn.DIRECT_SELECT,{featureId:t.featureTarget.properties.parent,coordPath:t.featureTarget.properties.coord_path,startPos:t.lngLat}),this.updateUIClasses({mouse:Fr.MOVE})},Cr.startOnActiveFeature=function(e,t){this.stopExtendedInteractions(e),this.map.dragPan.disable(),this.doRender(t.featureTarget.properties.id),e.canDragMove=!0,e.dragMoveLocation=t.lngLat},Cr.clickOnFeature=function(e,t){As.disable(this),this.stopExtendedInteractions(e);const n=u0(t),r=this.getSelectedIds(),i=t.featureTarget.properties.id,s=this.isSelected(i);if(!n&&s&&this.getFeature(i).type!==yn.POINT)return this.changeMode(Gn.DIRECT_SELECT,{featureId:i});s&&n?(this.deselect(i),this.updateUIClasses({mouse:Fr.POINTER}),r.length===1&&As.enable(this)):!s&&n?(this.select(i),this.updateUIClasses({mouse:Fr.MOVE})):!s&&!n&&(r.forEach(c=>this.doRender(c)),this.setSelected(i),this.updateUIClasses({mouse:Fr.MOVE})),this.doRender(i)},Cr.onMouseDown=function(e,t){if(e.initialDragPanState=this.map.dragPan.isEnabled(),Uc(t))return this.startOnActiveFeature(e,t);if(this.drawConfig.boxSelect&&SN(t))return this.startBoxSelect(e,t)},Cr.startBoxSelect=function(e,t){this.stopExtendedInteractions(e),this.map.dragPan.disable(),e.boxSelectStartLocation=sS(t.originalEvent,this.map.getContainer()),e.canBoxSelect=!0},Cr.onTouchStart=function(e,t){if(Uc(t))return this.startOnActiveFeature(e,t)},Cr.onDrag=function(e,t){if(e.canDragMove)return this.dragMove(e,t);if(this.drawConfig.boxSelect&&e.canBoxSelect)return this.whileBoxSelect(e,t)},Cr.whileBoxSelect=function(e,t){e.boxSelecting=!0,this.updateUIClasses({mouse:Fr.ADD}),e.boxSelectElement||(e.boxSelectElement=document.createElement("div"),e.boxSelectElement.classList.add(xa.BOX_SELECT),this.map.getContainer().appendChild(e.boxSelectElement));const n=sS(t.originalEvent,this.map.getContainer()),r=Math.min(e.boxSelectStartLocation.x,n.x),i=Math.max(e.boxSelectStartLocation.x,n.x),s=Math.min(e.boxSelectStartLocation.y,n.y),c=Math.max(e.boxSelectStartLocation.y,n.y),a=`translate(${r}px, ${s}px)`;e.boxSelectElement.style.transform=a,e.boxSelectElement.style.WebkitTransform=a,e.boxSelectElement.style.width=`${i-r}px`,e.boxSelectElement.style.height=`${c-s}px`},Cr.dragMove=function(e,t){e.dragMoving=!0,t.originalEvent.stopPropagation();const n={lng:t.lngLat.lng-e.dragMoveLocation.lng,lat:t.lngLat.lat-e.dragMoveLocation.lat};lS(this.getSelected(),n),e.dragMoveLocation=t.lngLat},Cr.onTouchEnd=Cr.onMouseUp=function(e,t){if(e.dragMoving)this.fireUpdate();else if(e.boxSelecting){const n=[e.boxSelectStartLocation,sS(t.originalEvent,this.map.getContainer())],r=this.featuresAt(null,n,"click"),i=this.getUniqueIds(r).filter(s=>!this.isSelected(s));i.length&&(this.select(i),i.forEach(s=>this.doRender(s)),this.updateUIClasses({mouse:Fr.MOVE}))}this.stopExtendedInteractions(e)},Cr.toDisplayFeatures=function(e,t,n){t.properties.active=this.isSelected(t.properties.id)?fi.ACTIVE:fi.INACTIVE,n(t),this.fireActionable(),!(t.properties.active!==fi.ACTIVE||t.geometry.type===yn.POINT)&&f0(t).forEach(n)},Cr.onTrash=function(){this.deleteFeature(this.getSelectedIds()),this.fireActionable()},Cr.onCombineFeatures=function(){const e=this.getSelected();if(e.length===0||e.length<2)return;const t=[],n=[],r=e[0].type.replace("Multi","");for(let i=0;i<e.length;i++){const s=e[i];if(s.type.replace("Multi","")!==r)return;s.type.includes("Multi")?s.getCoordinates().forEach(c=>{t.push(c)}):t.push(s.getCoordinates()),n.push(s.toGeoJSON())}if(n.length>1){const i=this.newFeature({type:yn.FEATURE,properties:n[0].properties,geometry:{type:`Multi${r}`,coordinates:t}});this.addFeature(i),this.deleteFeature(this.getSelectedIds(),{silent:!0}),this.setSelected([i.id]),this.fire(ta.COMBINE_FEATURES,{createdFeatures:[i.toGeoJSON()],deletedFeatures:n})}this.fireActionable()},Cr.onUncombineFeatures=function(){const e=this.getSelected();if(e.length===0)return;const t=[],n=[];for(let r=0;r<e.length;r++){const i=e[r];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}),n.push(i.toGeoJSON()))}t.length>1&&this.fire(ta.UNCOMBINE_FEATURES,{createdFeatures:t,deletedFeatures:n}),this.fireActionable()};const IN=l0(Bi.VERTEX),PN=l0(Bi.MIDPOINT),Mr={};Mr.fireUpdate=function(){this.fire(ta.UPDATE,{action:Fp.CHANGE_COORDINATES,features:this.getSelected().map(e=>e.toGeoJSON())})},Mr.fireActionable=function(e){this.setActionableState({combineFeatures:!1,uncombineFeatures:!1,trash:e.selectedCoordPaths.length>0})},Mr.startDragging=function(e,t){e.initialDragPanState=this.map.dragPan.isEnabled(),this.map.dragPan.disable(),e.canDragMove=!0,e.dragMoveLocation=t.lngLat},Mr.stopDragging=function(e){e.canDragMove&&e.initialDragPanState===!0&&this.map.dragPan.enable(),e.dragMoving=!1,e.canDragMove=!1,e.dragMoveLocation=null},Mr.onVertex=function(e,t){this.startDragging(e,t);const n=t.featureTarget.properties,r=e.selectedCoordPaths.indexOf(n.coord_path);!u0(t)&&r===-1?e.selectedCoordPaths=[n.coord_path]:u0(t)&&r===-1&&e.selectedCoordPaths.push(n.coord_path);const i=this.pathsToCoordinates(e.featureId,e.selectedCoordPaths);this.setSelectedCoordinates(i)},Mr.onMidpoint=function(e,t){this.startDragging(e,t);const n=t.featureTarget.properties;e.feature.addCoordinate(n.coord_path,n.lng,n.lat),this.fireUpdate(),e.selectedCoordPaths=[n.coord_path]},Mr.pathsToCoordinates=function(e,t){return t.map(n=>({feature_id:e,coord_path:n}))},Mr.onFeature=function(e,t){e.selectedCoordPaths.length===0?this.startDragging(e,t):this.stopDragging(e)},Mr.dragFeature=function(e,t,n){lS(this.getSelected(),n),e.dragMoveLocation=t.lngLat},Mr.dragVertex=function(e,t,n){const r=e.selectedCoordPaths.map(c=>e.feature.getCoordinate(c)),i=r.map(c=>({type:yn.FEATURE,properties:{},geometry:{type:yn.POINT,coordinates:c}})),s=oS(i,n);for(let c=0;c<r.length;c++){const a=r[c];e.feature.updateCoordinate(e.selectedCoordPaths[c],a[0]+s.lng,a[1]+s.lat)}},Mr.clickNoTarget=function(){this.changeMode(Gn.SIMPLE_SELECT)},Mr.clickInactive=function(){this.changeMode(Gn.SIMPLE_SELECT)},Mr.clickActiveFeature=function(e){e.selectedCoordPaths=[],this.clearSelectedCoordinates(),e.feature.changed()},Mr.onSetup=function(e){const t=e.featureId,n=this.getFeature(t);if(!n)throw new Error("You must provide a featureId to enter direct_select mode");if(n.type===yn.POINT)throw new TypeError("direct_select mode doesn't handle point features");const r={featureId:t,feature:n,dragMoveLocation:e.startPos||null,dragMoving:!1,canDragMove:!1,selectedCoordPaths:e.coordPath?[e.coordPath]:[]};return this.setSelectedCoordinates(this.pathsToCoordinates(t,r.selectedCoordPaths)),this.setSelected(t),As.disable(this),this.setActionableState({trash:!0}),r},Mr.onStop=function(){As.enable(this),this.clearSelectedCoordinates()},Mr.toDisplayFeatures=function(e,t,n){e.featureId===t.properties.id?(t.properties.active=fi.ACTIVE,n(t),f0(t,{map:this.map,midpoints:!0,selectedPaths:e.selectedCoordPaths}).forEach(n)):(t.properties.active=fi.INACTIVE,n(t)),this.fireActionable(e)},Mr.onTrash=function(e){e.selectedCoordPaths.sort((t,n)=>n.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(Gn.SIMPLE_SELECT,{}))},Mr.onMouseMove=function(e,t){const n=Uc(t),r=IN(t),i=PN(t),s=e.selectedCoordPaths.length===0;return n&&s?this.updateUIClasses({mouse:Fr.MOVE}):r&&!s?this.updateUIClasses({mouse:Fr.MOVE}):this.updateUIClasses({mouse:Fr.NONE}),(r||n||i)&&e.dragMoving&&this.fireUpdate(),this.stopDragging(e),!0},Mr.onMouseOut=function(e){return e.dragMoving&&this.fireUpdate(),!0},Mr.onTouchStart=Mr.onMouseDown=function(e,t){if(IN(t))return this.onVertex(e,t);if(Uc(t))return this.onFeature(e,t);if(PN(t))return this.onMidpoint(e,t)},Mr.onDrag=function(e,t){if(e.canDragMove!==!0)return;e.dragMoving=!0,t.originalEvent.stopPropagation();const n={lng:t.lngLat.lng-e.dragMoveLocation.lng,lat:t.lngLat.lat-e.dragMoveLocation.lat};e.selectedCoordPaths.length>0?this.dragVertex(e,t,n):this.dragFeature(e,t,n),e.dragMoveLocation=t.lngLat},Mr.onClick=function(e,t){if(c0(t))return this.clickNoTarget(e,t);if(Uc(t))return this.clickActiveFeature(e,t);if(iS(t))return this.clickInactive(e,t);this.stopDragging(e)},Mr.onTap=function(e,t){if(c0(t))return this.clickNoTarget(e,t);if(Uc(t))return this.clickActiveFeature(e,t);if(iS(t))return this.clickInactive(e,t)},Mr.onTouchEnd=Mr.onMouseUp=function(e){e.dragMoving&&this.fireUpdate(),this.stopDragging(e)};const ao={};ao.onSetup=function(){const e=this.newFeature({type:yn.FEATURE,properties:{},geometry:{type:yn.POINT,coordinates:[]}});return this.addFeature(e),this.clearSelectedFeatures(),this.updateUIClasses({mouse:Fr.ADD}),this.activateUIButton(_a.POINT),this.setActionableState({trash:!0}),{point:e}},ao.stopDrawingAndRemove=function(e){this.deleteFeature([e.point.id],{silent:!0}),this.changeMode(Gn.SIMPLE_SELECT)},ao.onTap=ao.onClick=function(e,t){this.updateUIClasses({mouse:Fr.MOVE}),e.point.updateCoordinate("",t.lngLat.lng,t.lngLat.lat),this.fire(ta.CREATE,{features:[e.point.toGeoJSON()]}),this.changeMode(Gn.SIMPLE_SELECT,{featureIds:[e.point.id]})},ao.onStop=function(e){this.activateUIButton(),e.point.getCoordinate().length||this.deleteFeature([e.point.id],{silent:!0})},ao.toDisplayFeatures=function(e,t,n){const r=t.properties.id===e.point.id;if(t.properties.active=r?fi.ACTIVE:fi.INACTIVE,!r)return n(t)},ao.onTrash=ao.stopDrawingAndRemove,ao.onKeyUp=function(e,t){if(h0(t)||d0(t))return this.stopDrawingAndRemove(e,t)};function g0(e,t){return e.lngLat?e.lngLat.lng===t[0]&&e.lngLat.lat===t[1]:!1}const Es={};Es.onSetup=function(){const e=this.newFeature({type:yn.FEATURE,properties:{},geometry:{type:yn.POLYGON,coordinates:[[]]}});return this.addFeature(e),this.clearSelectedFeatures(),As.disable(this),this.updateUIClasses({mouse:Fr.ADD}),this.activateUIButton(_a.POLYGON),this.setActionableState({trash:!0}),{polygon:e,currentVertexPosition:0}},Es.clickAnywhere=function(e,t){if(e.currentVertexPosition>0&&g0(t,e.polygon.coordinates[0][e.currentVertexPosition-1]))return this.changeMode(Gn.SIMPLE_SELECT,{featureIds:[e.polygon.id]});this.updateUIClasses({mouse:Fr.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)},Es.clickOnVertex=function(e){return this.changeMode(Gn.SIMPLE_SELECT,{featureIds:[e.polygon.id]})},Es.onMouseMove=function(e,t){e.polygon.updateCoordinate(`0.${e.currentVertexPosition}`,t.lngLat.lng,t.lngLat.lat),Vp(t)&&this.updateUIClasses({mouse:Fr.POINTER})},Es.onTap=Es.onClick=function(e,t){return Vp(t)?this.clickOnVertex(e,t):this.clickAnywhere(e,t)},Es.onKeyUp=function(e,t){h0(t)?(this.deleteFeature([e.polygon.id],{silent:!0}),this.changeMode(Gn.SIMPLE_SELECT)):d0(t)&&this.changeMode(Gn.SIMPLE_SELECT,{featureIds:[e.polygon.id]})},Es.onStop=function(e){this.updateUIClasses({mouse:Fr.NONE}),As.enable(this),this.activateUIButton(),this.getFeature(e.polygon.id)!==void 0&&(e.polygon.removeCoordinate(`0.${e.currentVertexPosition}`),e.polygon.isValid()?this.fire(ta.CREATE,{features:[e.polygon.toGeoJSON()]}):(this.deleteFeature([e.polygon.id],{silent:!0}),this.changeMode(Gn.SIMPLE_SELECT,{},{silent:!0})))},Es.toDisplayFeatures=function(e,t,n){const r=t.properties.id===e.polygon.id;if(t.properties.active=r?fi.ACTIVE:fi.INACTIVE,!r)return n(t);if(t.geometry.coordinates.length===0)return;const i=t.geometry.coordinates[0].length;if(!(i<3)){if(t.properties.meta=Bi.FEATURE,n(qh(e.polygon.id,t.geometry.coordinates[0][0],"0.0",!1)),i>3){const s=t.geometry.coordinates[0].length-3;n(qh(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(n({type:yn.FEATURE,properties:t.properties,geometry:{coordinates:s,type:yn.LINE_STRING}}),i===3)return}return n(t)}},Es.onTrash=function(e){this.deleteFeature([e.polygon.id],{silent:!0}),this.changeMode(Gn.SIMPLE_SELECT)};const Ts={};Ts.onSetup=function(e){e=e||{};const t=e.featureId;let n,r,i="forward";if(t){if(n=this.getFeature(t),!n)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=n.coordinates.length-1;if(n.coordinates[c][0]===s[0]&&n.coordinates[c][1]===s[1])r=c+1,n.addCoordinate(r,...n.coordinates[c]);else if(n.coordinates[0][0]===s[0]&&n.coordinates[0][1]===s[1])i="backwards",r=0,n.addCoordinate(r,...n.coordinates[0]);else throw new Error("`from` should match the point at either the start or the end of the provided LineString")}else n=this.newFeature({type:yn.FEATURE,properties:{},geometry:{type:yn.LINE_STRING,coordinates:[]}}),r=0,this.addFeature(n);return this.clearSelectedFeatures(),As.disable(this),this.updateUIClasses({mouse:Fr.ADD}),this.activateUIButton(_a.LINE),this.setActionableState({trash:!0}),{line:n,currentVertexPosition:r,direction:i}},Ts.clickAnywhere=function(e,t){if(e.currentVertexPosition>0&&g0(t,e.line.coordinates[e.currentVertexPosition-1])||e.direction==="backwards"&&g0(t,e.line.coordinates[e.currentVertexPosition+1]))return this.changeMode(Gn.SIMPLE_SELECT,{featureIds:[e.line.id]});this.updateUIClasses({mouse:Fr.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)},Ts.clickOnVertex=function(e){return this.changeMode(Gn.SIMPLE_SELECT,{featureIds:[e.line.id]})},Ts.onMouseMove=function(e,t){e.line.updateCoordinate(e.currentVertexPosition,t.lngLat.lng,t.lngLat.lat),Vp(t)&&this.updateUIClasses({mouse:Fr.POINTER})},Ts.onTap=Ts.onClick=function(e,t){if(Vp(t))return this.clickOnVertex(e,t);this.clickAnywhere(e,t)},Ts.onKeyUp=function(e,t){d0(t)?this.changeMode(Gn.SIMPLE_SELECT,{featureIds:[e.line.id]}):h0(t)&&(this.deleteFeature([e.line.id],{silent:!0}),this.changeMode(Gn.SIMPLE_SELECT))},Ts.onStop=function(e){As.enable(this),this.activateUIButton(),this.getFeature(e.line.id)!==void 0&&(e.line.removeCoordinate(`${e.currentVertexPosition}`),e.line.isValid()?this.fire(ta.CREATE,{features:[e.line.toGeoJSON()]}):(this.deleteFeature([e.line.id],{silent:!0}),this.changeMode(Gn.SIMPLE_SELECT,{},{silent:!0})))},Ts.onTrash=function(e){this.deleteFeature([e.line.id],{silent:!0}),this.changeMode(Gn.SIMPLE_SELECT)},Ts.toDisplayFeatures=function(e,t,n){const r=t.properties.id===e.line.id;if(t.properties.active=r?fi.ACTIVE:fi.INACTIVE,!r)return n(t);t.geometry.coordinates.length<2||(t.properties.meta=Bi.FEATURE,n(qh(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)),n(t))};const ON={simple_select:Cr,direct_select:Mr,draw_point:ao,draw_polygon:Es,draw_line_string:Ts},fSe={defaultMode:Gn.SIMPLE_SELECT,keybindings:!0,touchEnabled:!0,clickBuffer:2,touchBuffer:25,boxSelect:!0,displayControlsDefault:!0,styles:wN,modes:ON,controls:{},userProperties:!1,suppressAPIEvents:!0},pSe={point:!0,line_string:!0,polygon:!0,trash:!0,combine_features:!0,uncombine_features:!0},mSe={point:!1,line_string:!1,polygon:!1,trash:!1,combine_features:!1,uncombine_features:!1};function kN(e,t){return e.map(n=>n.source?n:Object.assign({},n,{id:`${n.id}.${t}`,source:t==="hot"?ss.HOT:ss.COLD}))}function gSe(e={}){let t=Object.assign({},e);return e.controls||(t.controls={}),e.displayControlsDefault===!1?t.controls=Object.assign({},mSe,e.controls):t.controls=Object.assign({},pSe,e.controls),t=Object.assign({},fSe,t),t.styles=kN(t.styles,"cold").concat(kN(t.styles,"hot")),t}var ySe=bSe,vSe={Point:"geometry",MultiPoint:"geometry",LineString:"geometry",MultiLineString:"geometry",Polygon:"geometry",MultiPolygon:"geometry",GeometryCollection:"geometry",Feature:"feature",FeatureCollection:"featurecollection"};function bSe(e){if(!e||!e.type)return null;var t=vSe[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 xSe=Jn(ySe);function DN(e,t){return e.length!==t.length?!1:JSON.stringify(e.map(n=>n).sort())===JSON.stringify(t.map(n=>n).sort())}const _Se={Polygon:Da,LineString:io,Point:Fl,MultiPolygon:ra,MultiLineString:ra,MultiPoint:ra};function wSe(e,t){t.modes=Gn;const n=e.options.suppressAPIEvents!==void 0?!!e.options.suppressAPIEvents:!0;return t.getFeatureIdsAt=function(r){return Yh.click({point:r},null,e).map(s=>s.properties.id)},t.getSelectedIds=function(){return e.store.getSelectedIds()},t.getSelected=function(){return{type:yn.FEATURE_COLLECTION,features:e.store.getSelectedIds().map(r=>e.store.get(r)).map(r=>r.toGeoJSON())}},t.getSelectedPoints=function(){return{type:yn.FEATURE_COLLECTION,features:e.store.getSelectedCoordinates().map(r=>({type:yn.FEATURE,properties:{},geometry:{type:yn.POINT,coordinates:r.coordinates}}))}},t.set=function(r){if(r.type===void 0||r.type!==yn.FEATURE_COLLECTION||!Array.isArray(r.features))throw new Error("Invalid FeatureCollection");const i=e.store.createRenderBatch();let s=e.store.getAllIds().slice();const c=t.add(r),a=new os(c);return s=s.filter(d=>!a.has(d)),s.length&&t.delete(s),i(),c},t.add=function(r){const s=JSON.parse(JSON.stringify(xSe(r))).features.map(c=>{if(c.id=c.id||nS(),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=_Se[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:n})}else{const a=e.store.get(c.id),d=a.properties;a.properties=c.properties,hI(d,c.properties)||e.store.featureChanged(a.id,{silent:n}),hI(a.getCoordinates(),c.geometry.coordinates)||a.incomingCoords(c.geometry.coordinates)}return c.id});return e.store.render(),s},t.get=function(r){const i=e.store.get(r);if(i)return i.toGeoJSON()},t.getAll=function(){return{type:yn.FEATURE_COLLECTION,features:e.store.getAll().map(r=>r.toGeoJSON())}},t.delete=function(r){return e.store.delete(r,{silent:n}),t.getMode()===Gn.DIRECT_SELECT&&!e.store.getSelectedIds().length?e.events.changeMode(Gn.SIMPLE_SELECT,void 0,{silent:n}):e.store.render(),t},t.deleteAll=function(){return e.store.delete(e.store.getAllIds(),{silent:n}),t.getMode()===Gn.DIRECT_SELECT?e.events.changeMode(Gn.SIMPLE_SELECT,void 0,{silent:n}):e.store.render(),t},t.changeMode=function(r,i={}){return r===Gn.SIMPLE_SELECT&&t.getMode()===Gn.SIMPLE_SELECT?(DN(i.featureIds||[],e.store.getSelectedIds())||(e.store.setSelected(i.featureIds,{silent:n}),e.store.render()),t):(r===Gn.DIRECT_SELECT&&t.getMode()===Gn.DIRECT_SELECT&&i.featureId===e.store.getSelectedIds()[0]||e.events.changeMode(r,i,{silent:n}),t)},t.getMode=function(){return e.events.getMode()},t.trash=function(){return e.events.trash({silent:n}),t},t.combineFeatures=function(){return e.events.combineFeatures({silent:n}),t},t.uncombineFeatures=function(){return e.events.uncombineFeatures({silent:n}),t},t.setFeatureProperty=function(r,i,s){return e.store.setFeatureProperty(r,i,s,{silent:n}),t},t}const SSe=Object.freeze(Object.defineProperty({__proto__:null,CommonSelectors:hSe,ModeHandler:X2,StringSet:os,constrainFeatureMovement:oS,createMidPoint:CN,createSupplementaryPoints:f0,createVertex:qh,doubleClickZoom:As,euclideanDistance:Q2,featuresAt:Yh,getFeatureAtAndSetCursors:s0,isClick:eS,isEventAtCoordinates:g0,isTap:tS,mapEventToBoundingBox:yN,moveFeatures:lS,sortFeatures:gN,stringSetsAreEqual:DN,theme:wN,toDenseArray:zp},Symbol.toStringTag,{value:"Module"})),CSe=function(e,t){e=gSe(e);const n={options:e};t=wSe(n,t),n.api=t;const r=cSe(n);return t.onAdd=r.onAdd,t.onRemove=r.onRemove,t.types=_a,t.options=e,t};function Jh(e){CSe(e,this)}Jh.modes=ON,Jh.constants=pN,Jh.lib=SSe;const MSe=({polygon:e,deleteFeature:t,trigger:n})=>{var C;const[r,i]=H.useState(!1),{mapRef:s}=H.useContext(ii),{addNewPlot:c}=H.useContext(Po);H.useState(null);const[a,d]=H.useState([]),[p,y]=H.useState(!1),[g,b]=H.useState(!1),w=()=>{i(!1),t()},S=M=>{console.log("handlePlotCreation data",M),b(!0),c(M).then(()=>{t(),Sc.success("Plot created successfully")}).catch(O=>{Sc.error("Could not create the plot")}).finally(()=>{b(!1),w()})};return H.useEffect(()=>{y(!0),Ng().then(M=>{d(M)}).finally(()=>{y(!1)})},[]),K.jsx(To,{trigger:n||K.jsx(Vn,{color:"primary",children:"Add New Plot"}),title:"Add New Plot",headerClassName:"m-4",open:r,setOpen:i,portalContainer:s!=null&&s.current?(C=s==null?void 0:s.current)==null?void 0:C.getMap().getContainer():document.body,children:K.jsx(xo,{children:K.jsx("div",{className:"h-[400px] overflow-y-auto",children:K.jsx(aP,{initialValues:{options:e},onSubmit:S,className:"p-4",submitButtonText:"Create Plot"})})})})},ASe=({feature:e,deleteFeature:t,trigger:n})=>{var p,y;const[r,i]=H.useState(!1);H.useContext(ii);const{addNewMarker:s}=H.useContext(Ns),c={longitude:(p=e==null?void 0:e.geometry)==null?void 0:p.coordinates[0],latitude:(y=e==null?void 0:e.geometry)==null?void 0:y.coordinates[1]};console.log("feature",e);const a=()=>{t(),i(!1)},d=g=>{s(g),t(),a()};return console.log("initialValues",c),K.jsx(To,{trigger:n||K.jsxs(yo,{color:"primary",children:[K.jsx(xG,{})," Add New Marker"]}),title:"Add New Marker",headerClassName:"m-4",description:"add a new marker to the map",open:r,setOpen:i,onClose:a,children:K.jsx(xo,{children:K.jsx(yT,{initialValues:c,onSubmit:d,onCancel:a})})})};function ESe(e){return vc({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 TSe(){const[e,t]=H.useState({});rn(C=>C.setViewMode),rn(C=>C.viewMode);const[n,r]=H.useState(),[i,s]=H.useState([]),{drawRef:c,mapRef:a,showDrawActionPopup:d,setShowDrawActionPopup:p}=H.useContext(ii),y=Jh.constants;y.classes.CONTROL_BASE="maplibregl-ctrl",y.classes.CONTROL_PREFIX="maplibregl-ctrl-",y.classes.CONTROL_GROUP="maplibregl-ctrl-group";const g=H.useCallback(C=>{console.log("onCreate"),t(M=>{const O={...M};for(const T of C.features)O[T.id]=T;return O})},[]),b=g;Eu(()=>{const C=new Jh({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 c.current=C,C},({map:C})=>{C.on("draw.create",g),C.on("draw.update",b)},({map:C})=>{C.off("draw.create",g),C.off("draw.update",b)},{position:"top-right"});const w=C=>{console.log("mode changed",C.mode),r(C.mode)},S=C=>{console.log("selection changed",C);const M=c.current.getSelected();s(M),p(M.features.length>0)};return H.useEffect(()=>{const C=a.current.getMap();return C.on("draw.modechange",w),C.on("draw.selectionchange",S),()=>{C.off("draw.modechange",w),C.off("draw.selectionchange",S)}},[c]),null}const ISe=()=>{const e=rn(r=>r.viewMode),t=rn(r=>r.cursorCords),n=rn(r=>r.hoveredValue);return K.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:[K.jsxs("span",{children:["mode: ",e]}),K.jsxs("span",{children:[n&&K.jsxs("span",{children:[K.jsxs("span",{children:[n.label,":",(n==null?void 0:n.value)&&n.value]}),K.jsx("div",{style:{width:10,height:10,backgroundColor:n.color,display:"inline-block"}})]})," ",K.jsx("span",{children:`${t[0].toFixed(6)}, ${t[1].toFixed(6)}`})]})]})};var cS="Tabs",[PSe,wEe]=_o(cS,[pg]),LN=pg(),[OSe,uS]=PSe(cS),NN=Ne.forwardRef((e,t)=>{const{__scopeTabs:n,value:r,onValueChange:i,defaultValue:s,orientation:c="horizontal",dir:a,activationMode:d="automatic",...p}=e,y=xx(a),[g,b]=Nu({prop:r,onChange:i,defaultProp:s});return K.jsx(OSe,{scope:n,baseId:mc(),value:g,onValueChange:b,orientation:c,dir:y,activationMode:d,children:K.jsx(Ar.div,{dir:y,"data-orientation":c,...p,ref:t})})});NN.displayName=cS;var RN="TabsList",jN=Ne.forwardRef((e,t)=>{const{__scopeTabs:n,loop:r=!0,...i}=e,s=uS(RN,n),c=LN(n);return K.jsx(NA,{asChild:!0,...c,orientation:s.orientation,dir:s.dir,loop:r,children:K.jsx(Ar.div,{role:"tablist","aria-orientation":s.orientation,...i,ref:t})})});jN.displayName=RN;var BN="TabsTrigger",FN=Ne.forwardRef((e,t)=>{const{__scopeTabs:n,value:r,disabled:i=!1,...s}=e,c=uS(BN,n),a=LN(n),d=VN(c.baseId,r),p=GN(c.baseId,r),y=r===c.value;return K.jsx(RA,{asChild:!0,...a,focusable:!i,active:y,children:K.jsx(Ar.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:nr(e.onMouseDown,g=>{!i&&g.button===0&&g.ctrlKey===!1?c.onValueChange(r):g.preventDefault()}),onKeyDown:nr(e.onKeyDown,g=>{[" ","Enter"].includes(g.key)&&c.onValueChange(r)}),onFocus:nr(e.onFocus,()=>{const g=c.activationMode!=="manual";!y&&!i&&g&&c.onValueChange(r)})})})});FN.displayName=BN;var zN="TabsContent",$N=Ne.forwardRef((e,t)=>{const{__scopeTabs:n,value:r,forceMount:i,children:s,...c}=e,a=uS(zN,n),d=VN(a.baseId,r),p=GN(a.baseId,r),y=r===a.value,g=Ne.useRef(y);return Ne.useEffect(()=>{const b=requestAnimationFrame(()=>g.current=!1);return()=>cancelAnimationFrame(b)},[]),K.jsx(Fs,{present:i||y,children:({present:b})=>K.jsx(Ar.div,{"data-state":y?"active":"inactive","data-orientation":a.orientation,role:"tabpanel","aria-labelledby":d,hidden:!b,id:p,tabIndex:0,...c,ref:t,style:{...e.style,animationDuration:g.current?"0s":void 0},children:b&&s})})});$N.displayName=zN;function VN(e,t){return`${e}-trigger-${t}`}function GN(e,t){return`${e}-content-${t}`}var kSe=NN,WN=jN,UN=FN,HN=$N;const DSe=kSe,XN=Ne.forwardRef(({className:e,...t},n)=>K.jsx(WN,{ref:n,className:Nn("inline-flex h-10 items-center justify-center rounded-md bg-muted p-1 text-muted-foreground",e),...t}));XN.displayName=WN.displayName;const hS=Ne.forwardRef(({className:e,...t},n)=>K.jsx(UN,{ref:n,className:Nn("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}));hS.displayName=UN.displayName;const ZN=Ne.forwardRef(({className:e,...t},n)=>K.jsx(HN,{ref:n,className:Nn("mt-2 ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",e),...t}));ZN.displayName=HN.displayName;function YN({value:e,children:t}){return K.jsx(ZN,{value:e,children:t})}tn.arrayOf(tn.shape({id:tn.string.isRequired,title:tn.string.isRequired,icon:tn.node,content:tn.node.isRequired,tooltipText:tn.string})).isRequired,tn.string.isRequired,tn.func,tn.func;function LSe(e){return vc({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 NSe(){const{mapRef:e}=H.useContext(ii),t=rn(b=>b.pickerData),n=rn(b=>b.setPickerData),r=rn(b=>b.rasterLayer),[i,s]=H.useState(null),{dateRange:c}=H.useContext(Mf),[a,d]=H.useState(!1),[p,y]=H.useState(null);function g(b){d(!0),s(null);const w=t.coordinates,S=e.current.getMap(),C=S.getBounds(),M=S.project(w),O=S.getCanvas(),T={width:O.width,height:O.height},D=[C.getWest(),C.getSouth(),C.getEast(),C.getNorth()].join(","),N="https://d27s6pvwcjpmsu.cloudfront.net/geoserver/ne/wms",k=new URLSearchParams({service:"WMS",version:"1.1.1",request:"GetFeatureInfo",layers:"ne:et_data",query_layers:"ne:et_data",bbox:D,width:T.width,height:T.height,srs:"EPSG:4326",time:c.start.toISOString().split("T")[0],info_format:"application/json",x:Math.floor(M.x),y:Math.floor(M.y)}),L=`${N}?${k.toString()}`;return fetch(L).then(B=>{if(!B.ok)throw new Error(`HTTP error! status: ${B.status}`);return console.log("response is",B),B.json()}).then(B=>{var q,re,ie,$,Y;console.log("Received coverage data for point:",w),console.log("Data:",B,typeof B),((q=B==null?void 0:B.features)==null?void 0:q.length)>0&&(console.log((ie=(re=B==null?void 0:B.features[0])==null?void 0:re.properties)==null?void 0:ie.GRAY_INDEX),s((Y=($=B==null?void 0:B.features[0])==null?void 0:$.properties)==null?void 0:Y.GRAY_INDEX))}).catch(B=>(console.error("There was a problem with the fetch operation:",B.message),s("could not fetch data"),y("could not load ET value at point"),null)).finally(()=>{d(!1)})}return H.useEffect(()=>{t&&r.value==="ET"&&g()},[t,r,c]),t?K.jsx(K.Fragment,{children:K.jsx(To,{open:!0,setOpen:()=>n(null),title:"Area Details",headerClassName:"m-4",children:K.jsxs(DSe,{className:"flex flex-col w-full h-full overflow-y-hidden",defaultValue:"point",children:[K.jsxs(XN,{className:"grid w-full grid-cols-2","aria-label":"Manage your account",children:[K.jsxs(hS,{value:"point",tooltipText:"Point",children:[K.jsx(LSe,{className:"cursor-pointer"}),"  ",K.jsx("span",{children:"Point"})]}),(t==null?void 0:t.plot)&&K.jsxs(hS,{value:"plot",tooltipText:"Plot",children:[K.jsx(ESe,{className:"cursor-pointer"})," ",K.jsx("span",{children:"Plot"})]})]}),K.jsx("br",{}),K.jsxs(YN,{value:"point",children:[r.value==="3_NDVI"&&K.jsx(U2,{point:t.coordinates}),a?K.jsx(fs,{}):p?K.jsx("div",{className:"text-red ",children:"Could not load ET value"}):i&&K.jsxs("div",{className:"flex items-center justify-between w-full gap-2 rounded-md bg-zinc-100 dark:bg-zinc-800 p-2 ",children:[K.jsx("h4",{className:"scroll-m-20 text-xs font-medium tracking-tight",children:"ET value at this point"}),K.jsx("div",{className:"flex items-center space-x-2",children:K.jsx("span",{className:"text-xs text-gray-700 dark:text-gray-200 font-bold",children:i.toFixed(3)})})]})]}),(t==null?void 0:t.plot)&&K.jsx(YN,{value:"plot",children:K.jsx(U2,{plot:t.plot})})]})})}):null}(yR=rn.getState().configs)==null||yR.VITE_SENTINAL_HUB_WMTS_ID;function qN({layer:e,dateRange:t}){var a;const r=`https://services.sentinel-hub.com/ogc/wmts/${(a=rn.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=Zm.find(d=>d.value===e);return s&&(s!=null&&s.url)?`${s.url}&TIME=${i}`:`${r}&LAYER=${e}&TIME=${i}`}const RSe=()=>{const{dateRange:e,isVisible:t}=H.useContext(Mf),n=rn(b=>b.showCroppedImages),r=rn(b=>b.rasterLayer),[i,s]=H.useState(qN({layer:r.value,dateRange:{...e}})),[c,a]=H.useState(null),d=rn(b=>b.rasterOpacity),{current:p}=Tu(),y=p.getMap();H.useEffect(()=>{console.log("dateRange in useEffect layerUrl",e);const b=qN({layer:r.value,dateRange:{...e}});s(b)},[r,e]),H.useEffect(()=>{p&&(p!=null&&p.loaded())&&p.getLayer("plots-line-layer")?(console.log("order setting before id to plots-line-layer"),a("plots-line-layer")):(console.log("order setting before id to plots-line-layer"),a(null))},[p]);const g=H.useCallback(b=>{if(console.log("handleLayerOrder"),y.getLayer("plots-line-layer")&&y.getLayer("raster-layer")){const w=y.getLayersOrder();w.indexOf("plots-line-layer")<w.indexOf("raster-layer")&&(console.log("reordering layers"),y.moveLayer("raster-layer","plots-line-layer"))}},[p]);return H.useEffect(()=>(y&&y.on("styledata",g),()=>{y&&y.off("styledata",g)}),[p]),!t||!i||n?null:K.jsxs(K.Fragment,{children:[K.jsx(pM,{id:"raster-source",type:"raster",tiles:[i],tileSize:256,minzoom:10,maxzoom:21,children:K.jsx(Hb,{id:"raster-layer",type:"raster",source:"raster-source",paint:{"raster-opacity":d/100},beforeId:c||void 0})}),K.jsx(NSe,{})]})},jSe=[{color:"#004400",label:" (0.5 to 1.0)"},{color:"#0f540a",label:" (0.4 to 0.5)"},{color:"#216011",label:" (0.35 to 0.4)"},{color:"#306d1c",label:" (0.3 to 0.35)"},{color:"#3f7c23",label:" (0.25 to 0.3)"},{color:"#4f892d",label:" (0.2 to 0.25)"},{color:"#609635",label:" (0.15 to 0.2)"},{color:"#70a33f",label:" (0.1 to 0.15)"},{color:"#7fb247",label:" (0.05 to 0.1)"},{color:"#91bf51",label:" (0.025 to 0.05)"},{color:"#a3cc59",label:" (0.0 to 0.025)"},{color:"#bcb76b",label:" (-0.1 to 0.0)"},{color:"#ccc682",label:" (-0.2 to -0.1)"},{color:"#ddd89b",label:" (-0.25 to -0.2)"},{color:"#ede8b5",label:" (-0.3 to -0.25)"},{color:"#fff9cc",label:" (-0.35 to -0.3)"},{color:"#eaeaea",label:" (-0.4 to -0.35)"},{color:"#dbdbdb",label:" (-0.5 to -0.4)"},{color:"#bfbfbf",label:" (-0.6 to -0.5)"},{color:"#c0c0c0",label:" (-0.7 to -0.6)"},{color:"#0c0c0c",label:" (-1.0 to -0.7)"}],BSe=[{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"}],FSe=[{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"}],zSe=[{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"}],$Se=[{color:"#00008B",label:"Very Low (0.001)"},{color:"#0000FF",label:"Low (3)"},{color:"#00FF00",label:"Moderate (6)"},{color:"#FFA500",label:"High (9)"},{color:"#FF0000",label:"Very High (12)"}],VSe=()=>{const e=rn(i=>i.rasterLayer),t=rn(i=>i.pixelColor);console.log("colorLegend rasterLayer",e);let n;switch(e==null?void 0:e.value){case"3_NDVI":n=jSe;break;case"AGRICULTURE":n=BSe;break;case"2_FALSE_COLOR":n=FSe;break;case"5-MOISTURE-INDEX1":n=zSe;break;case"ET":n=$Se}if(!n)return null;const r=n.find(i=>i.color==t);return console.log("item",r),K.jsxs("div",{className:"legend",children:[K.jsx("h4",{children:e==null?void 0:e.value}),n.map((i,s)=>K.jsxs("div",{className:"legend-item",children:[K.jsx("span",{className:"legend-color",style:{backgroundColor:i.color}}),K.jsx("span",{children:i.label})]},s))]})};function JN(e){const[t,n,r]=e,i=Math.round(t).toString(16).padStart(2,"0"),s=Math.round(n).toString(16).padStart(2,"0"),c=Math.round(r).toString(16).padStart(2,"0");return`#${i}${s}${c}`}function GSe(e,t){return e==="NDVI_RAW"?{label:"NDVI",value:(t[1]/127.5-1).toFixed(2),color:JN(t)}:{label:"color",value:null,color:JN(t)}}function WSe(){const{current:e}=Tu(),t=e.getMap();H.useRef(null);const n=rn(M=>M.viewMode),r=rn(M=>M.toggleNormalPickerMode),i=rn(M=>M.toNormalMode),s=rn(M=>M.setPickerData),c=rn(M=>M.setCursorCords),a=rn(M=>M.setHoveredValue),d=rn(M=>M.rasterLayer),p=rn(M=>M.setCursor),y=rn(M=>M.resetCursor),g=rn(M=>M.rasterOpacity),b=rn(M=>M.setRasterOpacity),w=H.useCallback(()=>{console.log("back to currentOpacity",g),b(100)},[g,b]),S=M=>{t&&(n==="PICKER"?t.setPaintProperty("raster-layer","raster-opacity",1):w()),r()};H.useEffect(()=>{const M=O=>{O.key==="Escape"&&(w(),i())};return n==="PICKER"&&window.addEventListener("keydown",M),()=>{window.removeEventListener("keydown",M)}},[i,g,t,w,n]);const C=H.useCallback(M=>{let O={coordinates:M.lngLat};if(t.getLayer("plots-layer")){const T=t.queryRenderedFeatures(M.point,{layers:["plots-layer"]});T.length>0&&(O.plot=T[0])}console.log("setting picker data",O),s(O)},[t,s]);return H.useEffect(()=>(t&&n==="PICKER"&&t.on("click",C),()=>{t&&t.off("click",C)}),[t,n,s]),H.useEffect(()=>{const M=O=>{const{lng:T,lat:D}=O.lngLat;c([T,D])};return t&&t.on("mousemove",M),()=>{t&&t.off("mousemove",M)}},[t,c,n]),H.useEffect(()=>{const O=cy(T=>{const D=t.getCanvas(),N=t.painter.context.gl;if(!N){console.error("WebGL context is not available.");return}const k=new Uint8Array(4),L=window.devicePixelRatio||1,B=Math.floor(T.point.x*L),q=Math.floor(D.height-T.point.y*L);if(B<0||q<0||B>=D.width||q>=D.height){console.warn("Mouse is outside the canvas bounds");return}N.readPixels(B,q,1,1,N.RGBA,N.UNSIGNED_BYTE,k);const re=GSe(d==null?void 0:d.value,k);a(re)},100);return t&&n==="PICKER"&&(t!=null&&t.loaded)&&(console.log("Adding pixel event listener"),t.on("mousemove",O)),()=>{t&&t.off("mousemove",O)}},[t,n,a,d]),H.useEffect(()=>{n==="PICKER"?p("crosshair"):y()},[n]),K.jsx(Vn,{variant:"outline",size:"icon",title:"Activate picker mode","aria-label":"Activate picker mode",onClick:S,className:` ${n===Hn.PICKER?" bg-gray-200 dark:bg-gray-600":""}`,children:K.jsx(AF,{})})}function USe(){const{current:e}=Tu(),[t,n]=H.useState(!1);H.useRef(null);const{settings:r,setSettings:i}=H.useContext(Gd),[s,c]=H.useState(!1),a=rn(g=>g.setViewMode),d=rn(g=>g.viewMode),p=H.useCallback(()=>{n(g=>!g),i(g=>({...g,basemap:{...g.basemap,id:g.basemap.id==="basic"?"satellite":"basic"}}))},[i]),y=H.useCallback(()=>{if(!e)return;const g=e.getContainer();console.log("mapContainer",g),document.fullscreenElement?(document.exitFullscreen(),c(!1)):g.requestFullscreen?g.requestFullscreen():g.mozRequestFullScreen?g.mozRequestFullScreen():g.webkitRequestFullscreen?g.webkitRequestFullscreen():g.msRequestFullscreen&&g.msRequestFullscreen(),c(!0)},[e]);return d===Hn.ADD_PLOT||d===Hn.ADD_MARKER||d===Hn.EDIT_PLOT||d===Hn.EDIT_MARKER?null:K.jsx(K.Fragment,{children:K.jsxs("div",{className:" gap-1 flex flex-col",children:[e&&K.jsx(Vn,{variant:"outline",size:"icon","aria-label":"Change view mode",title:"Change view mode",onClick:p,children:r.basemap.id==="basic"?K.jsx(EF,{}):K.jsx(xF,{})}),K.jsx(Vn,{variant:"outline",size:"icon",onClick:y,children:s?K.jsx(wF,{}):K.jsx(_F,{})}),K.jsx(WSe,{}),K.jsx(Vn,{variant:"outline",size:"icon",title:"add new plot",onClick:()=>a(Hn.ADD_PLOT),children:K.jsx(bF,{})}),K.jsx(Vn,{variant:"outline",size:"icon",title:"add new station",onClick:()=>a(Hn.ADD_MARKER),children:K.jsx(MF,{})}),K.jsx(Vn,{variant:"outline",size:"icon",title:"add new farm",onClick:()=>a(d===Hn.ADD_NEW_FARM?Hn.NORMAL:Hn.ADD_NEW_FARM),children:K.jsx(TF,{})})]})})}const dS=768;function HSe(){const[e,t]=Ne.useState(void 0);return Ne.useEffect(()=>{const n=window.matchMedia(`(max-width: ${dS-1}px)`),r=()=>{t(window.innerWidth<dS)};return n.addEventListener("change",r),t(window.innerWidth<dS),()=>n.removeEventListener("change",r)},[]),!!e}const KN=Ne.forwardRef(({className:e,type:t,...n},r)=>K.jsx("input",{type:t,className:Nn("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:r,...n}));KN.displayName="Input";var XSe="Separator",QN="horizontal",ZSe=["horizontal","vertical"],eR=Ne.forwardRef((e,t)=>{const{decorative:n,orientation:r=QN,...i}=e,s=YSe(r)?r:QN,a=n?{role:"none"}:{"aria-orientation":s==="vertical"?s:void 0,role:"separator"};return K.jsx(Ar.div,{"data-orientation":s,...a,...i,ref:t})});eR.displayName=XSe;function YSe(e){return ZSe.includes(e)}var tR=eR;const nR=Ne.forwardRef(({className:e,orientation:t="horizontal",decorative:n=!0,...r},i)=>K.jsx(tR,{ref:i,decorative:n,orientation:t,className:Nn("shrink-0 bg-border",t==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",e),...r}));nR.displayName=tR.displayName;const qSe=d1,JSe=f1,rR=Ne.forwardRef(({className:e,...t},n)=>K.jsx(Wg,{className:Nn("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:n}));rR.displayName=Wg.displayName;const KSe=qx("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"}}),iR=Ne.forwardRef(({side:e="right",className:t,children:n,...r},i)=>K.jsxs(JSe,{children:[K.jsx(rR,{}),K.jsxs(Ug,{ref:i,className:Nn(KSe({side:e}),t),...r,children:[n,K.jsxs(p1,{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:[K.jsx(ml,{className:"h-4 w-4"}),K.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));iR.displayName=Ug.displayName;const QSe=Ne.forwardRef(({className:e,...t},n)=>K.jsx(Hg,{ref:n,className:Nn("text-lg font-semibold text-foreground",e),...t}));QSe.displayName=Hg.displayName;const eCe=Ne.forwardRef(({className:e,...t},n)=>K.jsx(Xg,{ref:n,className:Nn("text-sm text-muted-foreground",e),...t}));eCe.displayName=Xg.displayName;function aR({className:e,...t}){return K.jsx("div",{className:Nn("animate-pulse rounded-md bg-muted",e),...t})}const tCe=EA,nCe=TA,rCe=IA,sR=Ne.forwardRef(({className:e,sideOffset:t=4,...n},r)=>K.jsx(bx,{ref:r,sideOffset:t,className:Nn("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),...n}));sR.displayName=bx.displayName;const iCe="sidebar:state",aCe=60*60*24*7,sCe="16rem",oCe="18rem",lCe="3rem",cCe="b",oR=Ne.createContext(null);function y0(){const e=Ne.useContext(oR);if(!e)throw new Error("useSidebar must be used within a SidebarProvider.");return e}const lR=Ne.forwardRef(({defaultOpen:e=!0,open:t,onOpenChange:n,className:r,style:i,children:s,...c},a)=>{const d=HSe(),[p,y]=Ne.useState(!1),[g,b]=Ne.useState(e),w=t??g,S=Ne.useCallback(T=>{const D=typeof T=="function"?T(w):T;n?n(D):b(D),document.cookie=`${iCe}=${D}; path=/; max-age=${aCe}`},[n,w]),C=Ne.useCallback(()=>d?y(T=>!T):S(T=>!T),[d,S,y]);Ne.useEffect(()=>{const T=D=>{D.key===cCe&&(D.metaKey||D.ctrlKey)&&(D.preventDefault(),C())};return window.addEventListener("keydown",T),()=>window.removeEventListener("keydown",T)},[C]);const M=w?"expanded":"collapsed",O=Ne.useMemo(()=>({state:M,open:w,setOpen:S,isMobile:d,openMobile:p,setOpenMobile:y,toggleSidebar:C}),[M,w,S,d,p,y,C]);return K.jsx(oR.Provider,{value:O,children:K.jsx(tCe,{delayDuration:0,children:K.jsx("div",{style:{"--sidebar-width":sCe,"--sidebar-width-icon":lCe,...i},className:Nn("group/sidebar-wrapper flex min-h-svh w-full has-[[data-variant=inset]]:bg-sidebar",r),ref:a,...c,children:s})})})});lR.displayName="SidebarProvider";const uCe=Ne.forwardRef(({side:e="left",variant:t="sidebar",collapsible:n="offcanvas",className:r,children:i,...s},c)=>{const{isMobile:a,state:d,openMobile:p,setOpenMobile:y}=y0();return n==="none"?K.jsx("div",{className:Nn("flex w-[--sidebar-width] flex-col bg-sidebar text-sidebar-foreground",r),ref:c,...s,children:i}):a?K.jsx(qSe,{open:p,onOpenChange:y,...s,children:K.jsx(iR,{"data-sidebar":"sidebar","data-mobile":"true",className:"w-[--sidebar-width] bg-sidebar p-0 text-sidebar-foreground [&>button]:hidden",style:{"--sidebar-width":oCe},side:e,children:K.jsx("div",{className:"flex h-full w-full flex-col",children:i})})}):K.jsxs("div",{ref:c,className:"group peer hidden md:block text-sidebar-foreground","data-state":d,"data-collapsible":d==="collapsed"?n:"","data-variant":t,"data-side":e,children:[K.jsx("div",{className:Nn("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]")}),K.jsx("div",{className:Nn("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",r),...s,children:K.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})})]})});uCe.displayName="Sidebar";const hCe=Ne.forwardRef(({className:e,onClick:t,...n},r)=>{const{toggleSidebar:i}=y0();return K.jsxs(Vn,{ref:r,"data-sidebar":"trigger",variant:"ghost",size:"icon",className:Nn("h-7 w-7",e),onClick:s=>{t==null||t(s),i()},...n,children:[K.jsx(CF,{}),K.jsx("span",{className:"sr-only",children:"Toggle Sidebar"})]})});hCe.displayName="SidebarTrigger";const dCe=Ne.forwardRef(({className:e,...t},n)=>{const{toggleSidebar:r}=y0();return K.jsx("button",{ref:n,"data-sidebar":"rail","aria-label":"Toggle Sidebar",tabIndex:-1,onClick:r,title:"Toggle Sidebar",className:Nn("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})});dCe.displayName="SidebarRail";const fCe=Ne.forwardRef(({className:e,...t},n)=>K.jsx("main",{ref:n,className:Nn("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}));fCe.displayName="SidebarInset";const pCe=Ne.forwardRef(({className:e,...t},n)=>K.jsx(KN,{ref:n,"data-sidebar":"input",className:Nn("h-8 w-full bg-background shadow-none focus-visible:ring-2 focus-visible:ring-sidebar-ring",e),...t}));pCe.displayName="SidebarInput";const mCe=Ne.forwardRef(({className:e,...t},n)=>K.jsx("div",{ref:n,"data-sidebar":"header",className:Nn("flex flex-col gap-2 p-2",e),...t}));mCe.displayName="SidebarHeader";const gCe=Ne.forwardRef(({className:e,...t},n)=>K.jsx("div",{ref:n,"data-sidebar":"footer",className:Nn("flex flex-col gap-2 p-2",e),...t}));gCe.displayName="SidebarFooter";const yCe=Ne.forwardRef(({className:e,...t},n)=>K.jsx(nR,{ref:n,"data-sidebar":"separator",className:Nn("mx-2 w-auto bg-sidebar-border",e),...t}));yCe.displayName="SidebarSeparator";const vCe=Ne.forwardRef(({className:e,...t},n)=>K.jsx("div",{ref:n,"data-sidebar":"content",className:Nn("flex min-h-0 flex-1 flex-col gap-2 overflow-auto group-data-[collapsible=icon]:overflow-hidden",e),...t}));vCe.displayName="SidebarContent";const bCe=Ne.forwardRef(({className:e,...t},n)=>K.jsx("div",{ref:n,"data-sidebar":"group",className:Nn("relative flex w-full min-w-0 flex-col p-2",e),...t}));bCe.displayName="SidebarGroup";const xCe=Ne.forwardRef(({className:e,asChild:t=!1,...n},r)=>{const i=t?Ya:"div";return K.jsx(i,{ref:r,"data-sidebar":"group-label",className:Nn("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),...n})});xCe.displayName="SidebarGroupLabel";const _Ce=Ne.forwardRef(({className:e,asChild:t=!1,...n},r)=>{const i=t?Ya:"button";return K.jsx(i,{ref:r,"data-sidebar":"group-action",className:Nn("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),...n})});_Ce.displayName="SidebarGroupAction";const wCe=Ne.forwardRef(({className:e,...t},n)=>K.jsx("div",{ref:n,"data-sidebar":"group-content",className:Nn("w-full text-sm",e),...t}));wCe.displayName="SidebarGroupContent";const SCe=Ne.forwardRef(({className:e,...t},n)=>K.jsx("ul",{ref:n,"data-sidebar":"menu",className:Nn("flex w-full min-w-0 flex-col gap-1",e),...t}));SCe.displayName="SidebarMenu";const CCe=Ne.forwardRef(({className:e,...t},n)=>K.jsx("li",{ref:n,"data-sidebar":"menu-item",className:Nn("group/menu-item relative",e),...t}));CCe.displayName="SidebarMenuItem";const MCe=qx("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"}}),ACe=Ne.forwardRef(({asChild:e=!1,isActive:t=!1,variant:n="default",size:r="default",tooltip:i,className:s,...c},a)=>{const d=e?Ya:"button",{isMobile:p,state:y}=y0(),g=K.jsx(d,{ref:a,"data-sidebar":"menu-button","data-size":r,"data-active":t,className:Nn(MCe({variant:n,size:r}),s),...c});return i?(typeof i=="string"&&(i={children:i}),K.jsxs(nCe,{children:[K.jsx(rCe,{asChild:!0,children:g}),K.jsx(sR,{side:"right",align:"center",hidden:y!=="collapsed"||p,...i})]})):g});ACe.displayName="SidebarMenuButton";const ECe=Ne.forwardRef(({className:e,asChild:t=!1,showOnHover:n=!1,...r},i)=>{const s=t?Ya:"button";return K.jsx(s,{ref:i,"data-sidebar":"menu-action",className:Nn("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",n&&"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),...r})});ECe.displayName="SidebarMenuAction";const TCe=Ne.forwardRef(({className:e,...t},n)=>K.jsx("div",{ref:n,"data-sidebar":"menu-badge",className:Nn("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}));TCe.displayName="SidebarMenuBadge";const ICe=Ne.forwardRef(({className:e,showIcon:t=!1,...n},r)=>{const i=Ne.useMemo(()=>`${Math.floor(Math.random()*40)+50}%`,[]);return K.jsxs("div",{ref:r,"data-sidebar":"menu-skeleton",className:Nn("rounded-md h-8 flex gap-2 px-2 items-center",e),...n,children:[t&&K.jsx(aR,{className:"size-4 rounded-md","data-sidebar":"menu-skeleton-icon"}),K.jsx(aR,{className:"h-4 flex-1 max-w-[--skeleton-width]","data-sidebar":"menu-skeleton-text",style:{"--skeleton-width":i}})]})});ICe.displayName="SidebarMenuSkeleton";const PCe=Ne.forwardRef(({className:e,...t},n)=>K.jsx("ul",{ref:n,"data-sidebar":"menu-sub",className:Nn("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}));PCe.displayName="SidebarMenuSub";const OCe=Ne.forwardRef(({...e},t)=>K.jsx("li",{ref:t,...e}));OCe.displayName="SidebarMenuSubItem";const kCe=Ne.forwardRef(({asChild:e=!1,size:t="md",isActive:n,className:r,...i},s)=>{const c=e?Ya:"a";return K.jsx(c,{ref:s,"data-sidebar":"menu-sub-button","data-size":t,"data-active":n,className:Nn("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",r),...i})});kCe.displayName="SidebarMenuSubButton";function DCe(){const[e,t]=H.useState({}),n=rn(q=>q.setViewMode),r=rn(q=>q.viewMode),[i,s]=H.useState(),{editingPlot:c,handlePlotUpdate:a}=H.useContext(Po),[d,p]=H.useState(c==null?void 0:c.options),[y,g]=H.useState([]),{drawRef:b,showDrawActionPopup:w,setShowDrawActionPopup:S}=H.useContext(ii),C=b.current,{current:M}=Tu(),O=Jh.constants;O.classes.CONTROL_BASE="maplibregl-ctrl",O.classes.CONTROL_PREFIX="maplibregl-ctrl-",O.classes.CONTROL_GROUP="maplibregl-ctrl-group",H.useCallback(q=>{console.log("onCreate"),t(re=>{const ie={...re};for(const $ of q.features)ie[$.id]=$;return ie})},[]),H.useCallback(q=>{r in[Hn.EDIT_PLOT,Hn.EDIT_MARKER]&&n(Hn.NORMAL),t(re=>{const ie={...re};for(const $ of q.features)delete ie[$.id];return ie})},[]);const T=q=>{console.log("event features",q.features),console.log("editing plot",c),d&&a({...c,options:d}).then(()=>{console.log("mode",q.mode),C.deleteAll(),n(Hn.NORMAL)}).catch(re=>{console.error("error updating plot",re)})};H.useEffect(()=>{console.log("editingPlot changed",c)},[c]);const D=q=>{console.log("mode changed",q.mode),s(q.mode)},N=q=>{console.log("selection changed",q);const re=b.current.getSelected();g(re)},k=H.useCallback(q=>{console.log("handling draw change",q),q.features&&q.features.length>0?p(q.features[0]):p(null)},[c,a]),L=()=>{C.deleteAll(),n(Hn.NORMAL)},B=()=>{C.getSelectedIds(),C.trash()};return H.useEffect(()=>{const q=M.getMap();return q.on("draw.modechange",D),q.on("draw.selectionchange",N),()=>{q.off("draw.modechange",D),q.off("draw.selectionchange",N)}},[b]),H.useEffect(()=>{if(map&&C)return M.on("draw.update",k),()=>{M.off("draw.update",k)}},[M,C,k]),K.jsx(K.Fragment,{children:K.jsx("div",{className:"absolute top-0 right-0 m-2 ",children:K.jsxs("div",{className:" gap-1 flex flex-col",children:[K.jsx(Vn,{variant:"outline",size:"icon",onClick:L,children:K.jsx(ml,{})}),K.jsx(Vn,{variant:"outline",size:"icon",onClick:B,children:K.jsx(Zb,{})}),K.jsx(Vn,{variant:"outline",size:"icon",onClick:T,children:K.jsx(Xb,{})})]})})})}function LCe(){H.useState({});const e=rn(D=>D.setViewMode);rn(D=>D.viewMode);const[t,n]=H.useState(),[r,i]=H.useState({}),[s,c]=H.useState([]),{drawRef:a,showDrawActionPopup:d,setShowDrawActionPopup:p}=H.useContext(ii),y=a.current,{current:g}=Tu();H.useEffect(()=>{y.changeMode("draw_polygon")},[y]);const b=()=>{y&&y.delete(r.id),e(Hn.NORMAL)},w=D=>{console.log("mode changed",D.mode),n(D.mode)},S=D=>{console.log("selection changed",D);const N=a.current.getSelected();c(N)},C=D=>{console.log("delete event",D,y.getMode()),y.getAll().features.length===0&&y.getMode()==="simple_select"&&y.changeMode("draw_polygon")},M=H.useCallback(D=>{console.log("running plot shape change",D.features),console.log("handling draw change",D),D.features&&D.features.length>0&&i(D.features[0])},[]);H.useEffect(()=>{console.log("shape changed",r)},[r]);const O=()=>{y.deleteAll(),e(Hn.NORMAL)},T=()=>{y.getSelectedIds().length>0&&y.trash()};return H.useEffect(()=>{const D=g.getMap();return D.on("draw.modechange",w),D.on("draw.selectionchange",S),()=>{D.off("draw.modechange",w),D.off("draw.selectionchange",S)}},[a]),H.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]),K.jsx(K.Fragment,{children:K.jsx("div",{className:"absolute top-0 right-0 m-2 ",children:K.jsxs("div",{className:" gap-1 flex flex-col",children:[K.jsx(Vn,{variant:"outline",size:"icon",onClick:O,children:K.jsx(ml,{})}),K.jsx(Vn,{variant:"outline",size:"icon",onClick:T,children:K.jsx(Zb,{})}),K.jsx(MSe,{trigger:K.jsx(Vn,{variant:"outline",size:"icon",children:K.jsx(Xb,{})}),polygon:r,deleteFeature:b})]})})})}function NCe(){H.useState({});const e=rn(T=>T.setViewMode);rn(T=>T.viewMode);const[t,n]=H.useState(),[r,i]=H.useState({}),[s,c]=H.useState([]),{drawRef:a,showDrawActionPopup:d,setShowDrawActionPopup:p}=H.useContext(ii),y=a.current,{current:g}=Tu();H.useEffect(()=>{y.changeMode("draw_point")},[y]);const b=()=>{y&&y.delete(r.id),e(Hn.NORMAL)},w=T=>{console.log("mode changed",T.mode),n(T.mode)},S=T=>{console.log("selection changed",T);const D=a.current.getSelected();c(D)},C=H.useCallback(T=>{console.log("running plot shape change",T.features),console.log("handling draw change",T),T.features&&T.features.length>0&&i(T.features[0])},[]);H.useEffect(()=>{console.log("shape changed",r)},[r]);const M=()=>{y.deleteAll(),e(Hn.NORMAL)},O=()=>{y.getSelectedIds(),y.trash()};return H.useEffect(()=>{const T=g.getMap();return T.on("draw.modechange",w),T.on("draw.selectionchange",S),()=>{T.off("draw.modechange",w),T.off("draw.selectionchange",S)}},[a]),H.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]),K.jsx(K.Fragment,{children:K.jsx("div",{className:"absolute top-0 right-0 m-2 ",children:K.jsxs("div",{className:" gap-1 flex flex-col",children:[K.jsx(Vn,{variant:"outline",size:"icon",onClick:M,children:K.jsx(ml,{})}),K.jsx(Vn,{variant:"outline",size:"icon",onClick:O,children:K.jsx(Zb,{})}),K.jsx(ASe,{trigger:K.jsx(Vn,{variant:"outline",size:"icon",children:K.jsx(gs,{text:"add station",children:K.jsx(Xb,{})})}),feature:r,deleteFeature:b})]})})})}const RCe=()=>{var c;const[e,t]=H.useState(!0),{mapRef:n}=H.useContext(ii),r=rn(a=>a.setViewMode),i=()=>{console.log("closing modal"),r(Hn.NORMAL),t(!1)},s=a=>{wG(a.name,a.marker_set).then(d=>{console.log("farm created successfully"),Sc("Farm Has been created",{description:`name: ${a.name}`})}),i()};return K.jsx(To,{title:"Add New Farm",headerClassName:"m-4",open:e,setOpen:t,onChange:i,portalContainer:n!=null&&n.current?(c=n==null?void 0:n.current)==null?void 0:c.getMap().getContainer():document.body,children:K.jsx("div",{className:"h-[400px] overflow-y-auto",children:K.jsx(jCe,{onClose:i,onSubmit:s})})})};function jCe({onClose:e,onSubmit:t}){const n=H.useRef(),{markers:r,loading:i}=H.useContext(Ns),s=H.useMemo(()=>r.map(S=>({value:S.id,label:(S==null?void 0:S.name)||(S==null?void 0:S.title)||(S==null?void 0:S.label)})),[r]),[c,a]=H.useState(!1),[d,p]=H.useState(""),[y,g]=H.useState([]);let b=H.useMemo(()=>bc(y,s),[y,s]);const w=S=>{S.preventDefault(),t({name:d,marker_set:y})};return K.jsxs("form",{onSubmit:w,className:"p-4 flex flex-col h-full",ref:n,children:[K.jsx(Ri,{label:"Name:",children:K.jsx(Eo,{type:"text",name:"name",className:"w-full sm:max-w-[483px] max-w-[227px]",value:d,onChange:S=>p(S.target.value)})}),K.jsx(Ri,{label:"Markers:",children:K.jsx(Gs,{formRef:n,className:"w-full sm:max-w-[483px] max-w-[227px]",name:"marker_set",value:b,onChange:g,options:s,isMulti:!0,isClearable:!0,isLoading:i,isSearchable:!0,closeMenuOnSelect:!1})}),K.jsxs("div",{className:"mt-5 flex gap-2 mt-auto self-end",children:[K.jsx(Vn,{type:"cancel",variant:"outline",onClick:!c&&e,disabled:c,children:"Cancel"}),K.jsx(Vn,{type:"submit",color:"primary",children:"Add Farm"})]})]})}function BCe({style:e,requestHeaders:t,configs:n}){const{mapStyle:r,mapRef:i}=H.useContext(ii),s=PB(),c=rn(y=>y.viewMode),a=rn(y=>y.cursor),d=rn(y=>y.setRequestHeaders),p=rn(y=>y.setConfigs);return H.useEffect(()=>{d(t)},[t]),H.useEffect(()=>{p(n)},[]),s?K.jsx(lR,{children:K.jsx(gK,{children:K.jsxs(dF,{id:"myMap",ref:i,initialViewState:s,style:{width:"100%",height:"80vh",...e},mapStyle:typeof r=="string"?r:r.toJS(),attributionControl:!1,reuseMaps:!0,preserveDrawingBuffer:!0,cursor:a,children:[K.jsx(RSe,{}),K.jsx(BK,{}),K.jsx("div",{className:"absolute top-0 left-0"}),K.jsx("div",{className:"absolute top-0 right-0 m-2",style:{zIndex:2},children:K.jsx(USe,{})}),K.jsx(TSe,{}),c==Hn.EDIT_PLOT&&K.jsx(DCe,{}),c==Hn.ADD_PLOT&&K.jsx(LCe,{}),c==Hn.ADD_MARKER&&K.jsx(NCe,{}),c==Hn.ADD_NEW_FARM&&K.jsx(RCe,{}),K.jsx(L2e,{}),K.jsx(YK,{}),K.jsx(eQ,{}),K.jsx(G2e,{}),K.jsx(ISe,{}),c===Hn.PICKER&&K.jsx(VSe,{})]})})}):K.jsx(fs,{})}var FCe={},cR={};(function(e){function t(O){"@babel/helpers - typeof";return t=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},t(O)}Object.defineProperty(e,"__esModule",{value:!0}),e.default=void 0;var n=s(H),r=["dispose","reject","resolve"];function i(O){if(typeof WeakMap!="function")return null;var T=new WeakMap,D=new WeakMap;return(i=function(k){return k?D:T})(O)}function s(O,T){if(O&&O.__esModule)return O;if(O===null||t(O)!=="object"&&typeof O!="function")return{default:O};var D=i(T);if(D&&D.has(O))return D.get(O);var N={},k=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var L in O)if(L!=="default"&&Object.prototype.hasOwnProperty.call(O,L)){var B=k?Object.getOwnPropertyDescriptor(O,L):null;B&&(B.get||B.set)?Object.defineProperty(N,L,B):N[L]=O[L]}return N.default=O,D&&D.set(O,N),N}function c(){return c=Object.assign||function(O){for(var T=1;T<arguments.length;T++){var D=arguments[T];for(var N in D)Object.prototype.hasOwnProperty.call(D,N)&&(O[N]=D[N])}return O},c.apply(this,arguments)}function a(O,T){return b(O)||g(O,T)||p(O,T)||d()}function d(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
989
989
  In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function p(O,T){if(O){if(typeof O=="string")return y(O,T);var D=Object.prototype.toString.call(O).slice(8,-1);if(D==="Object"&&O.constructor&&(D=O.constructor.name),D==="Map"||D==="Set")return Array.from(O);if(D==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(D))return y(O,T)}}function y(O,T){(T==null||T>O.length)&&(T=O.length);for(var D=0,N=new Array(T);D<T;D++)N[D]=O[D];return N}function g(O,T){var D=O==null?null:typeof Symbol<"u"&&O[Symbol.iterator]||O["@@iterator"];if(D!=null){var N=[],k=!0,L=!1,B,q;try{for(D=D.call(O);!(k=(B=D.next()).done)&&(N.push(B.value),!(T&&N.length===T));k=!0);}catch(re){L=!0,q=re}finally{try{!k&&D.return!=null&&D.return()}finally{if(L)throw q}}return N}}function b(O){if(Array.isArray(O))return O}function w(O,T){if(O==null)return{};var D=S(O,T),N,k;if(Object.getOwnPropertySymbols){var L=Object.getOwnPropertySymbols(O);for(k=0;k<L.length;k++)N=L[k],!(T.indexOf(N)>=0)&&Object.prototype.propertyIsEnumerable.call(O,N)&&(D[N]=O[N])}return D}function S(O,T){if(O==null)return{};var D={},N=Object.keys(O),k,L;for(L=0;L<N.length;L++)k=N[L],!(T.indexOf(k)>=0)&&(D[k]=O[k]);return D}var C=function(T){return function(D){var N=D.dispose,k=D.reject,L=D.resolve,B=w(D,r),q=(0,n.useState)(!0),re=a(q,2),ie=re[0],$=re[1],Y=function(){$(!1),N()},G=function(Z){$(!1),k(Z)},j=function(Z){$(!1),L(Z)};return n.default.createElement(T,c({cancel:G,dismiss:Y,proceed:j,show:ie},B))}},M=C;e.default=M})(cR);var uR={},v0={},Gp={},Wp=Ma;if(process.env.NODE_ENV==="production")Gp.createRoot=Wp.createRoot,Gp.hydrateRoot=Wp.hydrateRoot;else{var b0=Wp.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;Gp.createRoot=function(e,t){b0.usingClientEntryPoint=!0;try{return Wp.createRoot(e,t)}finally{b0.usingClientEntryPoint=!1}},Gp.hydrateRoot=function(e,t,n){b0.usingClientEntryPoint=!0;try{return Wp.hydrateRoot(e,t,n)}finally{b0.usingClientEntryPoint=!1}}}Object.defineProperty(v0,"__esModule",{value:!0}),v0.createDomTreeMounter=GCe;var zCe=VCe(H),$Ce=Gp;function VCe(e){return e&&e.__esModule?e:{default:e}}function GCe(e){var t={},n={};function r(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,$Ce.createRoot)(p);return y.render(zCe.default.createElement(s,c)),n.mounted&&n.mounted(),d}function i(s){var c=t[s];delete t[s],c&&c.parentNode&&c.parentNode.removeChild(c)}return{mount:r,unmount:i,options:{}}}(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.default=e.createConfirmationCreater=void 0;var t=v0;function n(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 r(a){for(var d=1;d<arguments.length;d++){var p=arguments[d]!=null?arguments[d]:{};d%2?n(Object(p),!0).forEach(function(y){i(a,y,p[y])}):Object.getOwnPropertyDescriptors?Object.defineProperties(a,Object.getOwnPropertyDescriptors(p)):n(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(b){var w,S=new Promise(function(M,O){try{w=d.mount(p,r({reject:O,resolve:M,dispose:C},b),g)}catch(T){throw console.error(T),T}});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})(uR);var x0={};function fS(e){"@babel/helpers - typeof";return fS=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},fS(e)}Object.defineProperty(x0,"__esModule",{value:!0}),x0.createMountPoint=eMe,x0.createReactTreeMounter=QCe;var Up=UCe(H),WCe=Ma;function hR(e){if(typeof WeakMap!="function")return null;var t=new WeakMap,n=new WeakMap;return(hR=function(i){return i?n:t})(e)}function UCe(e,t){if(e&&e.__esModule)return e;if(e===null||fS(e)!=="object"&&typeof e!="function")return{default:e};var n=hR(t);if(n&&n.has(e))return n.get(e);var r={},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(r,s,c):r[s]=e[s]}return r.default=e,n&&n.set(e,r),r}function pS(){return pS=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},pS.apply(this,arguments)}function dR(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(i){return Object.getOwnPropertyDescriptor(e,i).enumerable})),n.push.apply(n,r)}return n}function HCe(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]!=null?arguments[t]:{};t%2?dR(Object(n),!0).forEach(function(r){XCe(e,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):dR(Object(n)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(n,r))})}return e}function XCe(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function ZCe(e,t){return KCe(e)||JCe(e,t)||qCe(e,t)||YCe()}function YCe(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
990
990
  In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function qCe(e,t){if(e){if(typeof e=="string")return fR(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if(n==="Object"&&e.constructor&&(n=e.constructor.name),n==="Map"||n==="Set")return Array.from(e);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return fR(e,t)}}function fR(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function JCe(e,t){var n=e==null?null:typeof Symbol<"u"&&e[Symbol.iterator]||e["@@iterator"];if(n!=null){var r=[],i=!0,s=!1,c,a;try{for(n=n.call(e);!(i=(c=n.next()).done)&&(r.push(c.value),!(t&&r.length===t));i=!0);}catch(d){s=!0,a=d}finally{try{!i&&n.return!=null&&n.return()}finally{if(s)throw a}}return r}}function KCe(e){if(Array.isArray(e))return e}function QCe(e){var t={},n={};function r(c,a){var d=Math.floor(Math.random()*1073741824).toString(16);return t[d]={Component:c,props:a},n.mounted&&n.mounted(t),d}function i(c){delete t[c],n.mounted&&n.mounted(t)}function s(c){n.mounted=c}return{mount:r,unmount:i,options:{setMountedCallback:s,mountNode:e}}}function eMe(e){return function(){var t=(0,Up.useState)({}),n=ZCe(t,2),r=n[0],i=n[1];(0,Up.useEffect)(function(){return e.options.setMountedCallback(function(c){i(HCe({},c))})},[]);var s=Up.default.createElement(Up.default.Fragment,null,Object.keys(r).map(function(c){var a=r[c],d=a.Component,p=a.props;return Up.default.createElement(d,pS({key:c},p))}));return e.options.mountNode&&(s=(0,WCe.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 n.default}}),Object.defineProperty(e,"createConfirmation",{enumerable:!0,get:function(){return r.default}}),Object.defineProperty(e,"createConfirmationCreater",{enumerable:!0,get:function(){return r.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 n=d(cR),r=a(uR),i=v0,s=x0;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 b={},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(b,S,C):b[S]=p[S]}return b.default=p,g&&g.set(p,b),b}function d(p){return p&&p.__esModule?p:{default:p}}})(FCe);const tMe=H.forwardRef(({onClose:e,...t},n)=>K.jsx(Vn,{ref:n,variant:"outline",size:"icon",onClick:e,...t,children:K.jsx(ml,{className:"w-5 h-5 action-icon"})})),pR=()=>{const{prompt:e="",isOpen:t=!0,proceed:n,cancel:r}=af(),i=()=>{r()};return K.jsx(d1,{open:t,onOpenChange:s=>{s||i()},children:K.jsxs(f1,{children:[K.jsx(Wg,{className:"fixed inset-0 bg-black opacity-30 z-20"}),K.jsxs(Ug,{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:[K.jsx(Hg,{className:"text-lg font-bold dark:text-gray-200",children:"Warning"}),K.jsx(Xg,{className:"mt-2 text-sm text-gray-600 dark:text-gray-200",children:e}),K.jsxs("div",{className:"mt-4 flex justify-end space-x-2",children:[K.jsx(Vn,{variant:"outline",onClick:r,children:"Cancel"}),K.jsx(Vn,{variant:"destructive",onClick:()=>n(!0),children:"delete"})]}),K.jsx(p1,{asChild:!0,children:K.jsx(tMe,{className:"absolute top-2 right-2"})})]})]})})};pR.propTypes={show:tn.bool,proceed:tn.func,confirmation:tn.string,options:tn.object};const nMe=H.createContext();function rMe({children:e,defaultTheme:t="system",storageKey:n="vite-ui-theme",...r}){const[i,s]=H.useState(()=>localStorage.getItem(n)||t);H.useEffect(()=>{const a=document.documentElement;if(a.classList.remove("light","dark"),i==="system"&&a){const d=window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light";a.classList.add(d)}else a.classList.add(i)},[i]),H.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:i,setTheme:a=>{localStorage.setItem(n,a),s(a)}};return K.jsx(nMe.Provider,{value:c,...r,children:e})}var iMe=(e,t,n,r,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(O=>s[O]||O):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 b(){return window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}if(r)y(r);else try{let w=localStorage.getItem(t)||n,S=c&&w==="system"?b():w;y(S)}catch{}},aMe=Ne.createContext(void 0),sMe={setTheme:e=>{},themes:[]},oMe=()=>{var e;return(e=Ne.useContext(aMe))!=null?e:sMe};Ne.memo(({forcedTheme:e,storageKey:t,attribute:n,enableSystem:r,enableColorScheme:i,defaultTheme:s,value:c,themes:a,nonce:d,scriptProps:p})=>{let y=JSON.stringify([n,t,s,e,a,c,r,i]).slice(1,-1);return Ne.createElement("script",{...p,suppressHydrationWarning:!0,nonce:typeof window>"u"?d:"",dangerouslySetInnerHTML:{__html:`(${iMe.toString()})(${y})`}})});const lMe=({...e})=>{const{theme:t="system"}=oMe();return K.jsx(hY,{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 cMe({style:e,requestHeaders:t,configs:n,markers:r}){return K.jsx(rMe,{defaultTheme:"system",children:K.jsx(EA,{delayDuration:200,children:K.jsx(OB,{children:K.jsx(L7,{children:K.jsx(rM,{configs:n,children:K.jsx(vY,{children:K.jsx(rP,{children:K.jsx(kM,{providedMarkers:r,children:K.jsxs(Yx,{children:[K.jsx(BCe,{style:e,requestHeaders:t,configs:n}),K.jsx(lMe,{richColors:!0}),K.jsx(pR,{})]})})})})})})})})})}ua.AgvMap=cMe,Object.defineProperty(ua,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agvmap-react",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "type": "module",
5
5
  "main": "dist/agvmap-react.umd.cjs",
6
6
  "module": "dist/agvmap-react.js",