agviewermap-react 0.1.37-2 → 0.1.37-3

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.
@@ -1330,6 +1330,6 @@ For more information, see https://radix-ui.com/primitives/docs/components/alert-
1330
1330
  <b>${this.point.ndviRange}</b><br/>
1331
1331
  Pixel Count: ${this.point.y.toLocaleString()}<br/>
1332
1332
  NDVI Value: ${this.point.ndviValue.toFixed(2)}
1333
- `}},plotOptions:{column:{dataLabels:{enabled:!1},borderWidth:0,groupPadding:.1,pointPadding:.05}},series:[{name:"Pixel Count",data:r}],credits:{enabled:!1},legend:{enabled:!1}};return I.jsx(Sg,{highcharts:mo,options:n})}const tw=new Map,IGe=async e=>{var r,n,i;const t=e.id||((r=e.options)==null?void 0:r.id)||((i=(n=e.options)==null?void 0:n.properties)==null?void 0:i.id);if(tw.has(t))return tw.get(t);try{const a=await khe({stationId:e==null?void 0:e.device,plotId:t});return tw.set(t,a),a}catch{return null}},PGe=(e,t,r)=>{const[n,i]=j.useState(!1);return j.useRef(new Set),zt(a=>a.passDates),zt(a=>a.hoveredFarmId),j.useCallback(()=>{if(!(e!=null&&e.current)||!t||t.length===0)return[];const a=e.current.getMap();if(!a)return[];const o=a.getBounds();return o?t.filter(s=>{var T;if(!((T=s==null?void 0:s.options)!=null&&T.geometry))return!1;const u=Zl(s.options.geometry),[h,f,m,g]=u,[[v,b],[x,w]]=o.toArray();return!(h>x||m<v||f>w||g<b)}):[]},[t,e]),j.useCallback((a,o)=>!a||!o||o.length===0?[]:o.filter(s=>{var f,m;const u=(s==null?void 0:s.farm)||((m=(f=s==null?void 0:s.options)==null?void 0:f.properties)==null?void 0:m.farm);return u?(typeof u=="object"?u==null?void 0:u.id:u)==a:!1}),[]),j.useCallback(async a=>{if(!a||a.length===0)return;const o=a.filter(s=>{var h,f,m;const u=s.id||((h=s.options)==null?void 0:h.id)||((m=(f=s.options)==null?void 0:f.properties)==null?void 0:m.id);return!tw.has(u)});o.length!==0&&await Promise.allSettled(o.map(s=>IGe(s)))},[]),j.useCallback(async()=>{},[]),{prefetching:n}},TW=new Map,OGe=e=>{const t=new Date(e);return`${t.getFullYear()}-${String(t.getMonth()+1).padStart(2,"0")}`},AW=(e,t)=>{var i,a,o;const r=e.id||((i=e.options)==null?void 0:i.id)||((o=(a=e.options)==null?void 0:a.properties)==null?void 0:o.id),n=OGe(t);return`${r}_${n}`},kGe=(e,t)=>{if(!e||!t)return null;const r=AW(e,t);return TW.get(r)||null},DGe=(e,t,r)=>{if(!e||!t||!r)return;const n=AW(e,t);TW.set(n,r)},rw=[[-.5,12,12,12],[-.2,191,191,191],[-.1,219,219,219],[0,234,234,234],[.025,255,249,204],[.05,237,232,181],[.075,221,216,155],[.1,204,198,130],[.125,188,183,107],[.15,175,193,96],[.175,163,204,89],[.2,145,191,81],[.25,127,178,71],[.3,112,163,63],[.35,96,150,53],[.4,79,137,45],[.45,63,124,35],[.5,48,109,28],[.55,33,96,17],[.6,15,84,10],[1,0,68,0]];function NGe(e,t,r){let n=0,i=1/0;for(let a=0;a<rw.length-1;a++){const[o,s,u,h]=rw[a],[f,m,g,v]=rw[a+1],b=m-s,x=g-u,w=v-h,T=b*b+x*x+w*w;let C;T<1e-12?C=0:(C=((e-s)*b+(t-u)*x+(r-h)*w)/T,C<0&&(C=0),C>1&&(C=1));const M=s+C*b,O=u+C*x,P=h+C*w,k=(e-M)*(e-M)+(t-O)*(t-O)+(r-P)*(r-P);k<i&&(i=k,n=o+C*(f-o))}{const[a,o,s,u]=rw[0],h=(e-o)*(e-o)+(t-s)*(t-s)+(r-u)*(r-u);h<i&&(i=h,n=a)}return n}async function LGe({mapRef:e,plot:t,startDate:r,endDate:n,bins:i=32}){var ve,ce;if(!(e!=null&&e.current)||!((ve=t==null?void 0:t.options)!=null&&ve.geometry))return null;const a=e.current.getMap();if(!a)return null;const o=a.getCanvas();if(!o)return null;const s=document.createElement("canvas");s.width=o.width,s.height=o.height;const u=s.getContext("2d");try{u.drawImage(o,0,0)}catch{return null}const h=t.options.geometry;if(!h)return null;const f=h.type==="Polygon"?[h.coordinates]:h.coordinates||[],m=(ce=a.getContainer)==null?void 0:ce.call(a),g=(m==null?void 0:m.clientWidth)||o.clientWidth||o.width,v=(m==null?void 0:m.clientHeight)||o.clientHeight||o.height,b=g>0?o.width/g:1,x=v>0?o.height/v:1,w=f.map(q=>q.map(se=>se.map(([he,be])=>{const Ae=a.project({lng:he,lat:be});return[Math.round(Ae.x*b),Math.round(Ae.y*x)]})));function T(q,se,he){let be=!1;for(let Ae=0,le=he.length-1;Ae<he.length;le=Ae++){const K=he[Ae][0],ue=he[Ae][1],ge=he[le][0],Y=he[le][1];ue>se!=Y>se&&q<(ge-K)*(se-ue)/(Y-ue+0)+K&&(be=!be)}return be}const C=s.width,M=s.height;let O=C,P=M,k=0,D=0;if(w.forEach(q=>q.forEach(se=>se.forEach(([he,be])=>{O=Math.max(0,Math.min(O,he)),P=Math.max(0,Math.min(P,be)),k=Math.min(C-1,Math.max(k,he)),D=Math.min(M-1,Math.max(D,be))}))),O>k||P>D)return null;O=Math.floor(O),P=Math.floor(P),k=Math.ceil(k),D=Math.ceil(D);let V;try{V=u.getImageData(O,P,k-O+1,D-P+1).data}catch{return null}const U=new Array(i).fill(0),X=-1,W=(1-X)/i,H=k-O+1,G=D-P+1;for(let q=0;q<G;q++)for(let se=0;se<H;se++){const he=se+O,be=q+P;let Ae=!1;for(const Me of w){for(const ye of Me)if(T(he,be,ye)){Ae=!0;break}if(Ae)break}if(!Ae)continue;const le=(q*H+se)*4,K=V[le],ue=V[le+1],ge=V[le+2];if(V[le+3]===0)continue;const xe=NGe(K,ue,ge);let pe=Math.floor((xe-X)/W);pe<0&&(pe=0),pe>=i&&(pe=i-1),U[pe]+=1}if(U.reduce((q,se)=>q+se,0)===0)return null;const Z=new Array(i).fill(0).map((q,se)=>({lowEdge:X+se*W,highEdge:X+(se+1)*W}));let Q=0;for(;Q<i&&U[Q]===0;)Q++;let ae=i-1;for(;ae>=Q&&U[ae]===0;)ae--;const oe=Z.slice(Q,ae+1),te=U.slice(Q,ae+1);return te.some(q=>q>0)?{data:[{interval:{from:r instanceof Date?r.toISOString():new Date(r).toISOString(),to:n instanceof Date?n.toISOString():new Date(n).toISOString()},outputs:{index:{bands:{B0:{histogram:{bins:oe,counts:te}}}}}}]}:null}function MW({mapRef:e,EnableSentinalHistogram:t=!1}){var ae,oe;const r=Kn(),{plots:n,setClickedPlot:i}=j.useContext(xs),{accessToken:a}=j.useContext(G0),o=zt(te=>te.dateRange),s=zt(te=>te.setPickerData),u=zt(te=>te.setHoveredPlot),h=zt(te=>te.rasterLayer),f=zt(te=>te.viewMode),m=zt(te=>te.rasterLayerLoading),{isRasterVisible:g}=j.useContext(yp),[v,b]=j.useState(null),[x,w]=j.useState(null),[T,C]=j.useState(null),[M,O]=j.useState(null),[P,k]=j.useState(!1),[D,V]=j.useState(!1),[U,X]=j.useState("local");j.useEffect(()=>{!t&&U!=="local"&&X("local")},[t,U]),PGe(e,n),j.useEffect(()=>{if(!(e!=null&&e.current)||!v||f!==Xr.NORMAL)return;const te=e.current.getMap();if(!te)return;const ve=`plot-highlight-${v.id}`,ce=`plot-highlight-outline-${v.id}`,q=`plot-highlight-source-${v.id}`;return te.getLayer(ve)&&te.removeLayer(ve),te.getLayer(ce)&&te.removeLayer(ce),te.getSource(q)&&te.removeSource(q),te.addSource(q,{type:"geojson",data:v.options.geometry}),te.addLayer({id:ce,type:"line",source:q,layout:{"line-cap":"round","line-join":"round"},paint:{"line-color":"#ffffff","line-width":4,"line-opacity":1}}),te.addLayer({id:ve,type:"line",source:q,layout:{"line-cap":"round","line-join":"round"},paint:{"line-color":"#16a34a","line-width":6,"line-opacity":1}},ce),()=>{te.getLayer(ve)&&te.removeLayer(ve),te.getLayer(ce)&&te.removeLayer(ce),te.getSource(q)&&te.removeSource(q)}},[v,e]),j.useEffect(()=>{if(!(e!=null&&e.current))return;const te=e.current.getMap();if(!te)return;const ve=q=>{var he,be,Ae;if(!te.getLayer("plots-layer"))return;const se=te.queryRenderedFeatures(q.point,{layers:["plots-layer"]});if(se.length>0){const le=se[0],K=((he=le.properties)==null?void 0:he.plot_id)||((be=le.properties)==null?void 0:be.plotId);let ue=K?n.find(ge=>ge.id===K):null;if(!ue&&((Ae=le.properties)!=null&&Ae.id)&&(ue=n.find(ge=>{var Y;return((Y=ge.options)==null?void 0:Y.id)===le.properties.id})),ue&&ue.id!==(v==null?void 0:v.id)){b(ue),u(ue),i(null);const ge=zt.getState().pickerData;ge!=null&&ge.plot||s(null)}}},ce=q=>{te.queryRenderedFeatures(q.point,{layers:["plots-layer"]}).length===0&&(b(null),u(null))};return te.on("mousemove",ve),te.on("click",ce),()=>{te.off("mousemove",ve),te.off("click",ce)}},[n,e,v,i,s,u]);const z=j.useCallback(te=>new Date(te).toISOString().split("T")[0],[]),W=j.useCallback((te,ve)=>{if(!te||te.length===0)return null;const ce=z(ve),q=te.find(Ae=>z(Ae.interval.from)===ce);if(q)return q;const se=new Date(ve).getTime();let he=null,be=1/0;return te.forEach(Ae=>{const le=new Date(Ae.interval.from).getTime(),K=Math.abs(le-se);K<be&&(be=K,he=Ae)}),he},[z]);j.useEffect(()=>{if(h.value==="ET"){w(null),C(null),k(!1);return}if(!v||!a||!(o!=null&&o.start)){w(null),C(null),k(!1);return}let te=!1;return(async()=>{var ce;V(!0),k(!0);try{const q=new Date(o.start),se=CD(q),he=ED(q),be=new Date(Date.UTC(se.getFullYear(),se.getMonth(),se.getDate(),0,0,0,0)),Ae=new Date(Date.UTC(he.getFullYear(),he.getMonth(),he.getDate(),23,59,59,999));let le=null;try{const K=(ce=e==null?void 0:e.current)==null?void 0:ce.getMap();K&&K.getLayer&&K.getLayer(`croppedImageLayer-${v.options.id}`)?m?(le=null,O("Raster tiles are still loading"),k(!0)):(le=await LGe({mapRef:e,plot:v,startDate:be,endDate:Ae,bins:32}),O(le?null:"Local histogram unavailable (canvas may be tainted or tiles use a color ramp)"),k(!1)):(le=null,O("Raster layer not present in current map style"),k(!1))}catch{le=null,O("Local histogram computation error (see console)"),k(!1)}if(le&&le.data&&le.data.length>0){const K=W(le.data,q);C(K?[K]:null)}else C(null);if(k(!!m),t){let K=null;const ue=kGe(v,q);ue?K=ue:(K=await VO({plot:v,accessToken:a,startDate:be.toISOString(),endDate:Ae.toISOString()}),K&&DGe(v,q,K));const ge=K&&K.data?W(K.data,q):null;w(ge?[ge]:null)}else w(null)}catch{te||(w(null),k(!1))}finally{te||V(!1)}})(),()=>{te=!0}},[v==null?void 0:v.id,a,o==null?void 0:o.start,W,h.value,m]);const H=j.useMemo(()=>{var se,he,be,Ae,le;if(!(x!=null&&x.length))return null;const te=x[0],ve=(Ae=(be=(he=(se=te==null?void 0:te.outputs)==null?void 0:se.index)==null?void 0:he.bands)==null?void 0:be.B0)==null?void 0:Ae.histogram;if(!(ve!=null&&ve.bins))return null;const{bins:ce,counts:q}=ve;return!q&&((le=ce[0])==null?void 0:le.count)!==void 0?ce.map(K=>({ndviRange:`${K.lowEdge.toFixed(2)} - ${K.highEdge.toFixed(2)}`,ndviValue:(K.lowEdge+K.highEdge)/2,count:K.count||0,lowEdge:K.lowEdge,highEdge:K.highEdge})):!Array.isArray(q)||q.length!==ce.length?null:ce.map((K,ue)=>({ndviRange:`${K.lowEdge.toFixed(2)} - ${K.highEdge.toFixed(2)}`,ndviValue:(K.lowEdge+K.highEdge)/2,count:q[ue]||0,lowEdge:K.lowEdge,highEdge:K.highEdge}))},[x]),G=j.useMemo(()=>{var se,he,be,Ae,le;if(!(T!=null&&T.length))return null;const te=T[0],ve=(Ae=(be=(he=(se=te==null?void 0:te.outputs)==null?void 0:se.index)==null?void 0:he.bands)==null?void 0:be.B0)==null?void 0:Ae.histogram;if(!(ve!=null&&ve.bins))return null;const{bins:ce,counts:q}=ve;return!q&&((le=ce[0])==null?void 0:le.count)!==void 0?ce.map(K=>({ndviRange:`${K.lowEdge.toFixed(2)} - ${K.highEdge.toFixed(2)}`,ndviValue:(K.lowEdge+K.highEdge)/2,count:K.count||0,lowEdge:K.lowEdge,highEdge:K.highEdge})):!Array.isArray(q)||q.length!==ce.length?null:ce.map((K,ue)=>({ndviRange:`${K.lowEdge.toFixed(2)} - ${K.highEdge.toFixed(2)}`,ndviValue:(K.lowEdge+K.highEdge)/2,count:q[ue]||0,lowEdge:K.lowEdge,highEdge:K.highEdge}))},[T]),B=U==="local"?G:H,Z=U==="local"?P||m:D,Q=U==="local"?M||"No local histogram data available":"No Sentinel histogram data available";return!v||h.value==="ET"||f!==Xr.NORMAL||!g?null:I.jsxs("div",{className:`bg-white dark:bg-zinc-800 rounded-lg shadow-lg border border-gray-200 dark:border-gray-700 ${h.value==="ET"?"w-[500px]":"w-[320px]"}`,children:[I.jsxs("div",{className:"flex items-center justify-between px-3 py-2 border-b border-gray-200 dark:border-gray-700",children:[I.jsxs("div",{className:"flex items-center gap-2",children:[I.jsx(Ane,{className:"h-5 w-5 text-primary"}),I.jsxs("div",{children:[I.jsx("h4",{className:"text-sm font-semibold text-gray-900 dark:text-gray-100",children:h.value==="ET"?r.formatMessage({id:"app.agviewer_map.et_monthly_graph",defaultMessage:"ET Monthly Graph"}):r.formatMessage({id:"app.agviewer_map.ndvi_histogram",defaultMessage:"NDVI Histogram"})}),v&&I.jsx("p",{className:"text-xs text-gray-600 dark:text-gray-400",children:v.name||`Plot ${v.id}`}),!v&&I.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400 italic",children:r.formatMessage({id:"app.agviewer_map.hover_plot_histogram",defaultMessage:"Hover over a plot to view its histogram"})})]})]}),h.value!=="ET"&&t&&I.jsxs("div",{className:"flex items-center gap-1 bg-gray-100 dark:bg-zinc-700 rounded-md p-0.5",children:[I.jsx("button",{type:"button",onClick:()=>X("local"),className:`px-2 py-1 text-xs rounded-md transition ${U==="local"?"bg-white dark:bg-zinc-900 text-gray-900 dark:text-gray-100 shadow":"text-gray-600 dark:text-gray-300 hover:text-gray-900 dark:hover:text-gray-100"}`,children:"Local"}),I.jsx("button",{type:"button",onClick:()=>X("sentinel"),className:`px-2 py-1 text-xs rounded-md transition ${U==="sentinel"?"bg-white dark:bg-zinc-900 text-gray-900 dark:text-gray-100 shadow":"text-gray-600 dark:text-gray-300 hover:text-gray-900 dark:hover:text-gray-100"}`,children:"Sentinel"})]})]}),I.jsx("div",{className:"px-3 py-2",children:h.value==="ET"?null:I.jsx("div",{children:Z?I.jsx("div",{className:"flex items-center justify-center h-24",children:I.jsx(Ja,{})}):B?I.jsx(MGe,{data:B}):I.jsx("div",{className:"text-xs text-gray-500 dark:text-gray-400 italic",children:Q})})}),h.value!=="ET"&&B&&I.jsx("div",{className:"px-3 py-2 border-t border-gray-200 dark:border-gray-700 bg-gray-50 dark:bg-zinc-900/50",children:I.jsxs("div",{className:"grid grid-cols-2 gap-2 text-xs",children:[I.jsxs("div",{children:[I.jsxs("span",{className:"text-gray-600 dark:text-gray-400",children:[r.formatMessage({id:"app.agviewer_map.total_pixels",defaultMessage:"Total Pixels"}),":"]}),I.jsx("span",{className:"ml-2 font-semibold text-gray-900 dark:text-gray-100",children:B.reduce((te,ve)=>te+ve.count,0).toLocaleString()})]}),I.jsxs("div",{children:[I.jsxs("span",{className:"text-gray-600 dark:text-gray-400",children:[r.formatMessage({id:"app.agviewer_map.ndvi_range",defaultMessage:"NDVI Range"}),":"]}),I.jsxs("span",{className:"ml-2 font-semibold text-gray-900 dark:text-gray-100",children:[(ae=B[0])==null?void 0:ae.lowEdge.toFixed(2)," to"," ",(oe=B[B.length-1])==null?void 0:oe.highEdge.toFixed(2)]})]})]})}),h.value==="ET"&&v&&I.jsx("div",{className:"px-3 py-2 border-t border-gray-200 dark:border-gray-700 bg-gray-50 dark:bg-zinc-900/50",children:I.jsxs("div",{className:"text-xs text-gray-600 dark:text-gray-400",children:[I.jsxs("span",{className:"font-medium",children:[r.formatMessage({id:"app.agviewer_map.year",defaultMessage:"Year"}),":"]}),I.jsx("span",{className:"ml-2 font-semibold text-gray-900 dark:text-gray-100",children:new Date().getFullYear()})]})})]})}function FGe({isSearchFocused:e,searchQuery:t,searchResults:r,onResultClick:n}){return e?I.jsx("div",{className:"absolute top-full mt-1 left-0 right-0 sm:right-auto sm:w-64 bg-white backdrop-blur-xl rounded-md shadow-2xl border border-gray-200 overflow-hidden pointer-events-auto max-h-[400px] overflow-y-auto z-[1102]",children:I.jsx("div",{className:"p-2 space-y-1",children:t.trim()===""?I.jsxs(I.Fragment,{children:[I.jsx("div",{className:"px-2 py-1.5 text-[10px] font-bold text-muted-foreground uppercase tracking-wider",children:"Suggested"}),I.jsx("div",{className:"px-2 py-2 text-xs text-muted-foreground",children:"Start typing to search farms, plots, and stations..."})]}):r.length===0?I.jsx("div",{className:"px-2 py-4 text-xs text-muted-foreground text-center",children:"No results found"}):I.jsxs(I.Fragment,{children:[I.jsxs("div",{className:"px-2 py-1.5 text-[10px] font-bold text-muted-foreground uppercase tracking-wider",children:["Results (",r.length,")"]}),r.map(i=>I.jsxs("div",{className:"flex items-center gap-3 p-2 rounded-sm hover:bg-green-50/80 cursor-pointer transition-colors group",onClick:()=>n(i),children:[I.jsxs("div",{className:rr("w-8 h-8 rounded-sm flex items-center justify-center shrink-0",i.type==="farm"&&"bg-green-100 text-green-600",i.type==="plot"&&"bg-blue-100 text-blue-600",i.type==="station"&&"bg-orange-100 text-orange-600"),children:[i.type==="farm"&&I.jsx(NS,{className:"h-4 w-4"}),i.type==="plot"&&I.jsx(ug,{className:"h-4 w-4"}),i.type==="station"&&I.jsx(Zv,{className:"h-4 w-4"})]}),I.jsxs("div",{className:"flex flex-col min-w-0",children:[I.jsx("span",{className:"text-sm font-medium truncate text-foreground group-hover:text-green-700",children:i.label}),I.jsx("span",{className:"text-xs text-muted-foreground truncate",children:i.subLabel})]})]},i.id))]})})}):null}function Rp(e,t,{checkForDefaultPrevented:r=!0}={}){return function(i){if(e==null||e(i),r===!1||!i.defaultPrevented)return t==null?void 0:t(i)}}function RGe(e){const t=ie.useRef({value:e,previous:e});return ie.useMemo(()=>(t.current.value!==e&&(t.current.previous=t.current.value,t.current.value=e),t.current.previous),[e])}var IW=["PageUp","PageDown"],PW=["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"],OW={"from-left":["Home","PageDown","ArrowDown","ArrowLeft"],"from-right":["Home","PageDown","ArrowDown","ArrowRight"],"from-bottom":["Home","PageDown","ArrowDown","ArrowLeft"],"from-top":["Home","PageDown","ArrowUp","ArrowLeft"]},jp="Slider",[XI,jGe,BGe]=fG(jp),[kW,MYe]=rc(jp,[BGe]),[$Ge,nw]=kW(jp),DW=ie.forwardRef((e,t)=>{const{name:r,min:n=0,max:i=100,step:a=1,orientation:o="horizontal",disabled:s=!1,minStepsBetweenThumbs:u=0,defaultValue:h=[n],value:f,onValueChange:m=()=>{},onValueCommit:g=()=>{},inverted:v=!1,form:b,...x}=e,w=ie.useRef(new Set),T=ie.useRef(0),M=o==="horizontal"?zGe:VGe,[O=[],P]=lf({prop:f,defaultProp:h,onChange:z=>{var H;(H=[...w.current][T.current])==null||H.focus(),m(z)}}),k=ie.useRef(O);function D(z){const W=XGe(O,z);X(z,W)}function V(z){X(z,T.current)}function U(){const z=k.current[T.current];O[T.current]!==z&&g(O)}function X(z,W,{commit:H}={commit:!1}){const G=KGe(a),B=JGe(Math.round((z-n)/a)*a+n,G),Z=q_(B,[n,i]);P((Q=[])=>{const ae=UGe(Q,Z,W);if(qGe(ae,u*a)){T.current=ae.indexOf(Z);const oe=String(ae)!==String(Q);return oe&&H&&g(ae),oe?ae:Q}else return Q})}return I.jsx($Ge,{scope:e.__scopeSlider,name:r,disabled:s,min:n,max:i,valueIndexToChangeRef:T,thumbs:w.current,values:O,orientation:o,form:b,children:I.jsx(XI.Provider,{scope:e.__scopeSlider,children:I.jsx(XI.Slot,{scope:e.__scopeSlider,children:I.jsx(M,{"aria-disabled":s,"data-disabled":s?"":void 0,...x,ref:t,onPointerDown:Rp(x.onPointerDown,()=>{s||(k.current=O)}),min:n,max:i,inverted:v,onSlideStart:s?void 0:D,onSlideMove:s?void 0:V,onSlideEnd:s?void 0:U,onHomeKeyDown:()=>!s&&X(n,0,{commit:!0}),onEndKeyDown:()=>!s&&X(i,O.length-1,{commit:!0}),onStepKeyDown:({event:z,direction:W})=>{if(!s){const B=IW.includes(z.key)||z.shiftKey&&PW.includes(z.key)?10:1,Z=T.current,Q=O[Z],ae=a*B*W;X(Q+ae,Z,{commit:!0})}}})})})})});DW.displayName=jp;var[NW,LW]=kW(jp,{startEdge:"left",endEdge:"right",size:"width",direction:1}),zGe=ie.forwardRef((e,t)=>{const{min:r,max:n,dir:i,inverted:a,onSlideStart:o,onSlideMove:s,onSlideEnd:u,onStepKeyDown:h,...f}=e,[m,g]=ie.useState(null),v=Qr(t,M=>g(M)),b=ie.useRef(void 0),x=pG(i),w=x==="ltr",T=w&&!a||!w&&a;function C(M){const O=b.current||m.getBoundingClientRect(),P=[0,O.width],D=qI(P,T?[r,n]:[n,r]);return b.current=O,D(M-O.left)}return I.jsx(NW,{scope:e.__scopeSlider,startEdge:T?"left":"right",endEdge:T?"right":"left",direction:T?1:-1,size:"width",children:I.jsx(FW,{dir:x,"data-orientation":"horizontal",...f,ref:v,style:{...f.style,"--radix-slider-thumb-transform":"translateX(-50%)"},onSlideStart:M=>{const O=C(M.clientX);o==null||o(O)},onSlideMove:M=>{const O=C(M.clientX);s==null||s(O)},onSlideEnd:()=>{b.current=void 0,u==null||u()},onStepKeyDown:M=>{const P=OW[T?"from-left":"from-right"].includes(M.key);h==null||h({event:M,direction:P?-1:1})}})})}),VGe=ie.forwardRef((e,t)=>{const{min:r,max:n,inverted:i,onSlideStart:a,onSlideMove:o,onSlideEnd:s,onStepKeyDown:u,...h}=e,f=ie.useRef(null),m=Qr(t,f),g=ie.useRef(void 0),v=!i;function b(x){const w=g.current||f.current.getBoundingClientRect(),T=[0,w.height],M=qI(T,v?[n,r]:[r,n]);return g.current=w,M(x-w.top)}return I.jsx(NW,{scope:e.__scopeSlider,startEdge:v?"bottom":"top",endEdge:v?"top":"bottom",size:"height",direction:v?1:-1,children:I.jsx(FW,{"data-orientation":"vertical",...h,ref:m,style:{...h.style,"--radix-slider-thumb-transform":"translateY(50%)"},onSlideStart:x=>{const w=b(x.clientY);a==null||a(w)},onSlideMove:x=>{const w=b(x.clientY);o==null||o(w)},onSlideEnd:()=>{g.current=void 0,s==null||s()},onStepKeyDown:x=>{const T=OW[v?"from-bottom":"from-top"].includes(x.key);u==null||u({event:x,direction:T?-1:1})}})})}),FW=ie.forwardRef((e,t)=>{const{__scopeSlider:r,onSlideStart:n,onSlideMove:i,onSlideEnd:a,onHomeKeyDown:o,onEndKeyDown:s,onStepKeyDown:u,...h}=e,f=nw(jp,r);return I.jsx(Yr.span,{...h,ref:t,onKeyDown:Rp(e.onKeyDown,m=>{m.key==="Home"?(o(m),m.preventDefault()):m.key==="End"?(s(m),m.preventDefault()):IW.concat(PW).includes(m.key)&&(u(m),m.preventDefault())}),onPointerDown:Rp(e.onPointerDown,m=>{const g=m.target;g.setPointerCapture(m.pointerId),m.preventDefault(),f.thumbs.has(g)?g.focus():n(m)}),onPointerMove:Rp(e.onPointerMove,m=>{m.target.hasPointerCapture(m.pointerId)&&i(m)}),onPointerUp:Rp(e.onPointerUp,m=>{const g=m.target;g.hasPointerCapture(m.pointerId)&&(g.releasePointerCapture(m.pointerId),a(m))})})}),RW="SliderTrack",jW=ie.forwardRef((e,t)=>{const{__scopeSlider:r,...n}=e,i=nw(RW,r);return I.jsx(Yr.span,{"data-disabled":i.disabled?"":void 0,"data-orientation":i.orientation,...n,ref:t})});jW.displayName=RW;var YI="SliderRange",BW=ie.forwardRef((e,t)=>{const{__scopeSlider:r,...n}=e,i=nw(YI,r),a=LW(YI,r),o=ie.useRef(null),s=Qr(t,o),u=i.values.length,h=i.values.map(g=>VW(g,i.min,i.max)),f=u>1?Math.min(...h):0,m=100-Math.max(...h);return I.jsx(Yr.span,{"data-orientation":i.orientation,"data-disabled":i.disabled?"":void 0,...n,ref:s,style:{...e.style,[a.startEdge]:f+"%",[a.endEdge]:m+"%"}})});BW.displayName=YI;var ZI="SliderThumb",$W=ie.forwardRef((e,t)=>{const r=jGe(e.__scopeSlider),[n,i]=ie.useState(null),a=Qr(t,s=>i(s)),o=ie.useMemo(()=>n?r().findIndex(s=>s.ref.current===n):-1,[r,n]);return I.jsx(GGe,{...e,ref:a,index:o})}),GGe=ie.forwardRef((e,t)=>{const{__scopeSlider:r,index:n,name:i,...a}=e,o=nw(ZI,r),s=LW(ZI,r),[u,h]=ie.useState(null),f=Qr(t,C=>h(C)),m=u?o.form||!!u.closest("form"):!0,g=ux(u),v=o.values[n],b=v===void 0?0:VW(v,o.min,o.max),x=HGe(n,o.values.length),w=g==null?void 0:g[s.size],T=w?YGe(w,b,s.direction):0;return ie.useEffect(()=>{if(u)return o.thumbs.add(u),()=>{o.thumbs.delete(u)}},[u,o.thumbs]),I.jsxs("span",{style:{transform:"var(--radix-slider-thumb-transform)",position:"absolute",[s.startEdge]:`calc(${b}% + ${T}px)`},children:[I.jsx(XI.ItemSlot,{scope:e.__scopeSlider,children:I.jsx(Yr.span,{role:"slider","aria-label":e["aria-label"]||x,"aria-valuemin":o.min,"aria-valuenow":v,"aria-valuemax":o.max,"aria-orientation":o.orientation,"data-orientation":o.orientation,"data-disabled":o.disabled?"":void 0,tabIndex:o.disabled?void 0:0,...a,ref:f,style:v===void 0?{display:"none"}:e.style,onFocus:Rp(e.onFocus,()=>{o.valueIndexToChangeRef.current=n})})}),m&&I.jsx(zW,{name:i??(o.name?o.name+(o.values.length>1?"[]":""):void 0),form:o.form,value:v},n)]})});$W.displayName=ZI;var WGe="RadioBubbleInput",zW=ie.forwardRef(({__scopeSlider:e,value:t,...r},n)=>{const i=ie.useRef(null),a=Qr(i,n),o=RGe(t);return ie.useEffect(()=>{const s=i.current;if(!s)return;const u=window.HTMLInputElement.prototype,f=Object.getOwnPropertyDescriptor(u,"value").set;if(o!==t&&f){const m=new Event("input",{bubbles:!0});f.call(s,t),s.dispatchEvent(m)}},[o,t]),I.jsx(Yr.input,{style:{display:"none"},...r,ref:a,defaultValue:t})});zW.displayName=WGe;function UGe(e=[],t,r){const n=[...e];return n[r]=t,n.sort((i,a)=>i-a)}function VW(e,t,r){const a=100/(r-t)*(e-t);return q_(a,[0,100])}function HGe(e,t){return t>2?`Value ${e+1} of ${t}`:t===2?["Minimum","Maximum"][e]:void 0}function XGe(e,t){if(e.length===1)return 0;const r=e.map(i=>Math.abs(i-t)),n=Math.min(...r);return r.indexOf(n)}function YGe(e,t,r){const n=e/2,a=qI([0,50],[0,n]);return(n-a(t)*r)*r}function ZGe(e){return e.slice(0,-1).map((t,r)=>e[r+1]-t)}function qGe(e,t){if(t>0){const r=ZGe(e);return Math.min(...r)>=t}return!0}function qI(e,t){return r=>{if(e[0]===e[1]||t[0]===t[1])return t[0];const n=(t[1]-t[0])/(e[1]-e[0]);return t[0]+n*(r-e[0])}}function KGe(e){return(String(e).split(".")[1]||"").length}function JGe(e,t){const r=Math.pow(10,t);return Math.round(e*r)/r}var GW=DW,QGe=jW,eWe=BW,tWe=$W;const WW=ie.forwardRef(({className:e,...t},r)=>I.jsxs(GW,{ref:r,className:rr("relative flex w-full touch-none select-none items-center",e),...t,children:[I.jsx(QGe,{className:"relative h-2 w-full grow overflow-hidden rounded-full bg-secondary",children:I.jsx(eWe,{className:"absolute h-full bg-primary"})}),I.jsx(tWe,{className:"block h-5 w-5 rounded-full border-2 border-primary bg-background ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50"})]}));WW.displayName=GW.displayName;function KI(e,t,{checkForDefaultPrevented:r=!0}={}){return function(i){if(e==null||e(i),r===!1||!i.defaultPrevented)return t==null?void 0:t(i)}}function UW(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function HW(...e){return t=>{let r=!1;const n=e.map(i=>{const a=UW(i,t);return!r&&typeof a=="function"&&(r=!0),a});if(r)return()=>{for(let i=0;i<n.length;i++){const a=n[i];typeof a=="function"?a():UW(e[i],null)}}}}function JI(...e){return ie.useCallback(HW(...e),e)}function XW(e,t=[]){let r=[];function n(a,o){const s=ie.createContext(o),u=r.length;r=[...r,o];const h=m=>{var T;const{scope:g,children:v,...b}=m,x=((T=g==null?void 0:g[e])==null?void 0:T[u])||s,w=ie.useMemo(()=>b,Object.values(b));return I.jsx(x.Provider,{value:w,children:v})};h.displayName=a+"Provider";function f(m,g){var x;const v=((x=g==null?void 0:g[e])==null?void 0:x[u])||s,b=ie.useContext(v);if(b)return b;if(o!==void 0)return o;throw new Error(`\`${m}\` must be used within \`${a}\``)}return[h,f]}const i=()=>{const a=r.map(o=>ie.createContext(o));return function(s){const u=(s==null?void 0:s[e])||a;return ie.useMemo(()=>({[`__scope${e}`]:{...s,[e]:u}}),[s,u])}};return i.scopeName=e,[n,rWe(i,...t)]}function rWe(...e){const t=e[0];if(e.length===1)return t;const r=()=>{const n=e.map(i=>({useScope:i(),scopeName:i.scopeName}));return function(a){const o=n.reduce((s,{useScope:u,scopeName:h})=>{const m=u(a)[`__scope${h}`];return{...s,...m}},{});return ie.useMemo(()=>({[`__scope${t.scopeName}`]:o}),[o])}};return r.scopeName=t.scopeName,r}var YW=ie.forwardRef((e,t)=>{const{children:r,...n}=e,i=ie.Children.toArray(r),a=i.find(iWe);if(a){const o=a.props.children,s=i.map(u=>u===a?ie.Children.count(o)>1?ie.Children.only(null):ie.isValidElement(o)?o.props.children:null:u);return I.jsx(QI,{...n,ref:t,children:ie.isValidElement(o)?ie.cloneElement(o,void 0,s):null})}return I.jsx(QI,{...n,ref:t,children:r})});YW.displayName="Slot";var QI=ie.forwardRef((e,t)=>{const{children:r,...n}=e;if(ie.isValidElement(r)){const i=sWe(r);return ie.cloneElement(r,{...aWe(n,r.props),ref:t?HW(t,i):i})}return ie.Children.count(r)>1?ie.Children.only(null):null});QI.displayName="SlotClone";var nWe=({children:e})=>I.jsx(I.Fragment,{children:e});function iWe(e){return ie.isValidElement(e)&&e.type===nWe}function aWe(e,t){const r={...t};for(const n in t){const i=e[n],a=t[n];/^on[A-Z]/.test(n)?i&&a?r[n]=(...s)=>{a(...s),i(...s)}:i&&(r[n]=i):n==="style"?r[n]={...i,...a}:n==="className"&&(r[n]=[i,a].filter(Boolean).join(" "))}return{...e,...r}}function sWe(e){var n,i;let t=(n=Object.getOwnPropertyDescriptor(e.props,"ref"))==null?void 0:n.get,r=t&&"isReactWarning"in t&&t.isReactWarning;return r?e.ref:(t=(i=Object.getOwnPropertyDescriptor(e,"ref"))==null?void 0:i.get,r=t&&"isReactWarning"in t&&t.isReactWarning,r?e.props.ref:e.props.ref||e.ref)}var oWe=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","span","svg","ul"],eP=oWe.reduce((e,t)=>{const r=ie.forwardRef((n,i)=>{const{asChild:a,...o}=n,s=a?YW:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),I.jsx(s,{...o,ref:i})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{});function Bp(e,t,{checkForDefaultPrevented:r=!0}={}){return function(i){if(e==null||e(i),r===!1||!i.defaultPrevented)return t==null?void 0:t(i)}}function ZW(e,t=[]){let r=[];function n(a,o){const s=ie.createContext(o),u=r.length;r=[...r,o];const h=m=>{var T;const{scope:g,children:v,...b}=m,x=((T=g==null?void 0:g[e])==null?void 0:T[u])||s,w=ie.useMemo(()=>b,Object.values(b));return I.jsx(x.Provider,{value:w,children:v})};h.displayName=a+"Provider";function f(m,g){var x;const v=((x=g==null?void 0:g[e])==null?void 0:x[u])||s,b=ie.useContext(v);if(b)return b;if(o!==void 0)return o;throw new Error(`\`${m}\` must be used within \`${a}\``)}return[h,f]}const i=()=>{const a=r.map(o=>ie.createContext(o));return function(s){const u=(s==null?void 0:s[e])||a;return ie.useMemo(()=>({[`__scope${e}`]:{...s,[e]:u}}),[s,u])}};return i.scopeName=e,[n,lWe(i,...t)]}function lWe(...e){const t=e[0];if(e.length===1)return t;const r=()=>{const n=e.map(i=>({useScope:i(),scopeName:i.scopeName}));return function(a){const o=n.reduce((s,{useScope:u,scopeName:h})=>{const m=u(a)[`__scope${h}`];return{...s,...m}},{});return ie.useMemo(()=>({[`__scope${t.scopeName}`]:o}),[o])}};return r.scopeName=t.scopeName,r}function qW(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function KW(...e){return t=>{let r=!1;const n=e.map(i=>{const a=qW(i,t);return!r&&typeof a=="function"&&(r=!0),a});if(r)return()=>{for(let i=0;i<n.length;i++){const a=n[i];typeof a=="function"?a():qW(e[i],null)}}}}function tP(...e){return ie.useCallback(KW(...e),e)}var iw=ie.forwardRef((e,t)=>{const{children:r,...n}=e,i=ie.Children.toArray(r),a=i.find(uWe);if(a){const o=a.props.children,s=i.map(u=>u===a?ie.Children.count(o)>1?ie.Children.only(null):ie.isValidElement(o)?o.props.children:null:u);return I.jsx(rP,{...n,ref:t,children:ie.isValidElement(o)?ie.cloneElement(o,void 0,s):null})}return I.jsx(rP,{...n,ref:t,children:r})});iw.displayName="Slot";var rP=ie.forwardRef((e,t)=>{const{children:r,...n}=e;if(ie.isValidElement(r)){const i=dWe(r);return ie.cloneElement(r,{...hWe(n,r.props),ref:t?KW(t,i):i})}return ie.Children.count(r)>1?ie.Children.only(null):null});rP.displayName="SlotClone";var cWe=({children:e})=>I.jsx(I.Fragment,{children:e});function uWe(e){return ie.isValidElement(e)&&e.type===cWe}function hWe(e,t){const r={...t};for(const n in t){const i=e[n],a=t[n];/^on[A-Z]/.test(n)?i&&a?r[n]=(...s)=>{a(...s),i(...s)}:i&&(r[n]=i):n==="style"?r[n]={...i,...a}:n==="className"&&(r[n]=[i,a].filter(Boolean).join(" "))}return{...e,...r}}function dWe(e){var n,i;let t=(n=Object.getOwnPropertyDescriptor(e.props,"ref"))==null?void 0:n.get,r=t&&"isReactWarning"in t&&t.isReactWarning;return r?e.ref:(t=(i=Object.getOwnPropertyDescriptor(e,"ref"))==null?void 0:i.get,r=t&&"isReactWarning"in t&&t.isReactWarning,r?e.props.ref:e.props.ref||e.ref)}function fWe(e){const t=e+"CollectionProvider",[r,n]=ZW(t),[i,a]=r(t,{collectionRef:{current:null},itemMap:new Map}),o=v=>{const{scope:b,children:x}=v,w=j.useRef(null),T=j.useRef(new Map).current;return I.jsx(i,{scope:b,itemMap:T,collectionRef:w,children:x})};o.displayName=t;const s=e+"CollectionSlot",u=j.forwardRef((v,b)=>{const{scope:x,children:w}=v,T=a(s,x),C=tP(b,T.collectionRef);return I.jsx(iw,{ref:C,children:w})});u.displayName=s;const h=e+"CollectionItemSlot",f="data-radix-collection-item",m=j.forwardRef((v,b)=>{const{scope:x,children:w,...T}=v,C=j.useRef(null),M=tP(b,C),O=a(h,x);return j.useEffect(()=>(O.itemMap.set(C,{ref:C,...T}),()=>void O.itemMap.delete(C))),I.jsx(iw,{[f]:"",ref:M,children:w})});m.displayName=h;function g(v){const b=a(e+"CollectionConsumer",v);return j.useCallback(()=>{const w=b.collectionRef.current;if(!w)return[];const T=Array.from(w.querySelectorAll(`[${f}]`));return Array.from(b.itemMap.values()).sort((O,P)=>T.indexOf(O.ref.current)-T.indexOf(P.ref.current))},[b.collectionRef,b.itemMap])}return[{Provider:o,Slot:u,ItemSlot:m},g,n]}var pWe=globalThis!=null&&globalThis.document?ie.useLayoutEffect:()=>{},mWe=ie.useId||(()=>{}),gWe=0;function yWe(e){const[t,r]=ie.useState(mWe());return pWe(()=>{r(n=>n??String(gWe++))},[e]),t?`radix-${t}`:""}var vWe=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","span","svg","ul"],JW=vWe.reduce((e,t)=>{const r=ie.forwardRef((n,i)=>{const{asChild:a,...o}=n,s=a?iw:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),I.jsx(s,{...o,ref:i})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{});function xWe({prop:e,defaultProp:t,onChange:r=()=>{}}){const[n,i]=bWe({defaultProp:t,onChange:r}),a=e!==void 0,o=a?e:n,s=Bs(r),u=ie.useCallback(h=>{if(a){const m=typeof h=="function"?h(e):h;m!==e&&s(m)}else i(h)},[a,e,i,s]);return[o,u]}function bWe({defaultProp:e,onChange:t}){const r=ie.useState(e),[n]=r,i=ie.useRef(n),a=Bs(t);return ie.useEffect(()=>{i.current!==n&&(a(n),i.current=n)},[n,i,a]),r}var _We=ie.createContext(void 0);function wWe(e){const t=ie.useContext(_We);return e||t||"ltr"}var nP="rovingFocusGroup.onEntryFocus",SWe={bubbles:!1,cancelable:!0},aw="RovingFocusGroup",[iP,QW,EWe]=fWe(aw),[CWe,sw]=ZW(aw,[EWe]),[TWe,AWe]=CWe(aw),eU=ie.forwardRef((e,t)=>I.jsx(iP.Provider,{scope:e.__scopeRovingFocusGroup,children:I.jsx(iP.Slot,{scope:e.__scopeRovingFocusGroup,children:I.jsx(MWe,{...e,ref:t})})}));eU.displayName=aw;var MWe=ie.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:r,orientation:n,loop:i=!1,dir:a,currentTabStopId:o,defaultCurrentTabStopId:s,onCurrentTabStopIdChange:u,onEntryFocus:h,preventScrollOnEntryFocus:f=!1,...m}=e,g=ie.useRef(null),v=tP(t,g),b=wWe(a),[x=null,w]=xWe({prop:o,defaultProp:s,onChange:u}),[T,C]=ie.useState(!1),M=Bs(h),O=QW(r),P=ie.useRef(!1),[k,D]=ie.useState(0);return ie.useEffect(()=>{const V=g.current;if(V)return V.addEventListener(nP,M),()=>V.removeEventListener(nP,M)},[M]),I.jsx(TWe,{scope:r,orientation:n,dir:b,loop:i,currentTabStopId:x,onItemFocus:ie.useCallback(V=>w(V),[w]),onItemShiftTab:ie.useCallback(()=>C(!0),[]),onFocusableItemAdd:ie.useCallback(()=>D(V=>V+1),[]),onFocusableItemRemove:ie.useCallback(()=>D(V=>V-1),[]),children:I.jsx(JW.div,{tabIndex:T||k===0?-1:0,"data-orientation":n,...m,ref:v,style:{outline:"none",...e.style},onMouseDown:Bp(e.onMouseDown,()=>{P.current=!0}),onFocus:Bp(e.onFocus,V=>{const U=!P.current;if(V.target===V.currentTarget&&U&&!T){const X=new CustomEvent(nP,SWe);if(V.currentTarget.dispatchEvent(X),!X.defaultPrevented){const z=O().filter(Z=>Z.focusable),W=z.find(Z=>Z.active),H=z.find(Z=>Z.id===x),B=[W,H,...z].filter(Boolean).map(Z=>Z.ref.current);nU(B,f)}}P.current=!1}),onBlur:Bp(e.onBlur,()=>C(!1))})})}),tU="RovingFocusGroupItem",rU=ie.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:r,focusable:n=!0,active:i=!1,tabStopId:a,...o}=e,s=yWe(),u=a||s,h=AWe(tU,r),f=h.currentTabStopId===u,m=QW(r),{onFocusableItemAdd:g,onFocusableItemRemove:v}=h;return ie.useEffect(()=>{if(n)return g(),()=>v()},[n,g,v]),I.jsx(iP.ItemSlot,{scope:r,id:u,focusable:n,active:i,children:I.jsx(JW.span,{tabIndex:f?0:-1,"data-orientation":h.orientation,...o,ref:t,onMouseDown:Bp(e.onMouseDown,b=>{n?h.onItemFocus(u):b.preventDefault()}),onFocus:Bp(e.onFocus,()=>h.onItemFocus(u)),onKeyDown:Bp(e.onKeyDown,b=>{if(b.key==="Tab"&&b.shiftKey){h.onItemShiftTab();return}if(b.target!==b.currentTarget)return;const x=OWe(b,h.orientation,h.dir);if(x!==void 0){if(b.metaKey||b.ctrlKey||b.altKey||b.shiftKey)return;b.preventDefault();let T=m().filter(C=>C.focusable).map(C=>C.ref.current);if(x==="last")T.reverse();else if(x==="prev"||x==="next"){x==="prev"&&T.reverse();const C=T.indexOf(b.currentTarget);T=h.loop?kWe(T,C+1):T.slice(C+1)}setTimeout(()=>nU(T))}})})})});rU.displayName=tU;var IWe={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function PWe(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function OWe(e,t,r){const n=PWe(e.key,r);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(n))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(n)))return IWe[n]}function nU(e,t=!1){const r=document.activeElement;for(const n of e)if(n===r||(n.focus({preventScroll:t}),document.activeElement!==r))return}function kWe(e,t){return e.map((r,n)=>e[(t+n)%e.length])}var iU=eU,aU=rU;function DWe({prop:e,defaultProp:t,onChange:r=()=>{}}){const[n,i]=NWe({defaultProp:t,onChange:r}),a=e!==void 0,o=a?e:n,s=Bs(r),u=ie.useCallback(h=>{if(a){const m=typeof h=="function"?h(e):h;m!==e&&s(m)}else i(h)},[a,e,i,s]);return[o,u]}function NWe({defaultProp:e,onChange:t}){const r=ie.useState(e),[n]=r,i=ie.useRef(n),a=Bs(t);return ie.useEffect(()=>{i.current!==n&&(a(n),i.current=n)},[n,i,a]),r}var LWe=ie.createContext(void 0);function FWe(e){const t=ie.useContext(LWe);return e||t||"ltr"}var aP=globalThis!=null&&globalThis.document?ie.useLayoutEffect:()=>{};function RWe(e){const[t,r]=ie.useState(void 0);return aP(()=>{if(e){r({width:e.offsetWidth,height:e.offsetHeight});const n=new ResizeObserver(i=>{if(!Array.isArray(i)||!i.length)return;const a=i[0];let o,s;if("borderBoxSize"in a){const u=a.borderBoxSize,h=Array.isArray(u)?u[0]:u;o=h.inlineSize,s=h.blockSize}else o=e.offsetWidth,s=e.offsetHeight;r({width:o,height:s})});return n.observe(e,{box:"border-box"}),()=>n.unobserve(e)}else r(void 0)},[e]),t}function jWe(e){const t=ie.useRef({value:e,previous:e});return ie.useMemo(()=>(t.current.value!==e&&(t.current.previous=t.current.value,t.current.value=e),t.current.previous),[e])}function BWe(e,t){return ie.useReducer((r,n)=>t[r][n]??r,e)}var sU=e=>{const{present:t,children:r}=e,n=$We(t),i=typeof r=="function"?r({present:n.isPresent}):ie.Children.only(r),a=JI(n.ref,zWe(i));return typeof r=="function"||n.isPresent?ie.cloneElement(i,{ref:a}):null};sU.displayName="Presence";function $We(e){const[t,r]=ie.useState(),n=ie.useRef({}),i=ie.useRef(e),a=ie.useRef("none"),o=e?"mounted":"unmounted",[s,u]=BWe(o,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return ie.useEffect(()=>{const h=ow(n.current);a.current=s==="mounted"?h:"none"},[s]),aP(()=>{const h=n.current,f=i.current;if(f!==e){const g=a.current,v=ow(h);e?u("MOUNT"):v==="none"||(h==null?void 0:h.display)==="none"?u("UNMOUNT"):u(f&&g!==v?"ANIMATION_OUT":"UNMOUNT"),i.current=e}},[e,u]),aP(()=>{if(t){let h;const f=t.ownerDocument.defaultView??window,m=v=>{const x=ow(n.current).includes(v.animationName);if(v.target===t&&x&&(u("ANIMATION_END"),!i.current)){const w=t.style.animationFillMode;t.style.animationFillMode="forwards",h=f.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=w)})}},g=v=>{v.target===t&&(a.current=ow(n.current))};return t.addEventListener("animationstart",g),t.addEventListener("animationcancel",m),t.addEventListener("animationend",m),()=>{f.clearTimeout(h),t.removeEventListener("animationstart",g),t.removeEventListener("animationcancel",m),t.removeEventListener("animationend",m)}}else u("ANIMATION_END")},[t,u]),{isPresent:["mounted","unmountSuspended"].includes(s),ref:ie.useCallback(h=>{h&&(n.current=getComputedStyle(h)),r(h)},[])}}function ow(e){return(e==null?void 0:e.animationName)||"none"}function zWe(e){var n,i;let t=(n=Object.getOwnPropertyDescriptor(e.props,"ref"))==null?void 0:n.get,r=t&&"isReactWarning"in t&&t.isReactWarning;return r?e.ref:(t=(i=Object.getOwnPropertyDescriptor(e,"ref"))==null?void 0:i.get,r=t&&"isReactWarning"in t&&t.isReactWarning,r?e.props.ref:e.props.ref||e.ref)}var sP="Radio",[VWe,oU]=XW(sP),[GWe,WWe]=VWe(sP),lU=ie.forwardRef((e,t)=>{const{__scopeRadio:r,name:n,checked:i=!1,required:a,disabled:o,value:s="on",onCheck:u,form:h,...f}=e,[m,g]=ie.useState(null),v=JI(t,w=>g(w)),b=ie.useRef(!1),x=m?h||!!m.closest("form"):!0;return I.jsxs(GWe,{scope:r,checked:i,disabled:o,children:[I.jsx(eP.button,{type:"button",role:"radio","aria-checked":i,"data-state":hU(i),"data-disabled":o?"":void 0,disabled:o,value:s,...f,ref:v,onClick:KI(e.onClick,w=>{i||u==null||u(),x&&(b.current=w.isPropagationStopped(),b.current||w.stopPropagation())})}),x&&I.jsx(UWe,{control:m,bubbles:!b.current,name:n,value:s,checked:i,required:a,disabled:o,form:h,style:{transform:"translateX(-100%)"}})]})});lU.displayName=sP;var cU="RadioIndicator",uU=ie.forwardRef((e,t)=>{const{__scopeRadio:r,forceMount:n,...i}=e,a=WWe(cU,r);return I.jsx(sU,{present:n||a.checked,children:I.jsx(eP.span,{"data-state":hU(a.checked),"data-disabled":a.disabled?"":void 0,...i,ref:t})})});uU.displayName=cU;var UWe=e=>{const{control:t,checked:r,bubbles:n=!0,...i}=e,a=ie.useRef(null),o=jWe(r),s=RWe(t);return ie.useEffect(()=>{const u=a.current,h=window.HTMLInputElement.prototype,m=Object.getOwnPropertyDescriptor(h,"checked").set;if(o!==r&&m){const g=new Event("click",{bubbles:n});m.call(u,r),u.dispatchEvent(g)}},[o,r,n]),I.jsx("input",{type:"radio","aria-hidden":!0,defaultChecked:r,...i,tabIndex:-1,ref:a,style:{...e.style,...s,position:"absolute",pointerEvents:"none",opacity:0,margin:0}})};function hU(e){return e?"checked":"unchecked"}var HWe=["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"],oP="RadioGroup",[XWe,IYe]=XW(oP,[sw,oU]),dU=sw(),fU=oU(),[YWe,ZWe]=XWe(oP),pU=ie.forwardRef((e,t)=>{const{__scopeRadioGroup:r,name:n,defaultValue:i,value:a,required:o=!1,disabled:s=!1,orientation:u,dir:h,loop:f=!0,onValueChange:m,...g}=e,v=dU(r),b=FWe(h),[x,w]=DWe({prop:a,defaultProp:i,onChange:m});return I.jsx(YWe,{scope:r,name:n,required:o,disabled:s,value:x,onValueChange:w,children:I.jsx(iU,{asChild:!0,...v,orientation:u,dir:b,loop:f,children:I.jsx(eP.div,{role:"radiogroup","aria-required":o,"aria-orientation":u,"data-disabled":s?"":void 0,dir:b,...g,ref:t})})})});pU.displayName=oP;var mU="RadioGroupItem",gU=ie.forwardRef((e,t)=>{const{__scopeRadioGroup:r,disabled:n,...i}=e,a=ZWe(mU,r),o=a.disabled||n,s=dU(r),u=fU(r),h=ie.useRef(null),f=JI(t,h),m=a.value===i.value,g=ie.useRef(!1);return ie.useEffect(()=>{const v=x=>{HWe.includes(x.key)&&(g.current=!0)},b=()=>g.current=!1;return document.addEventListener("keydown",v),document.addEventListener("keyup",b),()=>{document.removeEventListener("keydown",v),document.removeEventListener("keyup",b)}},[]),I.jsx(aU,{asChild:!0,...s,focusable:!o,active:m,children:I.jsx(lU,{disabled:o,required:a.required,checked:m,...u,...i,name:a.name,ref:f,onCheck:()=>a.onValueChange(i.value),onKeyDown:KI(v=>{v.key==="Enter"&&v.preventDefault()}),onFocus:KI(i.onFocus,()=>{var v;g.current&&((v=h.current)==null||v.click())})})})});gU.displayName=mU;var qWe="RadioGroupIndicator",yU=ie.forwardRef((e,t)=>{const{__scopeRadioGroup:r,...n}=e,i=fU(r);return I.jsx(uU,{...i,...n,ref:t})});yU.displayName=qWe;var vU=pU,xU=gU,KWe=yU;const lw=ie.forwardRef(({className:e,...t},r)=>I.jsx(vU,{className:gu("grid gap-2",e),...t,ref:r}));lw.displayName=vU.displayName;const xy=ie.forwardRef(({className:e,...t},r)=>I.jsx(xU,{ref:r,className:gu("aspect-square h-4 w-4 rounded-full border border-primary text-primary ring-offset-background focus:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",e),...t,children:I.jsx(KWe,{className:"flex items-center justify-center",children:I.jsx(Ine,{className:"h-2.5 w-2.5 fill-current text-current"})})}));xy.displayName=xU.displayName;function Mc({children:e,className:t}){return I.jsx("label",{className:`text-gray-800 dark:text-gray-300 ${t||""}`,children:e})}function JWe({activePanel:e,togglePanel:t,viewType:r,setViewType:n,dataSource:i,setDataSource:a,layerOptions:o=[],layerOpacity:s=[100],setLayerOpacity:u,layerEnabled:h=!0,setLayerEnabled:f}){return I.jsx("div",{className:rr("absolute top-16 sm:top-20 left-2 right-2 sm:left-1/2 sm:-translate-x-1/2 z-[1101] w-auto sm:w-80 transition-all duration-300 origin-top pointer-events-none",e==="layers"?"opacity-100 translate-y-0 pointer-events-auto":"opacity-0 -translate-y-10 pointer-events-none"),children:I.jsxs("div",{className:"bg-white/90 backdrop-blur-xl rounded-xl sm:rounded-2xl shadow-2xl overflow-hidden flex flex-col max-h-[80vh] border border-white/50",children:[I.jsxs("div",{className:"p-4 border-b border-border flex justify-between items-center bg-white/50",children:[I.jsxs("div",{children:[I.jsx("h2",{className:"font-bold text-foreground",children:"Raster Layers"}),I.jsx("p",{className:"text-xs text-muted-foreground",children:"Manage map overlays"})]}),I.jsxs("div",{className:"flex items-center gap-3",children:[I.jsx(o_,{checked:h,onCheckedChange:f}),I.jsx(_r,{variant:"ghost",size:"icon",className:"h-8 w-8 rounded-full",onClick:()=>t(null),children:I.jsx(gs,{className:"h-5 w-5"})})]})]}),I.jsxs("div",{className:"p-4 space-y-5 overflow-y-auto",children:[I.jsxs("div",{className:"space-y-3",children:[I.jsx(Mc,{className:"text-xs font-bold text-muted-foreground uppercase tracking-wider",children:"Layer Options"}),I.jsxs("div",{children:[I.jsx(Mc,{className:"text-xs font-bold text-muted-foreground uppercase mb-2 block",children:"View Type"}),I.jsxs(lw,{value:r,onValueChange:n,className:"grid grid-cols-2 gap-1.5 sm:gap-2",children:[I.jsxs(Mc,{htmlFor:"view-plot",className:rr("flex flex-col items-center p-3 border-2 rounded-lg cursor-pointer transition-all",r==="plot"?"border-green-500 bg-green-50/50 text-green-600":"border-border hover:border-green-500/50"),children:[I.jsx(xy,{value:"plot",id:"view-plot",className:"sr-only"}),I.jsx(ug,{className:"h-6 w-6 mb-1"}),I.jsx("span",{className:"text-xs font-medium",children:"Plot View"})]}),I.jsxs(Mc,{htmlFor:"view-map",className:rr("flex flex-col items-center p-3 border-2 rounded-lg cursor-pointer transition-all",r==="map"?"border-green-500 bg-green-50/50 text-green-600":"border-border hover:border-green-500/50"),children:[I.jsx(xy,{value:"map",id:"view-map",className:"sr-only"}),I.jsx(kne,{className:"h-6 w-6 mb-1"}),I.jsx("span",{className:"text-xs font-medium",children:"Map View"})]})]})]})]}),I.jsxs("div",{className:"space-y-2",children:[I.jsx(Mc,{className:"text-xs font-bold text-muted-foreground uppercase tracking-wider",children:"Data Source"}),I.jsx("div",{className:"border rounded-md overflow-hidden",children:I.jsx("div",{className:"max-h-[150px] overflow-y-auto",children:o.length===0?I.jsx("div",{className:"py-6 text-center text-sm text-muted-foreground",children:"No data source available."}):I.jsx("div",{className:"p-1",children:o.map(m=>I.jsxs("div",{onClick:()=>a(m),className:rr("relative flex w-full cursor-pointer select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none hover:bg-accent hover:text-accent-foreground",(i==null?void 0:i.value)===m.value&&"bg-accent text-accent-foreground"),children:[I.jsx(LS,{className:rr("mr-2 h-4 w-4",(i==null?void 0:i.value)===m.value?"opacity-100":"opacity-0")}),I.jsx("span",{children:m.label})]},m.value))})})})]}),I.jsxs("div",{className:"space-y-3 pt-2",children:[I.jsxs("div",{className:"flex justify-between items-center text-xs font-medium text-muted-foreground",children:[I.jsx("span",{children:"Opacity"}),I.jsxs("span",{children:[s[0],"%"]})]}),I.jsx(WW,{value:s,onValueChange:u,max:100,step:1})]})]})]})})}function QWe({error:e,errorInfo:t,onReset:r}){return I.jsxs("div",{children:[I.jsx("h2",{children:"Something went wrong!"}),I.jsx("p",{children:e==null?void 0:e.message}),I.jsx("details",{children:t==null?void 0:t.componentStack}),I.jsx(Vx,{onClick:r,children:"Try Again"})]})}class bU extends j.Component{constructor(r){super(r);NX(this,"handleReset",()=>{this.setState({hasError:!1,error:null,errorInfo:null}),this.props.onReset&&this.props.onReset()});this.state={hasError:!1,error:null,errorInfo:null}}static getDerivedStateFromError(r){return{hasError:!0,error:r}}componentDidCatch(r,n){this.setState({error:r,errorInfo:n})}render(){const{hasError:r,error:n,errorInfo:i}=this.state,a=this.props.ErrorFallback||QWe;return r?I.jsx(a,{error:n,errorInfo:i,onReset:this.handleReset}):this.props.children}}const eUe=({width:e=24,height:t=24,fill:r="#000"})=>I.jsxs("svg",{width:e,height:t,viewBox:"0 0 32 32",xmlns:"http://www.w3.org/2000/svg",fill:r,children:[I.jsx("path",{d:"M17,28V17h1a2.0023,2.0023,0,0,0,2-2V11a2.0023,2.0023,0,0,0-2-2H14a2.0023,2.0023,0,0,0-2,2v4a2.0023,2.0023,0,0,0,2,2h1V28H2v2H30V28ZM14,11h4l.0015,4H14Z"}),I.jsx("path",{d:"M9.3325,18.2168a7.0007,7.0007,0,0,1,0-10.4341l1.334,1.49a5,5,0,0,0,0,7.4537Z"}),I.jsx("path",{d:"M22.667,18.2168l-1.334-1.49a4.9995,4.9995,0,0,0,0-7.4537l1.334-1.49a7,7,0,0,1,0,10.4341Z"}),I.jsx("path",{d:"M6.3994,21.8008a11.0019,11.0019,0,0,1,0-17.6006L7.6,5.8a9.0009,9.0009,0,0,0,0,14.4014Z"}),I.jsx("path",{d:"M25.6006,21.8008l-1.2012-1.6a9.001,9.001,0,0,0,0-14.4019l1.2012-1.6a11.002,11.002,0,0,1,0,17.6011Z"})]}),tUe=j.lazy(()=>Promise.resolve().then(()=>mHe));function rUe({activePanel:e,togglePanel:t,markerType:r,setMarkerType:n,pawStatus:i,setPawStatus:a,markerTypeOptions:o=[],pawStatusOptions:s=[],showMarkers:u=!0,setShowMarkers:h,formatLabel:f}){const{mapRef:m}=j.useContext(qi),g=Kn(),[v,b]=j.useState(!1),{unfilteredMarkers:x,loading:w,handleDeleteMarker:T}=j.useContext(ys),{isConfirmed:C}=h1(),M=j.useCallback((k,D)=>{if(!(m!=null&&m.current)||!D)return;const{lat:V,lng:U}=D.location;m.current.flyTo({center:[U,V],zoom:14})},[m]),O=j.useCallback(async(k,D)=>{!D||!await C(g.formatMessage({id:"app.agviewer_map.delete_marker_confirm_message",defaultMessage:"Do you want to delete this marker?"}))||T(D.id)},[C,T,g]),P=j.useCallback(()=>{b(k=>!k)},[]);return I.jsx("div",{className:rr("absolute top-16 sm:top-20 left-2 right-2 sm:left-1/2 sm:-translate-x-1/2 z-[1101] w-auto sm:w-80 transition-all duration-300 origin-top pointer-events-none",e==="stations"?"opacity-100 translate-y-0 pointer-events-auto":"opacity-0 -translate-y-10 pointer-events-none"),children:I.jsxs("div",{className:"bg-white/90 backdrop-blur-xl rounded-xl sm:rounded-2xl shadow-2xl overflow-hidden flex flex-col max-h-[80vh] border border-white/50",children:[I.jsxs("div",{className:"p-4 border-b border-border flex justify-between items-center bg-white/50",children:[I.jsxs("div",{children:[I.jsx("h2",{className:"font-bold text-foreground",children:"Stations"}),I.jsx("p",{className:"text-xs text-muted-foreground",children:"Filter and manage markers"})]}),I.jsxs("div",{className:"flex items-center gap-3",children:[I.jsx(o_,{checked:u,onCheckedChange:h}),I.jsx(_r,{variant:"ghost",size:"icon",className:"h-8 w-8 rounded-full",onClick:()=>t(null),children:I.jsx(gs,{className:"h-5 w-5"})})]})]}),I.jsxs("div",{className:"p-4 space-y-4 overflow-y-auto",children:[I.jsxs("div",{children:[I.jsx(Mc,{className:"text-xs font-bold text-muted-foreground uppercase mb-2 block",children:"Marker Type"}),I.jsx(lw,{value:r||"",onValueChange:n,className:"grid grid-cols-3 gap-1.5 sm:gap-2",children:o.map(k=>I.jsxs(Mc,{htmlFor:`type-${k.value}`,className:rr("flex items-center justify-center py-2 px-3 text-xs font-medium rounded-lg border-2 cursor-pointer transition-all",(r||"")===k.value?"border-green-500 bg-green-50/50 text-green-600":"border-border hover:border-green-500/50"),children:[I.jsx(xy,{value:k.value,id:`type-${k.value}`,className:"sr-only"}),k.label]},k.value))})]}),I.jsxs("div",{children:[I.jsx(Mc,{className:"text-xs font-bold text-muted-foreground uppercase mb-2 block",children:"PAW Status"}),I.jsx(lw,{value:i||"",onValueChange:a,className:"grid grid-cols-2 sm:grid-cols-4 gap-1.5 sm:gap-2",children:s.map(k=>I.jsxs(Mc,{htmlFor:`paw-${k.value}`,className:rr("flex items-center justify-center py-2 px-2 text-xs font-medium rounded-lg border-2 cursor-pointer transition-all",(i||"")===k.value?"border-green-500 bg-green-50/50 text-green-600":"border-border hover:border-green-500/50"),children:[I.jsx(xy,{value:k.value,id:`paw-${k.value}`,className:"sr-only"}),k.label]},k.value))})]}),I.jsx(bU,{children:I.jsx(Mg,{open:v,setOpen:b,titleWithIcon:I.jsxs(I.Fragment,{children:[I.jsx(eUe,{}),I.jsx("span",{children:g.formatMessage({id:"app.agviewer_map.stations",defaultMessage:"Stations"})})]}),trigger:I.jsxs(_r,{variant:"outline",className:"w-full border-2 border-dashed hover:border-green-500 hover:text-green-600 hover:bg-green-50",onClick:()=>{b(!0),t(null)},children:[I.jsx(mh,{className:"h-4 w-4 mr-2"}),"Find Specific Station"]}),onClose:P,children:I.jsx(Gx,{className:"border-none shadow-md",children:I.jsx(j.Suspense,{fallback:I.jsx("div",{className:"flex justify-center items-center h-40",children:I.jsx(Ja,{})}),children:I.jsx(tUe,{markersData:x,loading:w,handleDeleteMarker:O,onMarkerClick:M,onClose:P,intl:g})})})})})]})]})})}function lP(e,t,{checkForDefaultPrevented:r=!0}={}){return function(i){if(e==null||e(i),r===!1||!i.defaultPrevented)return t==null?void 0:t(i)}}function nUe(e,t=[]){let r=[];function n(a,o){const s=ie.createContext(o),u=r.length;r=[...r,o];const h=m=>{var T;const{scope:g,children:v,...b}=m,x=((T=g==null?void 0:g[e])==null?void 0:T[u])||s,w=ie.useMemo(()=>b,Object.values(b));return I.jsx(x.Provider,{value:w,children:v})};h.displayName=a+"Provider";function f(m,g){var x;const v=((x=g==null?void 0:g[e])==null?void 0:x[u])||s,b=ie.useContext(v);if(b)return b;if(o!==void 0)return o;throw new Error(`\`${m}\` must be used within \`${a}\``)}return[h,f]}const i=()=>{const a=r.map(o=>ie.createContext(o));return function(s){const u=(s==null?void 0:s[e])||a;return ie.useMemo(()=>({[`__scope${e}`]:{...s,[e]:u}}),[s,u])}};return i.scopeName=e,[n,iUe(i,...t)]}function iUe(...e){const t=e[0];if(e.length===1)return t;const r=()=>{const n=e.map(i=>({useScope:i(),scopeName:i.scopeName}));return function(a){const o=n.reduce((s,{useScope:u,scopeName:h})=>{const m=u(a)[`__scope${h}`];return{...s,...m}},{});return ie.useMemo(()=>({[`__scope${t.scopeName}`]:o}),[o])}};return r.scopeName=t.scopeName,r}function _U(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function wU(...e){return t=>{let r=!1;const n=e.map(i=>{const a=_U(i,t);return!r&&typeof a=="function"&&(r=!0),a});if(r)return()=>{for(let i=0;i<n.length;i++){const a=n[i];typeof a=="function"?a():_U(e[i],null)}}}}function aUe(...e){return ie.useCallback(wU(...e),e)}var cP=globalThis!=null&&globalThis.document?ie.useLayoutEffect:()=>{};function sUe(e,t){return ie.useReducer((r,n)=>t[r][n]??r,e)}var SU=e=>{const{present:t,children:r}=e,n=oUe(t),i=typeof r=="function"?r({present:n.isPresent}):ie.Children.only(r),a=aUe(n.ref,lUe(i));return typeof r=="function"||n.isPresent?ie.cloneElement(i,{ref:a}):null};SU.displayName="Presence";function oUe(e){const[t,r]=ie.useState(),n=ie.useRef({}),i=ie.useRef(e),a=ie.useRef("none"),o=e?"mounted":"unmounted",[s,u]=sUe(o,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return ie.useEffect(()=>{const h=cw(n.current);a.current=s==="mounted"?h:"none"},[s]),cP(()=>{const h=n.current,f=i.current;if(f!==e){const g=a.current,v=cw(h);e?u("MOUNT"):v==="none"||(h==null?void 0:h.display)==="none"?u("UNMOUNT"):u(f&&g!==v?"ANIMATION_OUT":"UNMOUNT"),i.current=e}},[e,u]),cP(()=>{if(t){let h;const f=t.ownerDocument.defaultView??window,m=v=>{const x=cw(n.current).includes(v.animationName);if(v.target===t&&x&&(u("ANIMATION_END"),!i.current)){const w=t.style.animationFillMode;t.style.animationFillMode="forwards",h=f.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=w)})}},g=v=>{v.target===t&&(a.current=cw(n.current))};return t.addEventListener("animationstart",g),t.addEventListener("animationcancel",m),t.addEventListener("animationend",m),()=>{f.clearTimeout(h),t.removeEventListener("animationstart",g),t.removeEventListener("animationcancel",m),t.removeEventListener("animationend",m)}}else u("ANIMATION_END")},[t,u]),{isPresent:["mounted","unmountSuspended"].includes(s),ref:ie.useCallback(h=>{h&&(n.current=getComputedStyle(h)),r(h)},[])}}function cw(e){return(e==null?void 0:e.animationName)||"none"}function lUe(e){var n,i;let t=(n=Object.getOwnPropertyDescriptor(e.props,"ref"))==null?void 0:n.get,r=t&&"isReactWarning"in t&&t.isReactWarning;return r?e.ref:(t=(i=Object.getOwnPropertyDescriptor(e,"ref"))==null?void 0:i.get,r=t&&"isReactWarning"in t&&t.isReactWarning,r?e.props.ref:e.props.ref||e.ref)}var EU=ie.forwardRef((e,t)=>{const{children:r,...n}=e,i=ie.Children.toArray(r),a=i.find(uUe);if(a){const o=a.props.children,s=i.map(u=>u===a?ie.Children.count(o)>1?ie.Children.only(null):ie.isValidElement(o)?o.props.children:null:u);return I.jsx(uP,{...n,ref:t,children:ie.isValidElement(o)?ie.cloneElement(o,void 0,s):null})}return I.jsx(uP,{...n,ref:t,children:r})});EU.displayName="Slot";var uP=ie.forwardRef((e,t)=>{const{children:r,...n}=e;if(ie.isValidElement(r)){const i=dUe(r);return ie.cloneElement(r,{...hUe(n,r.props),ref:t?wU(t,i):i})}return ie.Children.count(r)>1?ie.Children.only(null):null});uP.displayName="SlotClone";var cUe=({children:e})=>I.jsx(I.Fragment,{children:e});function uUe(e){return ie.isValidElement(e)&&e.type===cUe}function hUe(e,t){const r={...t};for(const n in t){const i=e[n],a=t[n];/^on[A-Z]/.test(n)?i&&a?r[n]=(...s)=>{a(...s),i(...s)}:i&&(r[n]=i):n==="style"?r[n]={...i,...a}:n==="className"&&(r[n]=[i,a].filter(Boolean).join(" "))}return{...e,...r}}function dUe(e){var n,i;let t=(n=Object.getOwnPropertyDescriptor(e.props,"ref"))==null?void 0:n.get,r=t&&"isReactWarning"in t&&t.isReactWarning;return r?e.ref:(t=(i=Object.getOwnPropertyDescriptor(e,"ref"))==null?void 0:i.get,r=t&&"isReactWarning"in t&&t.isReactWarning,r?e.props.ref:e.props.ref||e.ref)}var fUe=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","span","svg","ul"],uw=fUe.reduce((e,t)=>{const r=ie.forwardRef((n,i)=>{const{asChild:a,...o}=n,s=a?EU:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),I.jsx(s,{...o,ref:i})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{}),pUe=ie.createContext(void 0);function mUe(e){const t=ie.useContext(pUe);return e||t||"ltr"}function gUe({prop:e,defaultProp:t,onChange:r=()=>{}}){const[n,i]=yUe({defaultProp:t,onChange:r}),a=e!==void 0,o=a?e:n,s=Bs(r),u=ie.useCallback(h=>{if(a){const m=typeof h=="function"?h(e):h;m!==e&&s(m)}else i(h)},[a,e,i,s]);return[o,u]}function yUe({defaultProp:e,onChange:t}){const r=ie.useState(e),[n]=r,i=ie.useRef(n),a=Bs(t);return ie.useEffect(()=>{i.current!==n&&(a(n),i.current=n)},[n,i,a]),r}var vUe=ie.useId||(()=>{}),xUe=0;function bUe(e){const[t,r]=ie.useState(vUe());return cP(()=>{e||r(n=>n??String(xUe++))},[e]),e||(t?`radix-${t}`:"")}var hP="Tabs",[_Ue,PYe]=nUe(hP,[sw]),CU=sw(),[wUe,dP]=_Ue(hP),TU=ie.forwardRef((e,t)=>{const{__scopeTabs:r,value:n,onValueChange:i,defaultValue:a,orientation:o="horizontal",dir:s,activationMode:u="automatic",...h}=e,f=mUe(s),[m,g]=gUe({prop:n,onChange:i,defaultProp:a});return I.jsx(wUe,{scope:r,baseId:bUe(),value:m,onValueChange:g,orientation:o,dir:f,activationMode:u,children:I.jsx(uw.div,{dir:f,"data-orientation":o,...h,ref:t})})});TU.displayName=hP;var AU="TabsList",MU=ie.forwardRef((e,t)=>{const{__scopeTabs:r,loop:n=!0,...i}=e,a=dP(AU,r),o=CU(r);return I.jsx(iU,{asChild:!0,...o,orientation:a.orientation,dir:a.dir,loop:n,children:I.jsx(uw.div,{role:"tablist","aria-orientation":a.orientation,...i,ref:t})})});MU.displayName=AU;var IU="TabsTrigger",PU=ie.forwardRef((e,t)=>{const{__scopeTabs:r,value:n,disabled:i=!1,...a}=e,o=dP(IU,r),s=CU(r),u=DU(o.baseId,n),h=NU(o.baseId,n),f=n===o.value;return I.jsx(aU,{asChild:!0,...s,focusable:!i,active:f,children:I.jsx(uw.button,{type:"button",role:"tab","aria-selected":f,"aria-controls":h,"data-state":f?"active":"inactive","data-disabled":i?"":void 0,disabled:i,id:u,...a,ref:t,onMouseDown:lP(e.onMouseDown,m=>{!i&&m.button===0&&m.ctrlKey===!1?o.onValueChange(n):m.preventDefault()}),onKeyDown:lP(e.onKeyDown,m=>{[" ","Enter"].includes(m.key)&&o.onValueChange(n)}),onFocus:lP(e.onFocus,()=>{const m=o.activationMode!=="manual";!f&&!i&&m&&o.onValueChange(n)})})})});PU.displayName=IU;var OU="TabsContent",kU=ie.forwardRef((e,t)=>{const{__scopeTabs:r,value:n,forceMount:i,children:a,...o}=e,s=dP(OU,r),u=DU(s.baseId,n),h=NU(s.baseId,n),f=n===s.value,m=ie.useRef(f);return ie.useEffect(()=>{const g=requestAnimationFrame(()=>m.current=!1);return()=>cancelAnimationFrame(g)},[]),I.jsx(SU,{present:i||f,children:({present:g})=>I.jsx(uw.div,{"data-state":f?"active":"inactive","data-orientation":s.orientation,role:"tabpanel","aria-labelledby":u,hidden:!g,id:h,tabIndex:0,...o,ref:t,style:{...e.style,animationDuration:m.current?"0s":void 0},children:g&&a})})});kU.displayName=OU;function DU(e,t){return`${e}-trigger-${t}`}function NU(e,t){return`${e}-content-${t}`}var SUe=TU,LU=MU,FU=PU,RU=kU;const EUe=SUe,jU=ie.forwardRef(({className:e,...t},r)=>I.jsx(LU,{ref:r,className:rr("inline-flex h-10 items-center justify-center rounded-md bg-muted p-1 text-muted-foreground",e),...t}));jU.displayName=LU.displayName;const hw=ie.forwardRef(({className:e,...t},r)=>I.jsx(FU,{ref:r,className:rr("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}));hw.displayName=FU.displayName;const dw=ie.forwardRef(({className:e,...t},r)=>I.jsx(RU,{ref:r,className:rr("mt-2 ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",e),...t}));dw.displayName=RU.displayName;function CUe({activePanel:e,togglePanel:t,farms:r=[],plots:n=[],markers:i=[],formatLabel:a,onAddFarm:o,onAddPlot:s,onAddStation:u,onFarmsChange:h}){var Yt,qt,er,Pr;const{unfilteredMarkers:f=[],loading:m,markersData:g}=j.useContext(ys)||{},{plots:v}=j.useContext(xs)||{},b=v||n,x=f||i,[w,T]=j.useState(!1),[C,M]=j.useState(!1),[O,P]=j.useState(null),[k,D]=j.useState(!1),[V,U]=j.useState(""),[X,z]=j.useState(""),[W,H]=j.useState(""),[G,B]=j.useState(!1),[Z,Q]=j.useState(!1),[ae,oe]=j.useState(null),[te,ve]=j.useState(!1),[ce,q]=j.useState(!1),[se,he]=j.useState(!1),[be,Ae]=j.useState({name:"",area:""}),[le,K]=j.useState(!1),[ue,ge]=j.useState(!1),[Y,xe]=j.useState(null),[pe,Me]=j.useState(!1),[ye,Ee]=j.useState(!1),[Ge,We]=j.useState(!1),[Te,rt]=j.useState({location_name:""});j.useMemo(()=>f.map(Oe=>({value:Oe.id,label:(Oe==null?void 0:Oe.name)||(Oe==null?void 0:Oe.title)||(Oe==null?void 0:Oe.label)||`Marker ${(Oe==null?void 0:Oe.id)||""}`})),[f]);const it=j.useMemo(()=>{if(!V.trim())return r;const Oe=V.toLowerCase();return r.filter(Ce=>{var de,Pe;return((de=Ce.label)==null?void 0:de.toLowerCase().includes(Oe))||((Pe=Ce.details)==null?void 0:Pe.toLowerCase().includes(Oe))})},[r,V]),Be=j.useMemo(()=>{if(!X.trim())return n;const Oe=X.toLowerCase();return n.filter(Ce=>{var Qe,nt,ct,et,yt,Ot,wt,Bt,Fe;const de=((nt=(Qe=Ce==null?void 0:Ce.options)==null?void 0:Qe.properties)==null?void 0:nt.name)||((ct=Ce==null?void 0:Ce.properties)==null?void 0:ct.name)||`Plot ${(Ce==null?void 0:Ce.id)||""}`,Pe=((yt=(et=Ce==null?void 0:Ce.options)==null?void 0:et.properties)==null?void 0:yt.farm_name)||((Ot=Ce==null?void 0:Ce.properties)==null?void 0:Ot.farm_name)||"Unknown Farm",Ne=((Bt=(wt=Ce==null?void 0:Ce.options)==null?void 0:wt.properties)==null?void 0:Bt.area)||((Fe=Ce==null?void 0:Ce.properties)==null?void 0:Fe.area)||"N/A";return de.toLowerCase().includes(Oe)||Pe.toLowerCase().includes(Oe)||String(Ne).toLowerCase().includes(Oe)})},[n,X]),je=j.useMemo(()=>{if(!W.trim())return x;const Oe=W.toLowerCase();return x.filter(Ce=>{var nt,ct,et;const de=((nt=Ce==null?void 0:Ce.properties)==null?void 0:nt.name)||(Ce==null?void 0:Ce.name)||`Station ${(Ce==null?void 0:Ce.id)||""}`,Pe=((ct=Ce==null?void 0:Ce.properties)==null?void 0:ct.farm_name)||(Ce==null?void 0:Ce.farm_name)||"Unknown Farm",Ne=((et=Ce==null?void 0:Ce.properties)==null?void 0:et.paw_status)||(Ce==null?void 0:Ce.paw_status)||"Unknown",Qe=a(Ne);return de.toLowerCase().includes(Oe)||Pe.toLowerCase().includes(Oe)||Ne.toLowerCase().includes(Oe)||Qe.toLowerCase().includes(Oe)})},[x,W,a]),$e=j.useCallback(()=>{P(null)},[]),He=j.useCallback(()=>{T(!1),setTimeout($e,200)},[$e]),at=j.useCallback(Oe=>{Oe&&(P(Oe),T(!0))},[]),Ze=j.useCallback(async Oe=>{if(!O)return;const Ce=b.filter(Pe=>{const Ne=Pe==null?void 0:Pe.farm;return Ne?(typeof Ne=="object"?Ne==null?void 0:Ne.id:Ne)==O.value:!1}),de=QL(Ce);await aC(O.value,Oe.name.trim(),Oe.marker_set||[],Oe.season_start_date||void 0,de,Oe.status,Oe.weather_station,Oe.unit_system),an.success("Farm updated successfully"),h&&await h()},[O,b,h]),ut=j.useCallback(Oe=>{P(Oe),M(!0)},[]),gt=j.useCallback(async()=>{if(O){D(!0);try{await sC(O.value),an.success("Farm deleted successfully"),M(!1),$e(),h&&await h()}catch{an.error("Failed to delete farm")}finally{D(!1)}}},[h,$e,O]),xt=j.useCallback(async Oe=>{var Ce,de,Pe,Ne,Qe,nt,ct,et,yt;if(Oe){oe(Oe),B(!0),ve(!0);try{const Ot=(Oe==null?void 0:Oe.id)||((de=(Ce=Oe==null?void 0:Oe.options)==null?void 0:Ce.properties)==null?void 0:de.id)||((Pe=Oe==null?void 0:Oe.options)==null?void 0:Pe.id),wt=((Qe=(Ne=Oe==null?void 0:Oe.options)==null?void 0:Ne.properties)==null?void 0:Qe.name)||((nt=Oe==null?void 0:Oe.properties)==null?void 0:nt.name)||(Oe==null?void 0:Oe.name)||"",Bt=((et=(ct=Oe==null?void 0:Oe.options)==null?void 0:ct.properties)==null?void 0:et.area)||((yt=Oe==null?void 0:Oe.properties)==null?void 0:yt.area)||(Oe==null?void 0:Oe.area)||"";Ae({name:wt,area:Bt?String(Bt):""})}catch{an.error("Failed to load plot details"),B(!1)}finally{ve(!1)}}},[]),It=j.useCallback(async()=>{var Oe,Ce,de,Pe;if(ae){if(!((Oe=be.name)!=null&&Oe.trim())){an.error("Please provide a plot name");return}q(!0);try{const Qe={id:(ae==null?void 0:ae.id)||((de=(Ce=ae==null?void 0:ae.options)==null?void 0:Ce.properties)==null?void 0:de.id)||((Pe=ae==null?void 0:ae.options)==null?void 0:Pe.id),name:be.name.trim()};be.area&&(Qe.area=parseFloat(be.area)||null),await e5(Qe),an.success("Plot updated successfully"),B(!1),Ae({name:"",area:""}),oe(null),h&&await h()}catch{an.error("Failed to update plot")}finally{q(!1)}}},[be.name,be.area,ae,h]),ht=j.useCallback(Oe=>{oe(Oe),Q(!0)},[]),Pt=j.useCallback(async()=>{var Oe,Ce,de;if(ae){he(!0);try{const Pe=(ae==null?void 0:ae.id)||((Ce=(Oe=ae==null?void 0:ae.options)==null?void 0:Oe.properties)==null?void 0:Ce.id)||((de=ae==null?void 0:ae.options)==null?void 0:de.id);await t5(Pe),an.success("Plot deleted successfully"),Q(!1),oe(null),h&&await h()}catch{an.error("Failed to delete plot")}finally{he(!1)}}},[ae,h]),Lt=j.useCallback(async Oe=>{var Ce,de;if(Oe){xe(Oe),K(!0),Me(!0);try{const Pe=(Oe==null?void 0:Oe.id)||((Ce=Oe==null?void 0:Oe.properties)==null?void 0:Ce.id),Ne=await v4(Pe);rt({location_name:(Ne==null?void 0:Ne.location_name)||((de=Oe==null?void 0:Oe.properties)==null?void 0:de.name)||(Oe==null?void 0:Oe.name)||""})}catch{an.error("Failed to load station details"),K(!1)}finally{Me(!1)}}},[]),Xt=j.useCallback(async()=>{var Oe,Ce;if(Y){if(!((Oe=Te.location_name)!=null&&Oe.trim())){an.error("Please provide a station name");return}Ee(!0);try{const de=(Y==null?void 0:Y.id)||((Ce=Y==null?void 0:Y.properties)==null?void 0:Ce.id),Pe={id:de,location_name:Te.location_name.trim()},Ne=await v4(de);await x4({...Ne,...Pe}),an.success("Station updated successfully"),K(!1),rt({location_name:""}),xe(null),h&&await h()}catch{an.error("Failed to update station")}finally{Ee(!1)}}},[Te.location_name,Y,h]),Ut=j.useCallback(Oe=>{xe(Oe),ge(!0)},[]),Dt=j.useCallback(async()=>{var Oe;if(Y){We(!0);try{const Ce=(Y==null?void 0:Y.id)||((Oe=Y==null?void 0:Y.properties)==null?void 0:Oe.id);await b4(Ce),an.success("Station deleted successfully"),ge(!1),xe(null),h&&await h()}catch{an.error("Failed to delete station")}finally{We(!1)}}},[Y,h]);return I.jsxs("div",{className:rr("absolute top-16 sm:top-20 left-2 right-2 sm:left-1/2 sm:-translate-x-1/2 z-[1101] w-auto sm:w-96 transition-all duration-300 origin-top pointer-events-none",e==="settings"?"opacity-100 translate-y-0 pointer-events-auto":"opacity-0 -translate-y-10 pointer-events-none"),children:[I.jsxs("div",{className:"bg-white/90 backdrop-blur-xl rounded-xl sm:rounded-2xl shadow-2xl overflow-hidden flex flex-col max-h-[85vh] border border-white/50",children:[I.jsxs("div",{className:"p-4 border-b border-border flex justify-between items-center bg-white/50",children:[I.jsxs("div",{children:[I.jsx("h2",{className:"font-bold text-foreground",children:"Data Management"}),I.jsx("p",{className:"text-xs text-muted-foreground",children:"Manage farms, plots & stations"})]}),I.jsx(_r,{variant:"ghost",size:"icon",className:"h-8 w-8 rounded-full",onClick:()=>t(null),children:I.jsx(gs,{className:"h-5 w-5"})})]}),I.jsxs(EUe,{defaultValue:"farms",className:"flex-1 flex flex-col",children:[I.jsxs(jU,{className:"w-full rounded-none border-b bg-muted/50 grid grid-cols-3",children:[I.jsx(hw,{value:"farms",className:"text-[10px] sm:text-xs font-bold uppercase tracking-wide px-2 sm:px-4",children:"Farms"}),I.jsx(hw,{value:"plots",className:"text-[10px] sm:text-xs font-bold uppercase tracking-wide px-2 sm:px-4",children:"Plots"}),I.jsx(hw,{value:"stations",className:"text-[10px] sm:text-xs font-bold uppercase tracking-wide px-2 sm:px-4",children:"Stations"})]}),I.jsxs(dw,{value:"farms",className:"flex-1 overflow-y-auto p-4 space-y-3 mt-0",children:[I.jsx("h3",{className:"font-semibold text-sm mb-3",children:"All Farms"}),I.jsxs("div",{className:"relative mb-3",children:[I.jsx(mh,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),I.jsx(Zo,{placeholder:"Search farms...",value:V,onChange:Oe=>U(Oe.target.value),className:"pl-9 h-9"})]}),I.jsx("div",{className:"space-y-2 mb-4 max-h-[350px] overflow-y-auto",children:it.length===0?I.jsx("div",{className:"py-6 text-center text-sm text-muted-foreground",children:V.trim()?"No farms found.":"No farms available."}):it.map(Oe=>I.jsx("div",{className:"bg-white/60 p-3 rounded-lg border border-border hover:border-green-500/50 transition-colors cursor-pointer group",children:I.jsxs("div",{className:"flex items-center justify-between",children:[I.jsxs("div",{className:"flex items-center gap-2",children:[I.jsx("div",{className:"w-8 h-8 bg-green-100 rounded-lg flex items-center justify-center",children:I.jsx(NS,{className:"h-4 w-4 text-green-600"})}),I.jsxs("div",{children:[I.jsx("p",{className:"text-sm font-medium",children:Oe.label}),I.jsx("p",{className:"text-xs text-muted-foreground",children:Oe.details})]})]}),I.jsxs("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity",children:[I.jsx(_r,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:()=>at(Oe),"aria-label":"Edit farm",children:I.jsx(RS,{className:"h-4 w-4"})}),I.jsx(_r,{variant:"ghost",size:"icon",className:"h-8 w-8 text-destructive hover:text-destructive",onClick:()=>ut(Oe),"aria-label":"Delete farm",children:I.jsx(qv,{className:"h-4 w-4"})})]})]})},Oe.value))}),I.jsxs(_r,{variant:"outline",className:"w-full border-2 border-dashed hover:border-green-500 hover:text-green-600 hover:bg-green-50",onClick:o,children:[I.jsx(hg,{className:"h-4 w-4 mr-2"}),"Add New Farm"]})]}),I.jsxs(dw,{value:"plots",className:"flex-1 overflow-y-auto p-4 space-y-3 mt-0",children:[I.jsx("h3",{className:"font-semibold text-sm mb-3",children:"All Plots"}),I.jsxs("div",{className:"relative mb-3",children:[I.jsx(mh,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),I.jsx(Zo,{placeholder:"Search plots...",value:X,onChange:Oe=>z(Oe.target.value),className:"pl-9 h-9"})]}),I.jsx("div",{className:"space-y-2 max-h-[350px] overflow-y-auto",children:Be.length===0?I.jsx("div",{className:"py-6 text-center text-sm text-muted-foreground",children:X.trim()?"No plots found.":"No plots available."}):Be.map(Oe=>{var Ne,Qe,nt,ct,et,yt,Ot,wt,Bt,Fe,Se;const Ce=((Qe=(Ne=Oe==null?void 0:Oe.options)==null?void 0:Ne.properties)==null?void 0:Qe.name)||((nt=Oe==null?void 0:Oe.properties)==null?void 0:nt.name)||`Plot ${(Oe==null?void 0:Oe.id)||""}`,de=((et=(ct=Oe==null?void 0:Oe.options)==null?void 0:ct.properties)==null?void 0:et.farm_name)||((yt=Oe==null?void 0:Oe.properties)==null?void 0:yt.farm_name)||"Unknown Farm",Pe=((wt=(Ot=Oe==null?void 0:Oe.options)==null?void 0:Ot.properties)==null?void 0:wt.area)||((Bt=Oe==null?void 0:Oe.properties)==null?void 0:Bt.area)||"N/A";return I.jsx("div",{className:"bg-white/60 p-3 rounded-lg border border-border hover:border-green-500/50 transition-colors cursor-pointer group",children:I.jsxs("div",{className:"flex items-center justify-between",children:[I.jsxs("div",{className:"flex items-center gap-2",children:[I.jsx("div",{className:"w-8 h-8 bg-blue-100 rounded-lg flex items-center justify-center",children:I.jsx(ug,{className:"h-4 w-4 text-blue-600"})}),I.jsxs("div",{children:[I.jsx("p",{className:"text-sm font-medium",children:Ce}),I.jsxs("p",{className:"text-xs text-muted-foreground",children:[de," • ",Pe]})]})]}),I.jsxs("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity",children:[I.jsx(_r,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:()=>xt(Oe),"aria-label":"Edit plot",children:I.jsx(RS,{className:"h-4 w-4"})}),I.jsx(_r,{variant:"ghost",size:"icon",className:"h-8 w-8 text-destructive hover:text-destructive",onClick:()=>ht(Oe),"aria-label":"Delete plot",children:I.jsx(qv,{className:"h-4 w-4"})})]})]})},(Oe==null?void 0:Oe.id)||((Se=(Fe=Oe==null?void 0:Oe.options)==null?void 0:Fe.properties)==null?void 0:Se.id))})}),I.jsxs(_r,{variant:"outline",className:"w-full border-2 border-dashed hover:border-green-500 hover:text-green-600 hover:bg-green-50",onClick:s,children:[I.jsx(hg,{className:"h-4 w-4 mr-2"}),"Add Plot"]})]}),I.jsxs(dw,{value:"stations",className:"flex-1 overflow-y-auto p-4 space-y-3 mt-0",children:[I.jsx("h3",{className:"font-semibold text-sm mb-3",children:"All Stations"}),I.jsxs("div",{className:"relative mb-3",children:[I.jsx(mh,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),I.jsx(Zo,{placeholder:"Search stations...",value:W,onChange:Oe=>H(Oe.target.value),className:"pl-9 h-9"})]}),I.jsx("div",{className:"space-y-2 max-h-[350px] overflow-y-auto",children:je.length===0?I.jsx("div",{className:"py-6 text-center text-sm text-muted-foreground",children:W.trim()?"No stations found.":"No stations available."}):je.map(Oe=>{var Qe,nt,ct,et;const Ce=((Qe=Oe==null?void 0:Oe.properties)==null?void 0:Qe.name)||(Oe==null?void 0:Oe.name)||`Station ${(Oe==null?void 0:Oe.id)||""}`,de=((nt=Oe==null?void 0:Oe.properties)==null?void 0:nt.farm_name)||(Oe==null?void 0:Oe.farm_name)||"Unknown Farm",Pe=((ct=Oe==null?void 0:Oe.properties)==null?void 0:ct.paw_status)||(Oe==null?void 0:Oe.paw_status)||"Unknown",Ne=Pe==="OPTIMAL"||Pe==="optimal"?"green":Pe==="STRESS_START"||Pe==="stress"?"orange":"gray";return I.jsx("div",{className:"bg-white/60 p-3 rounded-lg border border-border hover:border-green-500/50 transition-colors cursor-pointer group",children:I.jsxs("div",{className:"flex items-center justify-between",children:[I.jsxs("div",{className:"flex items-center gap-2",children:[I.jsx("div",{className:rr("w-8 h-8 rounded-lg flex items-center justify-center",Ne==="orange"&&"bg-orange-100",Ne==="green"&&"bg-green-100",Ne==="gray"&&"bg-gray-100"),children:I.jsx(Zv,{className:rr("h-4 w-4",Ne==="orange"&&"text-orange-600",Ne==="green"&&"text-green-600",Ne==="gray"&&"text-gray-600")})}),I.jsxs("div",{children:[I.jsx("p",{className:"text-sm font-medium",children:Ce}),I.jsxs("p",{className:"text-xs text-muted-foreground",children:[de," • ",a(Pe)]})]})]}),I.jsxs("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity",children:[I.jsx(_r,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:()=>Lt(Oe),"aria-label":"Edit station",children:I.jsx(RS,{className:"h-4 w-4"})}),I.jsx(_r,{variant:"ghost",size:"icon",className:"h-8 w-8 text-destructive hover:text-destructive",onClick:()=>Ut(Oe),"aria-label":"Delete station",children:I.jsx(qv,{className:"h-4 w-4"})})]})]})},(Oe==null?void 0:Oe.id)||((et=Oe==null?void 0:Oe.properties)==null?void 0:et.id))})}),I.jsxs(_r,{variant:"outline",className:"w-full border-2 border-dashed hover:border-green-500 hover:text-green-600 hover:bg-green-50",onClick:u,children:[I.jsx(hg,{className:"h-4 w-4 mr-2"}),"Add Station"]})]})]})]}),I.jsx(yz,{open:w,onOpenChange:T,farm:O?{id:O.value,name:O.label}:null,onSave:Ze,onClose:He}),I.jsx(vy,{isOpen:C,onClose:()=>M(!1),onConfirm:gt,onCancel:()=>M(!1),title:"Delete farm",message:`Are you sure you want to delete "${(O==null?void 0:O.label)||"this farm"}"?`,confirmText:k?"Deleting...":"Delete",cancelText:"Cancel",variant:"destructive"}),I.jsx(r_,{open:G,onOpenChange:Oe=>!Oe&&B(!1),children:I.jsxs(j0,{className:"w-[calc(100vw-2rem)] sm:max-w-lg",children:[I.jsxs(B0,{children:[I.jsx(Au,{children:"Edit Plot"}),I.jsx(i_,{children:"Update the plot name and area."})]}),I.jsxs("div",{className:"space-y-4",children:[I.jsxs("div",{className:"space-y-2",children:[I.jsx("p",{className:"text-sm font-medium text-foreground",children:"Plot Name"}),I.jsx(Zo,{value:be.name,onChange:Oe=>Ae(Ce=>({...Ce,name:Oe.target.value})),placeholder:"Plot name",disabled:te})]}),I.jsxs("div",{className:"space-y-2",children:[I.jsx("p",{className:"text-sm font-medium text-foreground",children:"Area"}),I.jsx(Zo,{type:"number",value:be.area,onChange:Oe=>Ae(Ce=>({...Ce,area:Oe.target.value})),placeholder:"Area (optional)",disabled:te})]})]}),I.jsxs(n_,{children:[I.jsx(_r,{variant:"outline",onClick:()=>B(!1),disabled:ce,children:"Cancel"}),I.jsx(_r,{onClick:It,disabled:ce||te,children:ce?"Saving...":"Save changes"})]})]})}),I.jsx(vy,{isOpen:Z,onClose:()=>Q(!1),onConfirm:Pt,onCancel:()=>Q(!1),title:"Delete plot",message:`Are you sure you want to delete "${((qt=(Yt=ae==null?void 0:ae.options)==null?void 0:Yt.properties)==null?void 0:qt.name)||((er=ae==null?void 0:ae.properties)==null?void 0:er.name)||(ae==null?void 0:ae.name)||"this plot"}"?`,confirmText:se?"Deleting...":"Delete",cancelText:"Cancel",variant:"destructive"}),I.jsx(r_,{open:le,onOpenChange:Oe=>!Oe&&K(!1),children:I.jsxs(j0,{className:"w-[calc(100vw-2rem)] sm:max-w-lg",children:[I.jsxs(B0,{children:[I.jsx(Au,{children:"Edit Station"}),I.jsx(i_,{children:"Update the station name."})]}),I.jsx("div",{className:"space-y-4",children:I.jsxs("div",{className:"space-y-2",children:[I.jsx("p",{className:"text-sm font-medium text-foreground",children:"Station Name"}),I.jsx(Zo,{value:Te.location_name,onChange:Oe=>rt(Ce=>({...Ce,location_name:Oe.target.value})),placeholder:"Station name",disabled:pe})]})}),I.jsxs(n_,{children:[I.jsx(_r,{variant:"outline",onClick:()=>K(!1),disabled:ye,children:"Cancel"}),I.jsx(_r,{onClick:Xt,disabled:ye||pe,children:ye?"Saving...":"Save changes"})]})]})}),I.jsx(vy,{isOpen:ue,onClose:()=>ge(!1),onConfirm:Dt,onCancel:()=>ge(!1),title:"Delete station",message:`Are you sure you want to delete "${((Pr=Y==null?void 0:Y.properties)==null?void 0:Pr.name)||(Y==null?void 0:Y.name)||"this station"}"?`,confirmText:Ge?"Deleting...":"Delete",cancelText:"Cancel",variant:"destructive"})]})}function TUe({selectedFarm:e,farmOpen:t,setFarmOpen:r,farms:n=[],handleFarmSelect:i,onAddFarm:a}){const[o,s]=j.useState(""),u=j.useMemo(()=>{if(!o.trim())return n;const f=o.toLowerCase();return n.filter(m=>{var g,v;return((g=m.label)==null?void 0:g.toLowerCase().includes(f))||((v=m.details)==null?void 0:v.toLowerCase().includes(f))})},[n,o]),h=(f,m)=>{i(e===m||e===f?null:f),r(!1),s("")};return I.jsxs(wx,{open:t,onOpenChange:r,children:[I.jsx(Sx,{asChild:!0,children:I.jsxs(_r,{variant:"ghost",className:"h-9 sm:h-10 px-2 sm:px-4 rounded-none flex items-center gap-1.5 sm:gap-3 hover:bg-white/50 text-foreground shrink-0",children:[I.jsx(NS,{className:"h-3.5 w-3.5 sm:h-4 sm:w-4 text-muted-foreground shrink-0"}),I.jsxs("div",{className:"flex flex-col items-start leading-none hidden sm:flex",children:[I.jsx("span",{className:"text-[10px] font-bold text-muted-foreground uppercase tracking-wider",children:"Farm"}),I.jsx("span",{className:"text-xs font-bold whitespace-nowrap max-w-[120px] lg:max-w-none truncate",children:e||"Select a farm"})]}),I.jsx(Jl,{className:"h-3 w-3 text-muted-foreground ml-1 shrink-0 hidden sm:block!"})]})}),I.jsx(kE,{className:"w-[calc(100vw-2rem)] sm:w-[280px] p-0 z-[1102]",align:"start",children:I.jsxs("div",{className:"flex flex-col",children:[I.jsxs("div",{className:"flex items-center border-b px-3",children:[I.jsx(mh,{className:"mr-2 h-4 w-4 shrink-0 opacity-50"}),I.jsx(Zo,{placeholder:"Search farm...",value:o,onChange:f=>s(f.target.value),className:"border-none focus-visible:ring-0 focus-visible:ring-offset-0 focus-visible:shadow-none h-11 bg-transparent px-0"})]}),I.jsx("div",{className:"max-h-[350px] overflow-y-auto",children:u.length===0?I.jsx("div",{className:"py-6 text-center text-sm text-muted-foreground",children:"No farm found."}):I.jsxs(I.Fragment,{children:[I.jsx("div",{className:"px-2 py-1.5 text-xs font-medium text-muted-foreground",children:"Farms"}),I.jsx("div",{className:"p-1",children:u.map(f=>I.jsxs("div",{onClick:()=>h(f.value,f.label),className:rr("relative flex w-full cursor-pointer select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none hover:bg-accent hover:text-accent-foreground",(e===f.label||e===f.value)&&"bg-accent text-accent-foreground"),children:[I.jsx(LS,{className:rr("mr-2 h-4 w-4",e===f.label||e===f.value?"opacity-100":"opacity-0")}),I.jsxs("div",{className:"flex flex-col",children:[I.jsx("span",{children:f.label}),I.jsx("span",{className:"text-xs text-muted-foreground",children:f.details})]})]},f.value))})]})}),I.jsx("div",{className:"h-px bg-border mx-1"}),I.jsx("div",{className:"p-2 border-t",children:I.jsxs(_r,{variant:"ghost",className:"w-full justify-start h-9 text-sm font-medium text-muted-foreground hover:text-green-600 hover:bg-green-50",onClick:a,children:[I.jsx(hg,{className:"h-4 w-4 mr-2"}),"Add New Farm"]})})]})})]})}function AUe({enabled:e=!0,handler:t,excludedSelectors:r=[],delay:n=0,eventType:i="mousedown"}){const a=j.useRef(null),o=j.useRef(null),s=j.useCallback(u=>{if(!a.current||!t)return;const h=u.target;if(a.current.contains(h))return;r.some(m=>{const g=h.closest(m);return g&&!a.current.contains(g)})||t(u)},[t,r]);return j.useEffect(()=>{if(!e)return;o.current&&clearTimeout(o.current);const u=()=>{document.addEventListener(i,s),(i==="mousedown"||i==="click")&&document.addEventListener("touchstart",s)};return n>0?o.current=setTimeout(u,n):u(),()=>{o.current&&clearTimeout(o.current),document.removeEventListener(i,s),(i==="mousedown"||i==="click")&&document.removeEventListener("touchstart",s)}},[e,n,i,s]),a}function MUe({mapRef:e}){const[t,r]=j.useState(null),[n,i]=j.useState(null),[a,o]=j.useState(!1),[s,u]=j.useState(""),[h,f]=j.useState(!1);zt(Ee=>Ee.setSidebarExpanded);const m=zt(Ee=>Ee.setViewMode),{markerFilters:g,setMarkerFilters:v,showMarkers:b,setShowMarkers:x,markers:w,unfilteredMarkers:T}=j.useContext(ys),{plots:C}=j.useContext(xs),{farmOptions:M,refreshFarms:O}=j.useContext(yu),P=zt(Ee=>Ee.rasterLayer),k=zt(Ee=>Ee.setRasterLayer),D=zt(Ee=>Ee.showCroppedImages),V=zt(Ee=>Ee.setShowCroppedImages),U=zt(Ee=>Ee.rasterOpacity),X=zt(Ee=>Ee.setRasterOpacity),{isVisible:z,setIsVisible:W}=j.useContext(yp),H=j.useCallback(Ee=>{const Ge=Dm("selected-farm");if(Ge&&Ee.length>0){const We=Ee.find(Te=>Te.value===Ge||Te.value==Ge);if(We){i(We.label),v(Te=>({...Te,farm_id:We.value}));return}}i(null),L2("selected-farm"),v(We=>({...We,farm_id:null}))},[v]);j.useEffect(()=>{M&&M.length>0&&H(M)},[M,H]);const G=j.useCallback(Ee=>{r(t===Ee?null:Ee)},[t]),B=j.useCallback(Ee=>{const Ge=M.find(rt=>rt.value===Ee);if(Ge?(i(Ge.label),Ld("selected-farm",Ee)):(i(null),L2("selected-farm")),o(!1),v({...g,farm_id:Ee||null}),!Ee||!(e!=null&&e.current))return;const We=C.filter(rt=>{const it=rt==null?void 0:rt.farm;return it?(typeof it=="object"?it==null?void 0:it.id:it)==Ee:!1});if(We.length>0){const rt=new Nm.LngLatBounds;let it=!1;if(We.forEach(Be=>{var $e;const je=(($e=Be==null?void 0:Be.options)==null?void 0:$e.geometry)||(Be==null?void 0:Be.geometry);if(je!=null&&je.coordinates){const He=je.type==="Polygon"?je.coordinates[0]:je.coordinates;Array.isArray(He)&&He.forEach(at=>{Array.isArray(at)&&at.length>=2&&(rt.extend([at[0],at[1]]),it=!0)})}}),it){const Be=e.current.getMap();Be&&Be.fitBounds(rt,{padding:100,maxZoom:15,essential:!0});return}}const Te=T==null?void 0:T.find(rt=>{var it;return((it=rt==null?void 0:rt.farm)==null?void 0:it.id)==Ee});if(Te!=null&&Te.lat&&(Te!=null&&Te.lng)){const rt=e.current.getMap();rt&&rt.flyTo({center:[Te.lng,Te.lat],essential:!0,zoom:12})}},[M,g,v,C,T,e]),Z=j.useCallback(()=>{O()},[O]),Q=j.useCallback(Ee=>!Ee||Ee===""?"All":Ee.charAt(0).toUpperCase()+Ee.slice(1).replace(/_/g," "),[]),ae=(g==null?void 0:g.type)||"",oe=(g==null?void 0:g.paw_status)||"",te=D?"plot":"map",ve=j.useCallback(Ee=>{V(Ee==="plot")},[V]),ce=P,q=j.useCallback(Ee=>{k(Ee)},[k]),se=[{value:"",label:"All"},{value:"station",label:"Station"},{value:"forecast",label:"Forecast"}],he=[{value:"",label:"All"},{value:"OPTIMAL",label:"Optimal"},{value:"STRESS_START",label:"Stress"},{value:"SEVERE_STRESS",label:"Severe"}],be=j.useCallback(Ee=>{v({...g,type:Ee})},[g,v]),Ae=j.useCallback(Ee=>{v({...g,paw_status:Ee})},[g,v]),le=j.useCallback(Ee=>{if(!(e!=null&&e.current))return;const Ge=e.current.getMap();Ge&&Ge.getStyle().layers.forEach(We=>{We.id.startsWith("croppedImageLayer-")&&Ge.setPaintProperty(We.id,"raster-opacity",Number(Ee/100))})},[e]),K=xh(le,500),ue=[U],ge=j.useCallback(Ee=>{const Ge=Ee[0];X(Ge),K(Ge)},[X,K]),Y=j.useCallback(()=>{m(Xr.ADD_NEW_FARM),r(null)},[m]),xe=j.useCallback(()=>{m(Xr.ADD_PLOT),r(null)},[m]),pe=j.useCallback(()=>{m(Xr.ADD_MARKER),r(null)},[m]),Me=j.useMemo(()=>{if(!s||s.trim()==="")return[];const Ee=s.toLowerCase().trim(),Ge=[],We=w||[];return M.forEach(Te=>{const rt=(Te.label||"").toLowerCase(),it=(Te.details||"").toLowerCase();(rt.includes(Ee)||it.includes(Ee))&&Ge.push({id:`farm-${Te.value}`,type:"farm",label:Te.label,subLabel:Te.details||"Farm",data:Te})}),C.forEach(Te=>{var je,$e,He,at,Ze,ut,gt,xt,It,ht,Pt,Lt,Xt,Ut,Dt,Yt,qt;const rt=((($e=(je=Te==null?void 0:Te.options)==null?void 0:je.properties)==null?void 0:$e.name)||((He=Te==null?void 0:Te.properties)==null?void 0:He.name)||`Plot ${(Te==null?void 0:Te.id)||""}`).toLowerCase(),it=(((Ze=(at=Te==null?void 0:Te.options)==null?void 0:at.properties)==null?void 0:Ze.farm_name)||((ut=Te==null?void 0:Te.properties)==null?void 0:ut.farm_name)||"Unknown Farm").toLowerCase(),Be=((xt=(gt=Te==null?void 0:Te.options)==null?void 0:gt.properties)==null?void 0:xt.area)||((It=Te==null?void 0:Te.properties)==null?void 0:It.area)||"N/A";if(rt.includes(Ee)||it.includes(Ee)){const er=((Pt=(ht=Te==null?void 0:Te.options)==null?void 0:ht.properties)==null?void 0:Pt.farm_name)||((Lt=Te==null?void 0:Te.properties)==null?void 0:Lt.farm_name)||"Unknown Farm";Ge.push({id:`plot-${(Te==null?void 0:Te.id)||((Ut=(Xt=Te==null?void 0:Te.options)==null?void 0:Xt.properties)==null?void 0:Ut.id)}`,type:"plot",label:((Yt=(Dt=Te==null?void 0:Te.options)==null?void 0:Dt.properties)==null?void 0:Yt.name)||((qt=Te==null?void 0:Te.properties)==null?void 0:qt.name)||`Plot ${(Te==null?void 0:Te.id)||""}`,subLabel:`${er} • ${Be}`,data:Te})}}),We.forEach(Te=>{var at,Ze,ut,gt,xt,It;const rt=((Te==null?void 0:Te.title)||"").toLowerCase(),it=((Te==null?void 0:Te.location_name)||"").toLowerCase(),Be=(((at=Te==null?void 0:Te.device)==null?void 0:at.name)||"").toLowerCase(),je=(((Ze=Te==null?void 0:Te.device)==null?void 0:Ze.serial)||"").toLowerCase(),$e=(((ut=Te==null?void 0:Te.farm)==null?void 0:ut.name)||(Te==null?void 0:Te.farm_name)||"Unknown Farm").toLowerCase(),He=(Te==null?void 0:Te.paw_status)||((gt=Te==null?void 0:Te.properties)==null?void 0:gt.paw_status)||"Unknown";if(rt.includes(Ee)||it.includes(Ee)||Be.includes(Ee)||je.includes(Ee)||$e.includes(Ee)){const ht=((xt=Te==null?void 0:Te.farm)==null?void 0:xt.name)||(Te==null?void 0:Te.farm_name)||"Unknown Farm";Ge.push({id:`station-${(Te==null?void 0:Te.id)||((It=Te==null?void 0:Te.properties)==null?void 0:It.id)}`,type:"station",label:(Te==null?void 0:Te.title)||(Te==null?void 0:Te.location_name)||`Station ${(Te==null?void 0:Te.id)||""}`,subLabel:`${ht} • ${Q(He)}`,data:Te})}}),Ge},[s,M,C,w,Q]),ye=j.useCallback(Ee=>{var Ge,We;if(e!=null&&e.current){if(Ee.type==="farm")B(Ee.data.value),f(!1),u("");else if(Ee.type==="plot"){const Te=Ee.data,rt=((Ge=Te==null?void 0:Te.options)==null?void 0:Ge.geometry)||(Te==null?void 0:Te.geometry);if(rt&&rt.coordinates){const it=rt.coordinates[0]||rt.coordinates;if(it&&it.length>0){let Be=0,je=0;const $e=it.filter(He=>He&&He.length>=2);if($e.forEach(He=>{const[at,Ze]=He;je+=at,Be+=Ze}),$e.length>0){const He=je/$e.length,at=Be/$e.length;e.current.flyTo({center:[He,at],zoom:14})}}}f(!1),u("")}else if(Ee.type==="station"){const Te=Ee.data,rt=(Te==null?void 0:Te.location)||((We=Te==null?void 0:Te.properties)==null?void 0:We.location);if(rt){const it=rt.lat||rt.latitude,Be=rt.lng||rt.longitude;it&&Be&&e.current.flyTo({center:[Be,it],zoom:14})}f(!1),u("")}}},[e,B,f,u]);return j.useEffect(()=>{if(!(e!=null&&e.current)||!h)return;const Ee=e.current.getMap();if(!Ee)return;const Ge=()=>{f(!1);const We=document.querySelector("[data-search-container]");if(We){const Te=We.querySelector('input[type="text"]');Te&&Te.blur()}};return Ee.on("click",Ge),Ee.on("touchstart",Ge),()=>{Ee.off("click",Ge),Ee.off("touchstart",Ge)}},[e,h,f]),I.jsx(IUe,{activePanel:t,togglePanel:G,selectedFarm:n,farmOpen:a,setFarmOpen:o,farms:M,handleFarmSelect:B,markerType:ae,pawStatus:oe,formatLabel:Q,searchQuery:s,setSearchQuery:u,isSearchFocused:h,setIsSearchFocused:f,dataSource:ce,setDataSource:q,viewType:te,setViewType:ve,layerOptions:tg,layerOpacity:ue,setLayerOpacity:ge,layerEnabled:z,setLayerEnabled:W,setMarkerType:be,setPawStatus:Ae,markerTypeOptions:se,pawStatusOptions:he,showMarkers:b,setShowMarkers:x,plots:C||[],markers:w||[],onAddFarm:Y,onAddPlot:xe,onAddStation:pe,searchResults:Me,onSearchResultClick:ye,onFarmsChange:Z})}function IUe({togglePanel:e,activePanel:t,selectedFarm:r,farmOpen:n,setFarmOpen:i,farms:a,handleFarmSelect:o,markerType:s,pawStatus:u,formatLabel:h,searchQuery:f,setSearchQuery:m,isSearchFocused:g,setIsSearchFocused:v,dataSource:b,setDataSource:x,viewType:w,setViewType:T,layerOptions:C=[],layerOpacity:M=[100],setLayerOpacity:O,layerEnabled:P=!0,setLayerEnabled:k,setMarkerType:D,setPawStatus:V,markerTypeOptions:U=[],pawStatusOptions:X=[],showMarkers:z=!0,setShowMarkers:W,plots:H=[],markers:G=[],onAddFarm:B,onAddPlot:Z,onAddStation:Q,onFarmsChange:ae,searchResults:oe=[],onSearchResultClick:te}){j.useContext(qi);const ve=j.useRef(null),ce=AUe({enabled:g,handler:()=>{v(!1),ve.current&&ve.current.blur()},excludedSelectors:[],delay:100});return I.jsxs(I.Fragment,{children:[I.jsx("div",{className:"absolute top-2 sm:top-4 left-2 right-2 sm:left-auto sm:right-auto w-auto sm:w-full z-[1100] flex justify-center pointer-events-none",children:I.jsxs("div",{className:"bg-white/90 backdrop-blur-xl border border-white/50 shadow-sm rounded-md flex items-center pointer-events-auto w-full sm:w-auto max-w-full overflow-visible flex-wrap sm:flex-nowrap",children:[I.jsx(_r,{variant:"ghost",size:"icon",className:"w-9 h-9 sm:w-10 sm:h-10 rounded-l-md rounded-r-none text-muted-foreground hover:bg-white/50 hover:text-foreground shrink-0",onClick:()=>e("settings"),"aria-label":"Settings",children:I.jsx(jne,{className:"h-4 w-4 sm:h-5 sm:w-5"})}),I.jsx("div",{className:"w-px h-5 sm:h-6 bg-border hidden sm:block!"}),I.jsxs(_r,{variant:"ghost",className:"h-9 sm:h-10 px-2 sm:px-4 rounded-none flex items-center gap-1.5 sm:gap-3 hover:bg-white/50 text-foreground shrink-0",onClick:()=>e("layers"),children:[I.jsx(ug,{className:"h-3.5 w-3.5 sm:h-4 sm:w-4 text-muted-foreground shrink-0"}),I.jsxs("div",{className:"flex flex-col items-start leading-none hidden sm:flex",children:[I.jsx("span",{className:"text-[10px] font-bold text-muted-foreground uppercase tracking-wider",children:"Layer"}),I.jsxs("span",{className:"text-xs font-bold whitespace-nowrap",children:[(b==null?void 0:b.label)||"Evapo"," ",I.jsxs("span",{className:"text-muted-foreground font-normal",children:["• ",w==="plot"?"Plot View":"Map View"]})]})]}),I.jsx(Jl,{className:"h-3 w-3 text-muted-foreground ml-1 shrink-0 hidden sm:block!"})]}),I.jsx("div",{className:"w-px h-5 sm:h-6 bg-border hidden sm:block!"}),I.jsxs(_r,{variant:"ghost",className:"h-9 sm:h-10 px-2 sm:px-4 rounded-none flex items-center gap-1.5 sm:gap-3 hover:bg-white/50 text-foreground shrink-0",onClick:()=>e("stations"),children:[I.jsx(Zv,{className:"h-3.5 w-3.5 sm:h-4 sm:w-4 text-muted-foreground shrink-0"}),I.jsxs("div",{className:"flex flex-col items-start leading-none hidden sm:flex",children:[I.jsx("span",{className:"text-[10px] font-bold text-muted-foreground uppercase tracking-wider",children:"Filter"}),I.jsxs("span",{className:"text-xs font-bold whitespace-nowrap",children:[h(s)," ",I.jsx("span",{className:"text-muted-foreground font-normal",children:"•"})," ",h(u)]})]}),I.jsx(Jl,{className:"h-3 w-3 text-muted-foreground ml-1 shrink-0 hidden sm:block!"})]}),I.jsx("div",{className:"w-px h-5 sm:h-6 bg-border hidden sm:block!"}),I.jsx(TUe,{selectedFarm:r,farmOpen:n,setFarmOpen:i,farms:a,handleFarmSelect:o,onAddFarm:B}),I.jsx("div",{className:"w-px h-5 sm:h-6 bg-border hidden sm:block!"}),I.jsxs("div",{ref:ce,"data-search-container":!0,className:"relative flex-1 sm:flex-none min-w-0 overflow-visible",children:[I.jsxs("div",{className:rr("flex items-center gap-2 px-2 sm:px-3 h-9 sm:h-10 rounded-r-md transition-all duration-300",g?"w-full sm:w-64 bg-white":"w-full sm:w-40 hover:bg-white/50"),children:[I.jsx(mh,{className:"h-3.5 w-3.5 sm:h-4 sm:w-4 text-muted-foreground shrink-0"}),I.jsx(Zo,{ref:ve,type:"text",placeholder:"Search...",value:f,onChange:q=>m(q.target.value),onFocus:()=>v(!0),className:"bg-transparent border-none focus-visible:ring-0 focus-visible:ring-offset-0 focus-visible:shadow-none text-xs sm:text-sm h-full placeholder:text-muted-foreground/70 px-0 w-full min-w-0"})]}),I.jsx(FGe,{isSearchFocused:g,searchQuery:f,searchResults:oe,onResultClick:te})]})]})}),I.jsx(JWe,{activePanel:t,togglePanel:e,viewType:w,setViewType:T,dataSource:b,setDataSource:x,layerOptions:C,layerOpacity:M,setLayerOpacity:O,layerEnabled:P,setLayerEnabled:k}),I.jsx(rUe,{activePanel:t,togglePanel:e,markerType:s,setMarkerType:D,pawStatus:u,setPawStatus:V,markerTypeOptions:U,pawStatusOptions:X,showMarkers:z,setShowMarkers:W,formatLabel:h}),I.jsx(CUe,{activePanel:t,togglePanel:e,farms:a,plots:H,markers:G,formatLabel:h,onAddFarm:B,onAddPlot:Z,onAddStation:Q,onFarmsChange:ae})]})}const BU=ie.forwardRef(({className:e,value:t,...r},n)=>{const i=Math.min(Math.max(t||0,0),100);return I.jsx("div",{ref:n,className:rr("relative h-4 w-full overflow-hidden rounded-full bg-secondary",e),...r,children:I.jsx("div",{className:"h-full bg-primary transition-all",style:{width:`${i}%`}})})});BU.displayName="Progress";function PUe(e){return j.useMemo(()=>{if(!e)return null;const t=e.stopped||0,r=e.running||0,n=e.pending||0,i=e.failed||0,a=t+r+n+i;if(a===0)return null;const o=t,s=a,u=o/s*100,h=Math.max(0,s-o),f=o>=s,m=(r>0||n>0)&&!f;return{daysGenerated:o,totalDays:s,percentage:u,daysRemaining:h,isComplete:f,isGenerating:m}},[e])}function OUe({className:e,loading:t,tasksStats:r}){const n=PUe(r);if(t)return I.jsx("div",{className:rr("bg-card/95 backdrop-blur-sm border border-border rounded-lg shadow-lg p-2 sm:p-3 min-w-[200px] sm:min-w-[280px] max-w-[calc(100vw-2rem)]",e),children:I.jsx("div",{className:"space-y-1.5 sm:space-y-2",children:I.jsxs("div",{className:"flex items-center gap-1.5 sm:gap-2",children:[I.jsx("div",{className:"w-1.5 h-1.5 sm:w-2 sm:h-2 rounded-full bg-muted-foreground animate-pulse flex-shrink-0"}),I.jsx("span",{className:"text-xs sm:text-sm font-medium text-foreground truncate",children:"Loading ET Data..."})]})})});if(!n)return I.jsx("div",{className:rr("bg-card/95 backdrop-blur-sm border border-border rounded-lg shadow-lg p-2 sm:p-3 min-w-[200px] sm:min-w-[280px] max-w-[calc(100vw-2rem)]",e),children:I.jsx("div",{className:"space-y-1.5 sm:space-y-2",children:I.jsxs("div",{className:"flex items-center gap-1.5 sm:gap-2",children:[I.jsx("div",{className:"w-1.5 h-1.5 sm:w-2 sm:h-2 rounded-full bg-chart-1 animate-pulse flex-shrink-0"}),I.jsx("span",{className:"text-xs sm:text-sm font-medium text-foreground truncate",children:"Generating ET Data"})]})})});const{daysGenerated:i,totalDays:a,percentage:o,daysRemaining:s,isComplete:u,isGenerating:h}=n;return I.jsx("div",{className:rr("bg-card/95 backdrop-blur-sm border border-border rounded-lg shadow-lg p-2 sm:p-3 min-w-[200px] sm:min-w-[280px] max-w-[calc(100vw-2rem)]",e),children:I.jsxs("div",{className:"space-y-1.5 sm:space-y-2",children:[I.jsx("div",{className:"flex items-center justify-between gap-1.5 sm:gap-2",children:I.jsxs("div",{className:"flex items-center gap-1.5 sm:gap-2 min-w-0 flex-1",children:[I.jsx("div",{className:rr("w-1.5 h-1.5 sm:w-2 sm:h-2 rounded-full flex-shrink-0",h?"bg-chart-1 animate-pulse":"bg-green-500")}),I.jsx("span",{className:"text-xs sm:text-sm font-medium text-foreground truncate",children:h?"Generating ET Data":"ET Data Ready"})]})}),I.jsx(BU,{value:o,className:"h-1.5 sm:h-2"}),I.jsxs("div",{className:"flex items-center justify-between gap-2 text-[10px] sm:text-xs",children:[I.jsxs("span",{className:"text-muted-foreground truncate",children:[i," of ",a," days"]}),I.jsx("span",{className:rr("font-medium flex-shrink-0",u?"text-green-500":"text-chart-1"),children:u?"100%":s>0?`${s} remaining`:`${Math.round(o)}%`})]})]})})}function kUe({className:e,mapRef:t}){const n=zt(v=>v.hoveredFarmId),{farms:i}=j.useContext(yu)||{},[a,o]=j.useState(null),[s,u]=j.useState(!1),h=j.useRef(null),f=j.useRef(null),m=j.useCallback(()=>{var X;if(!(t!=null&&t.current)||!n||!i||i.length===0)return!1;const v=t.current.getMap();if(!v||v.getZoom()<10)return!1;const x=v.getBounds();if(!x)return!1;const w=i.find(z=>(z==null?void 0:z.id)===n);if(!((X=w==null?void 0:w.options)!=null&&X.geometry))return!1;const T=Zl(w.options.geometry),[C,M,O,P]=T,[[k,D],[V,U]]=x.toArray();return C>=k&&O<=V&&M>=D&&P<=U},[t,n,i]),g=j.useCallback(()=>{if(f.current&&(clearTimeout(f.current),f.current=null),!n){o(null),u(!1),h.current=null;return}if(!m()){o(null),u(!1),h.current=null;return}n!==h.current&&(f.current=setTimeout(()=>{n!==h.current&&m()&&(h.current=n,u(!0),lC(n).then(v=>{h.current===n&&m()&&o(v)}).catch(v=>{h.current===n&&o(null)}).finally(()=>{h.current===n&&u(!1)}))},300))},[n,m]);return j.useEffect(()=>(g(),()=>{f.current&&(clearTimeout(f.current),f.current=null)}),[g]),j.useEffect(()=>{if(!(t!=null&&t.current)||!n)return;const v=t.current.getMap();if(!v)return;let b;const x=()=>{clearTimeout(b),b=setTimeout(()=>{g()},200)};return v.on("moveend",x),v.on("zoomend",x),()=>{clearTimeout(b),v.off("moveend",x),v.off("zoomend",x)}},[t,n,g]),j.useEffect(()=>{if(!n||!a||!m()||!((a.running||0)>0||(a.pending||0)>0))return;const b=setInterval(()=>{m()&&lC(n).then(x=>{m()&&o(x)}).catch(x=>{})},5e3);return()=>{clearInterval(b)}},[n,a,t,i,m]),n?I.jsx(OUe,{className:e,loading:s,tasksStats:a}):null}const $U=(e,t)=>{var n;return`${(n=RQ.find(i=>i.id===e))==null?void 0:n.url}?key=${t}`},zU=e=>{j.useEffect(()=>{if(!(e!=null&&e.current))return;const t=e.current.getMap();if(!(t!=null&&t.scrollZoom))return;const r=()=>{t.scrollZoom&&t.scrollZoom.disable()};return t.loaded()?r():t.once("load",r),()=>{t&&t.off("load",r)}},[e])},VU=e=>r=>{e(r?{start:r,end:r}:{start:void 0,end:void 0})};function DUe({style:e,configs:t}){const{settings:r}=j.useContext(rg),{mapRef:n,mapContainerRef:i}=j.useContext(qi),a=j.useRef(),o=QQ(),[s,u]=j.useState(o),h=zt(W=>W.viewMode),f=zt(W=>W.mapMode),m=zt(W=>W.cursor),g=zt(W=>W.setConfigs);zt(W=>W.sidebarExpanded),z0();const v=zt(W=>W.showCroppedImages),b=zt(W=>W.dateRange),x=zt(W=>W.setDateRange),w=zt(W=>W.dateRange2),T=zt(W=>W.setDateRange2),C=j.useCallback(W=>u(W.viewState),[]),M=j.useRef(null),O=j.useCallback(W=>{M.current&&clearTimeout(M.current),M.current=setTimeout(()=>{try{F2("map-viewport",W)}catch{}},1e3)},[]);j.useEffect(()=>{try{const W=YO("map-viewport");W&&u(W)}catch{}},[]),j.useEffect(()=>()=>{M.current&&clearTimeout(M.current)},[]);const P=j.useCallback(W=>{O(W.viewState)},[O]),k=j.useCallback(W=>{O(W.viewState)},[O]);j.useEffect(()=>{if(f)try{Ld("map-mode",f)}catch{}},[f]);const D=j.useMemo(()=>VU(x),[x]),V=j.useMemo(()=>VU(T),[T]),[U,X]=j.useState($U(r.basemap.id,t==null?void 0:t.VITE_MAPTILER_ACCESS_KEY));j.useEffect(()=>{X($U(r.basemap.id,t==null?void 0:t.VITE_MAPTILER_ACCESS_KEY))},[r]),j.useEffect(()=>{g(t)},[]),j.useEffect(()=>{},[b,w]),zU(n),zU(a);const z=j.useMemo(()=>({initialViewState:o,...s,onMove:C,onMoveEnd:P,onZoomEnd:k,style:{width:"100%",...e},mapStyle:typeof U=="string"?U:U.toJS(),attributionControl:!1,reuseMaps:!0,preserveDrawingBuffer:!0,cursor:m,scrollZoom:!1}),[o,s,C,P,k,e,U,m]);return o?I.jsx(zFe,{children:I.jsxs("div",{ref:i,style:{width:"100%",height:"80vh"},className:"flex flex-row relative",children:[I.jsxs(mD,{id:"myMap",ref:n,...z,children:[!v&&I.jsx(_W,{mapRef:n,dateRange:b}),f==Ds.NORMAL&&I.jsx(MUe,{mapRef:n}),f==Ds.NORMAL&&I.jsx("div",{className:"absolute top-16 sm:top-4 left-2 sm:left-4 right-2 sm:right-auto z-[1200] pointer-events-none",children:I.jsx("div",{className:"pointer-events-auto flex flex-col sm:flex-row gap-2 justify-start",children:I.jsx(kUe,{mapRef:n})})}),I.jsx("div",{className:"absolute top-0 left-0",children:f==Ds.COMPARISION_VIEW&&I.jsx(Ex,{compact:!0,onDateSelect:D,mapRef:n,dateRange:b,autoRefresh:!0,autoRefreshMinutes:5})}),f===Ds.NORMAL&&I.jsx(CW,{dateRange:b,mapRef:n}),f!==Ds.NORMAL&&I.jsx("div",{className:"absolute top-0 right-0 m-2",style:{zIndex:2},children:I.jsx(EW,{dateRange:b,mapRef:n,showButton:!1})}),h!==Xr.PICKER&&I.jsx("div",{className:"absolute bottom-4 left-4",style:{zIndex:3},children:I.jsx(_Fe,{})}),I.jsxs("div",{className:"absolute bottom-20 right-4 lg:bottom-4 lg:right-20 flex flex-col gap-4 items-end",style:{zIndex:10},children:[I.jsx(MW,{mapRef:n}),I.jsx("div",{className:"hidden lg:block",children:I.jsx(wW,{})})]}),I.jsx("div",{className:"absolute bottom-16 left-0 right-0 flex justify-center lg:hidden",style:{zIndex:10},children:I.jsx(wW,{})}),I.jsx("div",{className:"absolute bottom-4 left-0 right-0 flex justify-center items-center",style:{zIndex:3},children:I.jsx(dle,{mapRef:n,configs:t,onDateSelect:D})}),I.jsx(H7e,{}),h==Xr.EDIT_PLOT&&I.jsx(_Ge,{}),h==Xr.ADD_PLOT&&I.jsx(wGe,{}),h==Xr.ADD_MARKER&&I.jsx(SGe,{}),h==Xr.ADD_NEW_FARM&&I.jsx(EGe,{}),I.jsx($le,{}),I.jsx(Dme,{}),I.jsx(l7e,{mapRef:n}),I.jsx(R$,{mapRef:n,dateRange:b}),I.jsx(X7e,{}),I.jsx(TGe,{})]}),f===Ds.COMPARISION_VIEW&&I.jsxs(mD,{id:"myMap2",ref:a,...z,children:[!v&&I.jsx(_W,{mapRef:a,dateRange:w}),I.jsx("div",{className:"absolute top-0 left-0",children:I.jsx(Ex,{compact:!0,onDateSelect:V,mapRef:a,dateRange:w})}),I.jsx(CW,{dateRange:w,mapRef:a}),I.jsx("div",{className:"absolute bottom-4 right-20 flex flex-col gap-4 items-end",style:{zIndex:3},children:I.jsx(MW,{mapRef:a})}),I.jsx(R$,{mapRef:a,dateRange:w})]}),I.jsx(vGe,{})]})}):I.jsx(Ja,{})}var NUe={},GU={};(function(e){function t(T){"@babel/helpers - typeof";return t=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(C){return typeof C}:function(C){return C&&typeof Symbol=="function"&&C.constructor===Symbol&&C!==Symbol.prototype?"symbol":typeof C},t(T)}Object.defineProperty(e,"__esModule",{value:!0}),e.default=void 0;var r=a(j),n=["dispose","reject","resolve"];function i(T){if(typeof WeakMap!="function")return null;var C=new WeakMap,M=new WeakMap;return(i=function(P){return P?M:C})(T)}function a(T,C){if(T&&T.__esModule)return T;if(T===null||t(T)!=="object"&&typeof T!="function")return{default:T};var M=i(C);if(M&&M.has(T))return M.get(T);var O={},P=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var k in T)if(k!=="default"&&Object.prototype.hasOwnProperty.call(T,k)){var D=P?Object.getOwnPropertyDescriptor(T,k):null;D&&(D.get||D.set)?Object.defineProperty(O,k,D):O[k]=T[k]}return O.default=T,M&&M.set(T,O),O}function o(){return o=Object.assign||function(T){for(var C=1;C<arguments.length;C++){var M=arguments[C];for(var O in M)Object.prototype.hasOwnProperty.call(M,O)&&(T[O]=M[O])}return T},o.apply(this,arguments)}function s(T,C){return g(T)||m(T,C)||h(T,C)||u()}function u(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
1333
+ `}},plotOptions:{column:{dataLabels:{enabled:!1},borderWidth:0,groupPadding:.1,pointPadding:.05}},series:[{name:"Pixel Count",data:r}],credits:{enabled:!1},legend:{enabled:!1}};return I.jsx(Sg,{highcharts:mo,options:n})}const tw=new Map,IGe=async e=>{var r,n,i;const t=e.id||((r=e.options)==null?void 0:r.id)||((i=(n=e.options)==null?void 0:n.properties)==null?void 0:i.id);if(tw.has(t))return tw.get(t);try{const a=await khe({stationId:e==null?void 0:e.device,plotId:t});return tw.set(t,a),a}catch{return null}},PGe=(e,t,r)=>{const[n,i]=j.useState(!1);return j.useRef(new Set),zt(a=>a.passDates),zt(a=>a.hoveredFarmId),j.useCallback(()=>{if(!(e!=null&&e.current)||!t||t.length===0)return[];const a=e.current.getMap();if(!a)return[];const o=a.getBounds();return o?t.filter(s=>{var T;if(!((T=s==null?void 0:s.options)!=null&&T.geometry))return!1;const u=Zl(s.options.geometry),[h,f,m,g]=u,[[v,b],[x,w]]=o.toArray();return!(h>x||m<v||f>w||g<b)}):[]},[t,e]),j.useCallback((a,o)=>!a||!o||o.length===0?[]:o.filter(s=>{var f,m;const u=(s==null?void 0:s.farm)||((m=(f=s==null?void 0:s.options)==null?void 0:f.properties)==null?void 0:m.farm);return u?(typeof u=="object"?u==null?void 0:u.id:u)==a:!1}),[]),j.useCallback(async a=>{if(!a||a.length===0)return;const o=a.filter(s=>{var h,f,m;const u=s.id||((h=s.options)==null?void 0:h.id)||((m=(f=s.options)==null?void 0:f.properties)==null?void 0:m.id);return!tw.has(u)});o.length!==0&&await Promise.allSettled(o.map(s=>IGe(s)))},[]),j.useCallback(async()=>{},[]),{prefetching:n}},TW=new Map,OGe=e=>{const t=new Date(e);return`${t.getFullYear()}-${String(t.getMonth()+1).padStart(2,"0")}`},AW=(e,t)=>{var i,a,o;const r=e.id||((i=e.options)==null?void 0:i.id)||((o=(a=e.options)==null?void 0:a.properties)==null?void 0:o.id),n=OGe(t);return`${r}_${n}`},kGe=(e,t)=>{if(!e||!t)return null;const r=AW(e,t);return TW.get(r)||null},DGe=(e,t,r)=>{if(!e||!t||!r)return;const n=AW(e,t);TW.set(n,r)},rw=[[-.5,12,12,12],[-.2,191,191,191],[-.1,219,219,219],[0,234,234,234],[.025,255,249,204],[.05,237,232,181],[.075,221,216,155],[.1,204,198,130],[.125,188,183,107],[.15,175,193,96],[.175,163,204,89],[.2,145,191,81],[.25,127,178,71],[.3,112,163,63],[.35,96,150,53],[.4,79,137,45],[.45,63,124,35],[.5,48,109,28],[.55,33,96,17],[.6,15,84,10],[1,0,68,0]];function NGe(e,t,r){let n=0,i=1/0;for(let a=0;a<rw.length-1;a++){const[o,s,u,h]=rw[a],[f,m,g,v]=rw[a+1],b=m-s,x=g-u,w=v-h,T=b*b+x*x+w*w;let C;T<1e-12?C=0:(C=((e-s)*b+(t-u)*x+(r-h)*w)/T,C<0&&(C=0),C>1&&(C=1));const M=s+C*b,O=u+C*x,P=h+C*w,k=(e-M)*(e-M)+(t-O)*(t-O)+(r-P)*(r-P);k<i&&(i=k,n=o+C*(f-o))}{const[a,o,s,u]=rw[0],h=(e-o)*(e-o)+(t-s)*(t-s)+(r-u)*(r-u);h<i&&(i=h,n=a)}return n}async function LGe({mapRef:e,plot:t,startDate:r,endDate:n,bins:i=32}){var ve,ce;if(!(e!=null&&e.current)||!((ve=t==null?void 0:t.options)!=null&&ve.geometry))return null;const a=e.current.getMap();if(!a)return null;const o=a.getCanvas();if(!o)return null;const s=document.createElement("canvas");s.width=o.width,s.height=o.height;const u=s.getContext("2d");try{u.drawImage(o,0,0)}catch{return null}const h=t.options.geometry;if(!h)return null;const f=h.type==="Polygon"?[h.coordinates]:h.coordinates||[],m=(ce=a.getContainer)==null?void 0:ce.call(a),g=(m==null?void 0:m.clientWidth)||o.clientWidth||o.width,v=(m==null?void 0:m.clientHeight)||o.clientHeight||o.height,b=g>0?o.width/g:1,x=v>0?o.height/v:1,w=f.map(q=>q.map(se=>se.map(([he,be])=>{const Ae=a.project({lng:he,lat:be});return[Math.round(Ae.x*b),Math.round(Ae.y*x)]})));function T(q,se,he){let be=!1;for(let Ae=0,le=he.length-1;Ae<he.length;le=Ae++){const K=he[Ae][0],ue=he[Ae][1],ge=he[le][0],Y=he[le][1];ue>se!=Y>se&&q<(ge-K)*(se-ue)/(Y-ue+0)+K&&(be=!be)}return be}const C=s.width,M=s.height;let O=C,P=M,k=0,D=0;if(w.forEach(q=>q.forEach(se=>se.forEach(([he,be])=>{O=Math.max(0,Math.min(O,he)),P=Math.max(0,Math.min(P,be)),k=Math.min(C-1,Math.max(k,he)),D=Math.min(M-1,Math.max(D,be))}))),O>k||P>D)return null;O=Math.floor(O),P=Math.floor(P),k=Math.ceil(k),D=Math.ceil(D);let V;try{V=u.getImageData(O,P,k-O+1,D-P+1).data}catch{return null}const U=new Array(i).fill(0),X=-1,W=(1-X)/i,H=k-O+1,G=D-P+1;for(let q=0;q<G;q++)for(let se=0;se<H;se++){const he=se+O,be=q+P;let Ae=!1;for(const Me of w){for(const ye of Me)if(T(he,be,ye)){Ae=!0;break}if(Ae)break}if(!Ae)continue;const le=(q*H+se)*4,K=V[le],ue=V[le+1],ge=V[le+2];if(V[le+3]===0)continue;const xe=NGe(K,ue,ge);let pe=Math.floor((xe-X)/W);pe<0&&(pe=0),pe>=i&&(pe=i-1),U[pe]+=1}if(U.reduce((q,se)=>q+se,0)===0)return null;const Z=new Array(i).fill(0).map((q,se)=>({lowEdge:X+se*W,highEdge:X+(se+1)*W}));let Q=0;for(;Q<i&&U[Q]===0;)Q++;let ae=i-1;for(;ae>=Q&&U[ae]===0;)ae--;const oe=Z.slice(Q,ae+1),te=U.slice(Q,ae+1);return te.some(q=>q>0)?{data:[{interval:{from:r instanceof Date?r.toISOString():new Date(r).toISOString(),to:n instanceof Date?n.toISOString():new Date(n).toISOString()},outputs:{index:{bands:{B0:{histogram:{bins:oe,counts:te}}}}}}]}:null}function MW({mapRef:e,EnableSentinalHistogram:t=!1}){var ae,oe;const r=Kn(),{plots:n,setClickedPlot:i}=j.useContext(xs),{accessToken:a}=j.useContext(G0),o=zt(te=>te.dateRange),s=zt(te=>te.setPickerData),u=zt(te=>te.setHoveredPlot),h=zt(te=>te.rasterLayer),f=zt(te=>te.viewMode),m=zt(te=>te.rasterLayerLoading),{isRasterVisible:g}=j.useContext(yp),[v,b]=j.useState(null),[x,w]=j.useState(null),[T,C]=j.useState(null),[M,O]=j.useState(null),[P,k]=j.useState(!1),[D,V]=j.useState(!1),[U,X]=j.useState("local");j.useEffect(()=>{!t&&U!=="local"&&X("local")},[t,U]),PGe(e,n),j.useEffect(()=>{if(!(e!=null&&e.current)||!v||f!==Xr.NORMAL)return;const te=e.current.getMap();if(!te)return;const ve=`plot-highlight-${v.id}`,ce=`plot-highlight-outline-${v.id}`,q=`plot-highlight-source-${v.id}`;return te.getLayer(ve)&&te.removeLayer(ve),te.getLayer(ce)&&te.removeLayer(ce),te.getSource(q)&&te.removeSource(q),te.addSource(q,{type:"geojson",data:v.options.geometry}),te.addLayer({id:ce,type:"line",source:q,layout:{"line-cap":"round","line-join":"round"},paint:{"line-color":"#ffffff","line-width":4,"line-opacity":1}}),te.addLayer({id:ve,type:"line",source:q,layout:{"line-cap":"round","line-join":"round"},paint:{"line-color":"#16a34a","line-width":6,"line-opacity":1}},ce),()=>{te.getLayer(ve)&&te.removeLayer(ve),te.getLayer(ce)&&te.removeLayer(ce),te.getSource(q)&&te.removeSource(q)}},[v,e]),j.useEffect(()=>{if(!(e!=null&&e.current))return;const te=e.current.getMap();if(!te)return;const ve=q=>{var he,be,Ae;if(!te.getLayer("plots-layer"))return;const se=te.queryRenderedFeatures(q.point,{layers:["plots-layer"]});if(se.length>0){const le=se[0],K=((he=le.properties)==null?void 0:he.plot_id)||((be=le.properties)==null?void 0:be.plotId);let ue=K?n.find(ge=>ge.id===K):null;if(!ue&&((Ae=le.properties)!=null&&Ae.id)&&(ue=n.find(ge=>{var Y;return((Y=ge.options)==null?void 0:Y.id)===le.properties.id})),ue&&ue.id!==(v==null?void 0:v.id)){b(ue),u(ue),i(null);const ge=zt.getState().pickerData;ge!=null&&ge.plot||s(null)}}},ce=q=>{te.queryRenderedFeatures(q.point,{layers:["plots-layer"]}).length===0&&(b(null),u(null))};return te.on("mousemove",ve),te.on("click",ce),()=>{te.off("mousemove",ve),te.off("click",ce)}},[n,e,v,i,s,u]);const z=j.useCallback(te=>new Date(te).toISOString().split("T")[0],[]),W=j.useCallback((te,ve)=>{if(!te||te.length===0)return null;const ce=z(ve),q=te.find(Ae=>z(Ae.interval.from)===ce);if(q)return q;const se=new Date(ve).getTime();let he=null,be=1/0;return te.forEach(Ae=>{const le=new Date(Ae.interval.from).getTime(),K=Math.abs(le-se);K<be&&(be=K,he=Ae)}),he},[z]);j.useEffect(()=>{if(h.value==="ET"){w(null),C(null),k(!1);return}if(!v||!a||!(o!=null&&o.start)){w(null),C(null),k(!1);return}let te=!1;return(async()=>{var ce;V(!0),k(!0);try{const q=new Date(o.start),se=CD(q),he=ED(q),be=new Date(Date.UTC(se.getFullYear(),se.getMonth(),se.getDate(),0,0,0,0)),Ae=new Date(Date.UTC(he.getFullYear(),he.getMonth(),he.getDate(),23,59,59,999));let le=null;try{const K=(ce=e==null?void 0:e.current)==null?void 0:ce.getMap();K&&K.getLayer&&K.getLayer(`croppedImageLayer-${v.options.id}`)?m?(le=null,O("Raster tiles are still loading"),k(!0)):(le=await LGe({mapRef:e,plot:v,startDate:be,endDate:Ae,bins:32}),O(le?null:"Local histogram unavailable (canvas may be tainted or tiles use a color ramp)"),k(!1)):(le=null,O("Raster layer not present in current map style"),k(!1))}catch{le=null,O("Local histogram computation error (see console)"),k(!1)}if(le&&le.data&&le.data.length>0){const K=W(le.data,q);C(K?[K]:null)}else C(null);if(k(!!m),t){let K=null;const ue=kGe(v,q);ue?K=ue:(K=await VO({plot:v,accessToken:a,startDate:be.toISOString(),endDate:Ae.toISOString()}),K&&DGe(v,q,K));const ge=K&&K.data?W(K.data,q):null;w(ge?[ge]:null)}else w(null)}catch{te||(w(null),k(!1))}finally{te||V(!1)}})(),()=>{te=!0}},[v==null?void 0:v.id,a,o==null?void 0:o.start,W,h.value,m]);const H=j.useMemo(()=>{var se,he,be,Ae,le;if(!(x!=null&&x.length))return null;const te=x[0],ve=(Ae=(be=(he=(se=te==null?void 0:te.outputs)==null?void 0:se.index)==null?void 0:he.bands)==null?void 0:be.B0)==null?void 0:Ae.histogram;if(!(ve!=null&&ve.bins))return null;const{bins:ce,counts:q}=ve;return!q&&((le=ce[0])==null?void 0:le.count)!==void 0?ce.map(K=>({ndviRange:`${K.lowEdge.toFixed(2)} - ${K.highEdge.toFixed(2)}`,ndviValue:(K.lowEdge+K.highEdge)/2,count:K.count||0,lowEdge:K.lowEdge,highEdge:K.highEdge})):!Array.isArray(q)||q.length!==ce.length?null:ce.map((K,ue)=>({ndviRange:`${K.lowEdge.toFixed(2)} - ${K.highEdge.toFixed(2)}`,ndviValue:(K.lowEdge+K.highEdge)/2,count:q[ue]||0,lowEdge:K.lowEdge,highEdge:K.highEdge}))},[x]),G=j.useMemo(()=>{var se,he,be,Ae,le;if(!(T!=null&&T.length))return null;const te=T[0],ve=(Ae=(be=(he=(se=te==null?void 0:te.outputs)==null?void 0:se.index)==null?void 0:he.bands)==null?void 0:be.B0)==null?void 0:Ae.histogram;if(!(ve!=null&&ve.bins))return null;const{bins:ce,counts:q}=ve;return!q&&((le=ce[0])==null?void 0:le.count)!==void 0?ce.map(K=>({ndviRange:`${K.lowEdge.toFixed(2)} - ${K.highEdge.toFixed(2)}`,ndviValue:(K.lowEdge+K.highEdge)/2,count:K.count||0,lowEdge:K.lowEdge,highEdge:K.highEdge})):!Array.isArray(q)||q.length!==ce.length?null:ce.map((K,ue)=>({ndviRange:`${K.lowEdge.toFixed(2)} - ${K.highEdge.toFixed(2)}`,ndviValue:(K.lowEdge+K.highEdge)/2,count:q[ue]||0,lowEdge:K.lowEdge,highEdge:K.highEdge}))},[T]),B=U==="local"?G:H,Z=U==="local"?P||m:D,Q=U==="local"?M||"No local histogram data available":"No Sentinel histogram data available";return!v||h.value==="ET"||f!==Xr.NORMAL||!g?null:I.jsxs("div",{className:`bg-white dark:bg-zinc-800 rounded-lg shadow-lg border border-gray-200 dark:border-gray-700 ${h.value==="ET"?"w-[500px]":"w-[320px]"}`,children:[I.jsxs("div",{className:"flex items-center justify-between px-3 py-2 border-b border-gray-200 dark:border-gray-700",children:[I.jsxs("div",{className:"flex items-center gap-2",children:[I.jsx(Ane,{className:"h-5 w-5 text-primary"}),I.jsxs("div",{children:[I.jsx("h4",{className:"text-sm font-semibold text-gray-900 dark:text-gray-100",children:h.value==="ET"?r.formatMessage({id:"app.agviewer_map.et_monthly_graph",defaultMessage:"ET Monthly Graph"}):r.formatMessage({id:"app.agviewer_map.ndvi_histogram",defaultMessage:"NDVI Histogram"})}),v&&I.jsx("p",{className:"text-xs text-gray-600 dark:text-gray-400",children:v.name||`Plot ${v.id}`}),!v&&I.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400 italic",children:r.formatMessage({id:"app.agviewer_map.hover_plot_histogram",defaultMessage:"Hover over a plot to view its histogram"})})]})]}),h.value!=="ET"&&t&&I.jsxs("div",{className:"flex items-center gap-1 bg-gray-100 dark:bg-zinc-700 rounded-md p-0.5",children:[I.jsx("button",{type:"button",onClick:()=>X("local"),className:`px-2 py-1 text-xs rounded-md transition ${U==="local"?"bg-white dark:bg-zinc-900 text-gray-900 dark:text-gray-100 shadow":"text-gray-600 dark:text-gray-300 hover:text-gray-900 dark:hover:text-gray-100"}`,children:"Local"}),I.jsx("button",{type:"button",onClick:()=>X("sentinel"),className:`px-2 py-1 text-xs rounded-md transition ${U==="sentinel"?"bg-white dark:bg-zinc-900 text-gray-900 dark:text-gray-100 shadow":"text-gray-600 dark:text-gray-300 hover:text-gray-900 dark:hover:text-gray-100"}`,children:"Sentinel"})]})]}),I.jsx("div",{className:"px-3 py-2",children:h.value==="ET"?null:I.jsx("div",{children:Z?I.jsx("div",{className:"flex items-center justify-center h-24",children:I.jsx(Ja,{})}):B?I.jsx(MGe,{data:B}):I.jsx("div",{className:"text-xs text-gray-500 dark:text-gray-400 italic",children:Q})})}),h.value!=="ET"&&B&&I.jsx("div",{className:"px-3 py-2 border-t border-gray-200 dark:border-gray-700 bg-gray-50 dark:bg-zinc-900/50",children:I.jsxs("div",{className:"grid grid-cols-2 gap-2 text-xs",children:[I.jsxs("div",{children:[I.jsxs("span",{className:"text-gray-600 dark:text-gray-400",children:[r.formatMessage({id:"app.agviewer_map.total_pixels",defaultMessage:"Total Pixels"}),":"]}),I.jsx("span",{className:"ml-2 font-semibold text-gray-900 dark:text-gray-100",children:B.reduce((te,ve)=>te+ve.count,0).toLocaleString()})]}),I.jsxs("div",{children:[I.jsxs("span",{className:"text-gray-600 dark:text-gray-400",children:[r.formatMessage({id:"app.agviewer_map.ndvi_range",defaultMessage:"NDVI Range"}),":"]}),I.jsxs("span",{className:"ml-2 font-semibold text-gray-900 dark:text-gray-100",children:[(ae=B[0])==null?void 0:ae.lowEdge.toFixed(2)," to"," ",(oe=B[B.length-1])==null?void 0:oe.highEdge.toFixed(2)]})]})]})}),h.value==="ET"&&v&&I.jsx("div",{className:"px-3 py-2 border-t border-gray-200 dark:border-gray-700 bg-gray-50 dark:bg-zinc-900/50",children:I.jsxs("div",{className:"text-xs text-gray-600 dark:text-gray-400",children:[I.jsxs("span",{className:"font-medium",children:[r.formatMessage({id:"app.agviewer_map.year",defaultMessage:"Year"}),":"]}),I.jsx("span",{className:"ml-2 font-semibold text-gray-900 dark:text-gray-100",children:new Date().getFullYear()})]})})]})}function FGe({isSearchFocused:e,searchQuery:t,searchResults:r,onResultClick:n}){return e?I.jsx("div",{className:"absolute top-full mt-1 left-0 right-0 sm:right-auto sm:w-64 bg-white backdrop-blur-xl rounded-md shadow-2xl border border-gray-200 overflow-hidden pointer-events-auto max-h-[400px] overflow-y-auto z-[1102]",children:I.jsx("div",{className:"p-2 space-y-1",children:t.trim()===""?I.jsxs(I.Fragment,{children:[I.jsx("div",{className:"px-2 py-1.5 text-[10px] font-bold text-muted-foreground uppercase tracking-wider",children:"Suggested"}),I.jsx("div",{className:"px-2 py-2 text-xs text-muted-foreground",children:"Start typing to search farms, plots, and stations..."})]}):r.length===0?I.jsx("div",{className:"px-2 py-4 text-xs text-muted-foreground text-center",children:"No results found"}):I.jsxs(I.Fragment,{children:[I.jsxs("div",{className:"px-2 py-1.5 text-[10px] font-bold text-muted-foreground uppercase tracking-wider",children:["Results (",r.length,")"]}),r.map(i=>I.jsxs("div",{className:"flex items-center gap-3 p-2 rounded-sm hover:bg-green-50/80 cursor-pointer transition-colors group",onClick:()=>n(i),children:[I.jsxs("div",{className:rr("w-8 h-8 rounded-sm flex items-center justify-center shrink-0",i.type==="farm"&&"bg-green-100 text-green-600",i.type==="plot"&&"bg-blue-100 text-blue-600",i.type==="station"&&"bg-orange-100 text-orange-600"),children:[i.type==="farm"&&I.jsx(NS,{className:"h-4 w-4"}),i.type==="plot"&&I.jsx(ug,{className:"h-4 w-4"}),i.type==="station"&&I.jsx(Zv,{className:"h-4 w-4"})]}),I.jsxs("div",{className:"flex flex-col min-w-0",children:[I.jsx("span",{className:"text-sm font-medium truncate text-foreground group-hover:text-green-700",children:i.label}),I.jsx("span",{className:"text-xs text-muted-foreground truncate",children:i.subLabel})]})]},i.id))]})})}):null}function Rp(e,t,{checkForDefaultPrevented:r=!0}={}){return function(i){if(e==null||e(i),r===!1||!i.defaultPrevented)return t==null?void 0:t(i)}}function RGe(e){const t=ie.useRef({value:e,previous:e});return ie.useMemo(()=>(t.current.value!==e&&(t.current.previous=t.current.value,t.current.value=e),t.current.previous),[e])}var IW=["PageUp","PageDown"],PW=["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"],OW={"from-left":["Home","PageDown","ArrowDown","ArrowLeft"],"from-right":["Home","PageDown","ArrowDown","ArrowRight"],"from-bottom":["Home","PageDown","ArrowDown","ArrowLeft"],"from-top":["Home","PageDown","ArrowUp","ArrowLeft"]},jp="Slider",[XI,jGe,BGe]=fG(jp),[kW,MYe]=rc(jp,[BGe]),[$Ge,nw]=kW(jp),DW=ie.forwardRef((e,t)=>{const{name:r,min:n=0,max:i=100,step:a=1,orientation:o="horizontal",disabled:s=!1,minStepsBetweenThumbs:u=0,defaultValue:h=[n],value:f,onValueChange:m=()=>{},onValueCommit:g=()=>{},inverted:v=!1,form:b,...x}=e,w=ie.useRef(new Set),T=ie.useRef(0),M=o==="horizontal"?zGe:VGe,[O=[],P]=lf({prop:f,defaultProp:h,onChange:z=>{var H;(H=[...w.current][T.current])==null||H.focus(),m(z)}}),k=ie.useRef(O);function D(z){const W=XGe(O,z);X(z,W)}function V(z){X(z,T.current)}function U(){const z=k.current[T.current];O[T.current]!==z&&g(O)}function X(z,W,{commit:H}={commit:!1}){const G=KGe(a),B=JGe(Math.round((z-n)/a)*a+n,G),Z=q_(B,[n,i]);P((Q=[])=>{const ae=UGe(Q,Z,W);if(qGe(ae,u*a)){T.current=ae.indexOf(Z);const oe=String(ae)!==String(Q);return oe&&H&&g(ae),oe?ae:Q}else return Q})}return I.jsx($Ge,{scope:e.__scopeSlider,name:r,disabled:s,min:n,max:i,valueIndexToChangeRef:T,thumbs:w.current,values:O,orientation:o,form:b,children:I.jsx(XI.Provider,{scope:e.__scopeSlider,children:I.jsx(XI.Slot,{scope:e.__scopeSlider,children:I.jsx(M,{"aria-disabled":s,"data-disabled":s?"":void 0,...x,ref:t,onPointerDown:Rp(x.onPointerDown,()=>{s||(k.current=O)}),min:n,max:i,inverted:v,onSlideStart:s?void 0:D,onSlideMove:s?void 0:V,onSlideEnd:s?void 0:U,onHomeKeyDown:()=>!s&&X(n,0,{commit:!0}),onEndKeyDown:()=>!s&&X(i,O.length-1,{commit:!0}),onStepKeyDown:({event:z,direction:W})=>{if(!s){const B=IW.includes(z.key)||z.shiftKey&&PW.includes(z.key)?10:1,Z=T.current,Q=O[Z],ae=a*B*W;X(Q+ae,Z,{commit:!0})}}})})})})});DW.displayName=jp;var[NW,LW]=kW(jp,{startEdge:"left",endEdge:"right",size:"width",direction:1}),zGe=ie.forwardRef((e,t)=>{const{min:r,max:n,dir:i,inverted:a,onSlideStart:o,onSlideMove:s,onSlideEnd:u,onStepKeyDown:h,...f}=e,[m,g]=ie.useState(null),v=Qr(t,M=>g(M)),b=ie.useRef(void 0),x=pG(i),w=x==="ltr",T=w&&!a||!w&&a;function C(M){const O=b.current||m.getBoundingClientRect(),P=[0,O.width],D=qI(P,T?[r,n]:[n,r]);return b.current=O,D(M-O.left)}return I.jsx(NW,{scope:e.__scopeSlider,startEdge:T?"left":"right",endEdge:T?"right":"left",direction:T?1:-1,size:"width",children:I.jsx(FW,{dir:x,"data-orientation":"horizontal",...f,ref:v,style:{...f.style,"--radix-slider-thumb-transform":"translateX(-50%)"},onSlideStart:M=>{const O=C(M.clientX);o==null||o(O)},onSlideMove:M=>{const O=C(M.clientX);s==null||s(O)},onSlideEnd:()=>{b.current=void 0,u==null||u()},onStepKeyDown:M=>{const P=OW[T?"from-left":"from-right"].includes(M.key);h==null||h({event:M,direction:P?-1:1})}})})}),VGe=ie.forwardRef((e,t)=>{const{min:r,max:n,inverted:i,onSlideStart:a,onSlideMove:o,onSlideEnd:s,onStepKeyDown:u,...h}=e,f=ie.useRef(null),m=Qr(t,f),g=ie.useRef(void 0),v=!i;function b(x){const w=g.current||f.current.getBoundingClientRect(),T=[0,w.height],M=qI(T,v?[n,r]:[r,n]);return g.current=w,M(x-w.top)}return I.jsx(NW,{scope:e.__scopeSlider,startEdge:v?"bottom":"top",endEdge:v?"top":"bottom",size:"height",direction:v?1:-1,children:I.jsx(FW,{"data-orientation":"vertical",...h,ref:m,style:{...h.style,"--radix-slider-thumb-transform":"translateY(50%)"},onSlideStart:x=>{const w=b(x.clientY);a==null||a(w)},onSlideMove:x=>{const w=b(x.clientY);o==null||o(w)},onSlideEnd:()=>{g.current=void 0,s==null||s()},onStepKeyDown:x=>{const T=OW[v?"from-bottom":"from-top"].includes(x.key);u==null||u({event:x,direction:T?-1:1})}})})}),FW=ie.forwardRef((e,t)=>{const{__scopeSlider:r,onSlideStart:n,onSlideMove:i,onSlideEnd:a,onHomeKeyDown:o,onEndKeyDown:s,onStepKeyDown:u,...h}=e,f=nw(jp,r);return I.jsx(Yr.span,{...h,ref:t,onKeyDown:Rp(e.onKeyDown,m=>{m.key==="Home"?(o(m),m.preventDefault()):m.key==="End"?(s(m),m.preventDefault()):IW.concat(PW).includes(m.key)&&(u(m),m.preventDefault())}),onPointerDown:Rp(e.onPointerDown,m=>{const g=m.target;g.setPointerCapture(m.pointerId),m.preventDefault(),f.thumbs.has(g)?g.focus():n(m)}),onPointerMove:Rp(e.onPointerMove,m=>{m.target.hasPointerCapture(m.pointerId)&&i(m)}),onPointerUp:Rp(e.onPointerUp,m=>{const g=m.target;g.hasPointerCapture(m.pointerId)&&(g.releasePointerCapture(m.pointerId),a(m))})})}),RW="SliderTrack",jW=ie.forwardRef((e,t)=>{const{__scopeSlider:r,...n}=e,i=nw(RW,r);return I.jsx(Yr.span,{"data-disabled":i.disabled?"":void 0,"data-orientation":i.orientation,...n,ref:t})});jW.displayName=RW;var YI="SliderRange",BW=ie.forwardRef((e,t)=>{const{__scopeSlider:r,...n}=e,i=nw(YI,r),a=LW(YI,r),o=ie.useRef(null),s=Qr(t,o),u=i.values.length,h=i.values.map(g=>VW(g,i.min,i.max)),f=u>1?Math.min(...h):0,m=100-Math.max(...h);return I.jsx(Yr.span,{"data-orientation":i.orientation,"data-disabled":i.disabled?"":void 0,...n,ref:s,style:{...e.style,[a.startEdge]:f+"%",[a.endEdge]:m+"%"}})});BW.displayName=YI;var ZI="SliderThumb",$W=ie.forwardRef((e,t)=>{const r=jGe(e.__scopeSlider),[n,i]=ie.useState(null),a=Qr(t,s=>i(s)),o=ie.useMemo(()=>n?r().findIndex(s=>s.ref.current===n):-1,[r,n]);return I.jsx(GGe,{...e,ref:a,index:o})}),GGe=ie.forwardRef((e,t)=>{const{__scopeSlider:r,index:n,name:i,...a}=e,o=nw(ZI,r),s=LW(ZI,r),[u,h]=ie.useState(null),f=Qr(t,C=>h(C)),m=u?o.form||!!u.closest("form"):!0,g=ux(u),v=o.values[n],b=v===void 0?0:VW(v,o.min,o.max),x=HGe(n,o.values.length),w=g==null?void 0:g[s.size],T=w?YGe(w,b,s.direction):0;return ie.useEffect(()=>{if(u)return o.thumbs.add(u),()=>{o.thumbs.delete(u)}},[u,o.thumbs]),I.jsxs("span",{style:{transform:"var(--radix-slider-thumb-transform)",position:"absolute",[s.startEdge]:`calc(${b}% + ${T}px)`},children:[I.jsx(XI.ItemSlot,{scope:e.__scopeSlider,children:I.jsx(Yr.span,{role:"slider","aria-label":e["aria-label"]||x,"aria-valuemin":o.min,"aria-valuenow":v,"aria-valuemax":o.max,"aria-orientation":o.orientation,"data-orientation":o.orientation,"data-disabled":o.disabled?"":void 0,tabIndex:o.disabled?void 0:0,...a,ref:f,style:v===void 0?{display:"none"}:e.style,onFocus:Rp(e.onFocus,()=>{o.valueIndexToChangeRef.current=n})})}),m&&I.jsx(zW,{name:i??(o.name?o.name+(o.values.length>1?"[]":""):void 0),form:o.form,value:v},n)]})});$W.displayName=ZI;var WGe="RadioBubbleInput",zW=ie.forwardRef(({__scopeSlider:e,value:t,...r},n)=>{const i=ie.useRef(null),a=Qr(i,n),o=RGe(t);return ie.useEffect(()=>{const s=i.current;if(!s)return;const u=window.HTMLInputElement.prototype,f=Object.getOwnPropertyDescriptor(u,"value").set;if(o!==t&&f){const m=new Event("input",{bubbles:!0});f.call(s,t),s.dispatchEvent(m)}},[o,t]),I.jsx(Yr.input,{style:{display:"none"},...r,ref:a,defaultValue:t})});zW.displayName=WGe;function UGe(e=[],t,r){const n=[...e];return n[r]=t,n.sort((i,a)=>i-a)}function VW(e,t,r){const a=100/(r-t)*(e-t);return q_(a,[0,100])}function HGe(e,t){return t>2?`Value ${e+1} of ${t}`:t===2?["Minimum","Maximum"][e]:void 0}function XGe(e,t){if(e.length===1)return 0;const r=e.map(i=>Math.abs(i-t)),n=Math.min(...r);return r.indexOf(n)}function YGe(e,t,r){const n=e/2,a=qI([0,50],[0,n]);return(n-a(t)*r)*r}function ZGe(e){return e.slice(0,-1).map((t,r)=>e[r+1]-t)}function qGe(e,t){if(t>0){const r=ZGe(e);return Math.min(...r)>=t}return!0}function qI(e,t){return r=>{if(e[0]===e[1]||t[0]===t[1])return t[0];const n=(t[1]-t[0])/(e[1]-e[0]);return t[0]+n*(r-e[0])}}function KGe(e){return(String(e).split(".")[1]||"").length}function JGe(e,t){const r=Math.pow(10,t);return Math.round(e*r)/r}var GW=DW,QGe=jW,eWe=BW,tWe=$W;const WW=ie.forwardRef(({className:e,...t},r)=>I.jsxs(GW,{ref:r,className:rr("relative flex w-full touch-none select-none items-center",e),...t,children:[I.jsx(QGe,{className:"relative h-2 w-full grow overflow-hidden rounded-full bg-secondary",children:I.jsx(eWe,{className:"absolute h-full bg-primary"})}),I.jsx(tWe,{className:"block h-5 w-5 rounded-full border-2 border-primary bg-background ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50"})]}));WW.displayName=GW.displayName;function KI(e,t,{checkForDefaultPrevented:r=!0}={}){return function(i){if(e==null||e(i),r===!1||!i.defaultPrevented)return t==null?void 0:t(i)}}function UW(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function HW(...e){return t=>{let r=!1;const n=e.map(i=>{const a=UW(i,t);return!r&&typeof a=="function"&&(r=!0),a});if(r)return()=>{for(let i=0;i<n.length;i++){const a=n[i];typeof a=="function"?a():UW(e[i],null)}}}}function JI(...e){return ie.useCallback(HW(...e),e)}function XW(e,t=[]){let r=[];function n(a,o){const s=ie.createContext(o),u=r.length;r=[...r,o];const h=m=>{var T;const{scope:g,children:v,...b}=m,x=((T=g==null?void 0:g[e])==null?void 0:T[u])||s,w=ie.useMemo(()=>b,Object.values(b));return I.jsx(x.Provider,{value:w,children:v})};h.displayName=a+"Provider";function f(m,g){var x;const v=((x=g==null?void 0:g[e])==null?void 0:x[u])||s,b=ie.useContext(v);if(b)return b;if(o!==void 0)return o;throw new Error(`\`${m}\` must be used within \`${a}\``)}return[h,f]}const i=()=>{const a=r.map(o=>ie.createContext(o));return function(s){const u=(s==null?void 0:s[e])||a;return ie.useMemo(()=>({[`__scope${e}`]:{...s,[e]:u}}),[s,u])}};return i.scopeName=e,[n,rWe(i,...t)]}function rWe(...e){const t=e[0];if(e.length===1)return t;const r=()=>{const n=e.map(i=>({useScope:i(),scopeName:i.scopeName}));return function(a){const o=n.reduce((s,{useScope:u,scopeName:h})=>{const m=u(a)[`__scope${h}`];return{...s,...m}},{});return ie.useMemo(()=>({[`__scope${t.scopeName}`]:o}),[o])}};return r.scopeName=t.scopeName,r}var YW=ie.forwardRef((e,t)=>{const{children:r,...n}=e,i=ie.Children.toArray(r),a=i.find(iWe);if(a){const o=a.props.children,s=i.map(u=>u===a?ie.Children.count(o)>1?ie.Children.only(null):ie.isValidElement(o)?o.props.children:null:u);return I.jsx(QI,{...n,ref:t,children:ie.isValidElement(o)?ie.cloneElement(o,void 0,s):null})}return I.jsx(QI,{...n,ref:t,children:r})});YW.displayName="Slot";var QI=ie.forwardRef((e,t)=>{const{children:r,...n}=e;if(ie.isValidElement(r)){const i=sWe(r);return ie.cloneElement(r,{...aWe(n,r.props),ref:t?HW(t,i):i})}return ie.Children.count(r)>1?ie.Children.only(null):null});QI.displayName="SlotClone";var nWe=({children:e})=>I.jsx(I.Fragment,{children:e});function iWe(e){return ie.isValidElement(e)&&e.type===nWe}function aWe(e,t){const r={...t};for(const n in t){const i=e[n],a=t[n];/^on[A-Z]/.test(n)?i&&a?r[n]=(...s)=>{a(...s),i(...s)}:i&&(r[n]=i):n==="style"?r[n]={...i,...a}:n==="className"&&(r[n]=[i,a].filter(Boolean).join(" "))}return{...e,...r}}function sWe(e){var n,i;let t=(n=Object.getOwnPropertyDescriptor(e.props,"ref"))==null?void 0:n.get,r=t&&"isReactWarning"in t&&t.isReactWarning;return r?e.ref:(t=(i=Object.getOwnPropertyDescriptor(e,"ref"))==null?void 0:i.get,r=t&&"isReactWarning"in t&&t.isReactWarning,r?e.props.ref:e.props.ref||e.ref)}var oWe=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","span","svg","ul"],eP=oWe.reduce((e,t)=>{const r=ie.forwardRef((n,i)=>{const{asChild:a,...o}=n,s=a?YW:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),I.jsx(s,{...o,ref:i})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{});function Bp(e,t,{checkForDefaultPrevented:r=!0}={}){return function(i){if(e==null||e(i),r===!1||!i.defaultPrevented)return t==null?void 0:t(i)}}function ZW(e,t=[]){let r=[];function n(a,o){const s=ie.createContext(o),u=r.length;r=[...r,o];const h=m=>{var T;const{scope:g,children:v,...b}=m,x=((T=g==null?void 0:g[e])==null?void 0:T[u])||s,w=ie.useMemo(()=>b,Object.values(b));return I.jsx(x.Provider,{value:w,children:v})};h.displayName=a+"Provider";function f(m,g){var x;const v=((x=g==null?void 0:g[e])==null?void 0:x[u])||s,b=ie.useContext(v);if(b)return b;if(o!==void 0)return o;throw new Error(`\`${m}\` must be used within \`${a}\``)}return[h,f]}const i=()=>{const a=r.map(o=>ie.createContext(o));return function(s){const u=(s==null?void 0:s[e])||a;return ie.useMemo(()=>({[`__scope${e}`]:{...s,[e]:u}}),[s,u])}};return i.scopeName=e,[n,lWe(i,...t)]}function lWe(...e){const t=e[0];if(e.length===1)return t;const r=()=>{const n=e.map(i=>({useScope:i(),scopeName:i.scopeName}));return function(a){const o=n.reduce((s,{useScope:u,scopeName:h})=>{const m=u(a)[`__scope${h}`];return{...s,...m}},{});return ie.useMemo(()=>({[`__scope${t.scopeName}`]:o}),[o])}};return r.scopeName=t.scopeName,r}function qW(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function KW(...e){return t=>{let r=!1;const n=e.map(i=>{const a=qW(i,t);return!r&&typeof a=="function"&&(r=!0),a});if(r)return()=>{for(let i=0;i<n.length;i++){const a=n[i];typeof a=="function"?a():qW(e[i],null)}}}}function tP(...e){return ie.useCallback(KW(...e),e)}var iw=ie.forwardRef((e,t)=>{const{children:r,...n}=e,i=ie.Children.toArray(r),a=i.find(uWe);if(a){const o=a.props.children,s=i.map(u=>u===a?ie.Children.count(o)>1?ie.Children.only(null):ie.isValidElement(o)?o.props.children:null:u);return I.jsx(rP,{...n,ref:t,children:ie.isValidElement(o)?ie.cloneElement(o,void 0,s):null})}return I.jsx(rP,{...n,ref:t,children:r})});iw.displayName="Slot";var rP=ie.forwardRef((e,t)=>{const{children:r,...n}=e;if(ie.isValidElement(r)){const i=dWe(r);return ie.cloneElement(r,{...hWe(n,r.props),ref:t?KW(t,i):i})}return ie.Children.count(r)>1?ie.Children.only(null):null});rP.displayName="SlotClone";var cWe=({children:e})=>I.jsx(I.Fragment,{children:e});function uWe(e){return ie.isValidElement(e)&&e.type===cWe}function hWe(e,t){const r={...t};for(const n in t){const i=e[n],a=t[n];/^on[A-Z]/.test(n)?i&&a?r[n]=(...s)=>{a(...s),i(...s)}:i&&(r[n]=i):n==="style"?r[n]={...i,...a}:n==="className"&&(r[n]=[i,a].filter(Boolean).join(" "))}return{...e,...r}}function dWe(e){var n,i;let t=(n=Object.getOwnPropertyDescriptor(e.props,"ref"))==null?void 0:n.get,r=t&&"isReactWarning"in t&&t.isReactWarning;return r?e.ref:(t=(i=Object.getOwnPropertyDescriptor(e,"ref"))==null?void 0:i.get,r=t&&"isReactWarning"in t&&t.isReactWarning,r?e.props.ref:e.props.ref||e.ref)}function fWe(e){const t=e+"CollectionProvider",[r,n]=ZW(t),[i,a]=r(t,{collectionRef:{current:null},itemMap:new Map}),o=v=>{const{scope:b,children:x}=v,w=j.useRef(null),T=j.useRef(new Map).current;return I.jsx(i,{scope:b,itemMap:T,collectionRef:w,children:x})};o.displayName=t;const s=e+"CollectionSlot",u=j.forwardRef((v,b)=>{const{scope:x,children:w}=v,T=a(s,x),C=tP(b,T.collectionRef);return I.jsx(iw,{ref:C,children:w})});u.displayName=s;const h=e+"CollectionItemSlot",f="data-radix-collection-item",m=j.forwardRef((v,b)=>{const{scope:x,children:w,...T}=v,C=j.useRef(null),M=tP(b,C),O=a(h,x);return j.useEffect(()=>(O.itemMap.set(C,{ref:C,...T}),()=>void O.itemMap.delete(C))),I.jsx(iw,{[f]:"",ref:M,children:w})});m.displayName=h;function g(v){const b=a(e+"CollectionConsumer",v);return j.useCallback(()=>{const w=b.collectionRef.current;if(!w)return[];const T=Array.from(w.querySelectorAll(`[${f}]`));return Array.from(b.itemMap.values()).sort((O,P)=>T.indexOf(O.ref.current)-T.indexOf(P.ref.current))},[b.collectionRef,b.itemMap])}return[{Provider:o,Slot:u,ItemSlot:m},g,n]}var pWe=globalThis!=null&&globalThis.document?ie.useLayoutEffect:()=>{},mWe=ie.useId||(()=>{}),gWe=0;function yWe(e){const[t,r]=ie.useState(mWe());return pWe(()=>{r(n=>n??String(gWe++))},[e]),t?`radix-${t}`:""}var vWe=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","span","svg","ul"],JW=vWe.reduce((e,t)=>{const r=ie.forwardRef((n,i)=>{const{asChild:a,...o}=n,s=a?iw:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),I.jsx(s,{...o,ref:i})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{});function xWe({prop:e,defaultProp:t,onChange:r=()=>{}}){const[n,i]=bWe({defaultProp:t,onChange:r}),a=e!==void 0,o=a?e:n,s=Bs(r),u=ie.useCallback(h=>{if(a){const m=typeof h=="function"?h(e):h;m!==e&&s(m)}else i(h)},[a,e,i,s]);return[o,u]}function bWe({defaultProp:e,onChange:t}){const r=ie.useState(e),[n]=r,i=ie.useRef(n),a=Bs(t);return ie.useEffect(()=>{i.current!==n&&(a(n),i.current=n)},[n,i,a]),r}var _We=ie.createContext(void 0);function wWe(e){const t=ie.useContext(_We);return e||t||"ltr"}var nP="rovingFocusGroup.onEntryFocus",SWe={bubbles:!1,cancelable:!0},aw="RovingFocusGroup",[iP,QW,EWe]=fWe(aw),[CWe,sw]=ZW(aw,[EWe]),[TWe,AWe]=CWe(aw),eU=ie.forwardRef((e,t)=>I.jsx(iP.Provider,{scope:e.__scopeRovingFocusGroup,children:I.jsx(iP.Slot,{scope:e.__scopeRovingFocusGroup,children:I.jsx(MWe,{...e,ref:t})})}));eU.displayName=aw;var MWe=ie.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:r,orientation:n,loop:i=!1,dir:a,currentTabStopId:o,defaultCurrentTabStopId:s,onCurrentTabStopIdChange:u,onEntryFocus:h,preventScrollOnEntryFocus:f=!1,...m}=e,g=ie.useRef(null),v=tP(t,g),b=wWe(a),[x=null,w]=xWe({prop:o,defaultProp:s,onChange:u}),[T,C]=ie.useState(!1),M=Bs(h),O=QW(r),P=ie.useRef(!1),[k,D]=ie.useState(0);return ie.useEffect(()=>{const V=g.current;if(V)return V.addEventListener(nP,M),()=>V.removeEventListener(nP,M)},[M]),I.jsx(TWe,{scope:r,orientation:n,dir:b,loop:i,currentTabStopId:x,onItemFocus:ie.useCallback(V=>w(V),[w]),onItemShiftTab:ie.useCallback(()=>C(!0),[]),onFocusableItemAdd:ie.useCallback(()=>D(V=>V+1),[]),onFocusableItemRemove:ie.useCallback(()=>D(V=>V-1),[]),children:I.jsx(JW.div,{tabIndex:T||k===0?-1:0,"data-orientation":n,...m,ref:v,style:{outline:"none",...e.style},onMouseDown:Bp(e.onMouseDown,()=>{P.current=!0}),onFocus:Bp(e.onFocus,V=>{const U=!P.current;if(V.target===V.currentTarget&&U&&!T){const X=new CustomEvent(nP,SWe);if(V.currentTarget.dispatchEvent(X),!X.defaultPrevented){const z=O().filter(Z=>Z.focusable),W=z.find(Z=>Z.active),H=z.find(Z=>Z.id===x),B=[W,H,...z].filter(Boolean).map(Z=>Z.ref.current);nU(B,f)}}P.current=!1}),onBlur:Bp(e.onBlur,()=>C(!1))})})}),tU="RovingFocusGroupItem",rU=ie.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:r,focusable:n=!0,active:i=!1,tabStopId:a,...o}=e,s=yWe(),u=a||s,h=AWe(tU,r),f=h.currentTabStopId===u,m=QW(r),{onFocusableItemAdd:g,onFocusableItemRemove:v}=h;return ie.useEffect(()=>{if(n)return g(),()=>v()},[n,g,v]),I.jsx(iP.ItemSlot,{scope:r,id:u,focusable:n,active:i,children:I.jsx(JW.span,{tabIndex:f?0:-1,"data-orientation":h.orientation,...o,ref:t,onMouseDown:Bp(e.onMouseDown,b=>{n?h.onItemFocus(u):b.preventDefault()}),onFocus:Bp(e.onFocus,()=>h.onItemFocus(u)),onKeyDown:Bp(e.onKeyDown,b=>{if(b.key==="Tab"&&b.shiftKey){h.onItemShiftTab();return}if(b.target!==b.currentTarget)return;const x=OWe(b,h.orientation,h.dir);if(x!==void 0){if(b.metaKey||b.ctrlKey||b.altKey||b.shiftKey)return;b.preventDefault();let T=m().filter(C=>C.focusable).map(C=>C.ref.current);if(x==="last")T.reverse();else if(x==="prev"||x==="next"){x==="prev"&&T.reverse();const C=T.indexOf(b.currentTarget);T=h.loop?kWe(T,C+1):T.slice(C+1)}setTimeout(()=>nU(T))}})})})});rU.displayName=tU;var IWe={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function PWe(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function OWe(e,t,r){const n=PWe(e.key,r);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(n))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(n)))return IWe[n]}function nU(e,t=!1){const r=document.activeElement;for(const n of e)if(n===r||(n.focus({preventScroll:t}),document.activeElement!==r))return}function kWe(e,t){return e.map((r,n)=>e[(t+n)%e.length])}var iU=eU,aU=rU;function DWe({prop:e,defaultProp:t,onChange:r=()=>{}}){const[n,i]=NWe({defaultProp:t,onChange:r}),a=e!==void 0,o=a?e:n,s=Bs(r),u=ie.useCallback(h=>{if(a){const m=typeof h=="function"?h(e):h;m!==e&&s(m)}else i(h)},[a,e,i,s]);return[o,u]}function NWe({defaultProp:e,onChange:t}){const r=ie.useState(e),[n]=r,i=ie.useRef(n),a=Bs(t);return ie.useEffect(()=>{i.current!==n&&(a(n),i.current=n)},[n,i,a]),r}var LWe=ie.createContext(void 0);function FWe(e){const t=ie.useContext(LWe);return e||t||"ltr"}var aP=globalThis!=null&&globalThis.document?ie.useLayoutEffect:()=>{};function RWe(e){const[t,r]=ie.useState(void 0);return aP(()=>{if(e){r({width:e.offsetWidth,height:e.offsetHeight});const n=new ResizeObserver(i=>{if(!Array.isArray(i)||!i.length)return;const a=i[0];let o,s;if("borderBoxSize"in a){const u=a.borderBoxSize,h=Array.isArray(u)?u[0]:u;o=h.inlineSize,s=h.blockSize}else o=e.offsetWidth,s=e.offsetHeight;r({width:o,height:s})});return n.observe(e,{box:"border-box"}),()=>n.unobserve(e)}else r(void 0)},[e]),t}function jWe(e){const t=ie.useRef({value:e,previous:e});return ie.useMemo(()=>(t.current.value!==e&&(t.current.previous=t.current.value,t.current.value=e),t.current.previous),[e])}function BWe(e,t){return ie.useReducer((r,n)=>t[r][n]??r,e)}var sU=e=>{const{present:t,children:r}=e,n=$We(t),i=typeof r=="function"?r({present:n.isPresent}):ie.Children.only(r),a=JI(n.ref,zWe(i));return typeof r=="function"||n.isPresent?ie.cloneElement(i,{ref:a}):null};sU.displayName="Presence";function $We(e){const[t,r]=ie.useState(),n=ie.useRef({}),i=ie.useRef(e),a=ie.useRef("none"),o=e?"mounted":"unmounted",[s,u]=BWe(o,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return ie.useEffect(()=>{const h=ow(n.current);a.current=s==="mounted"?h:"none"},[s]),aP(()=>{const h=n.current,f=i.current;if(f!==e){const g=a.current,v=ow(h);e?u("MOUNT"):v==="none"||(h==null?void 0:h.display)==="none"?u("UNMOUNT"):u(f&&g!==v?"ANIMATION_OUT":"UNMOUNT"),i.current=e}},[e,u]),aP(()=>{if(t){let h;const f=t.ownerDocument.defaultView??window,m=v=>{const x=ow(n.current).includes(v.animationName);if(v.target===t&&x&&(u("ANIMATION_END"),!i.current)){const w=t.style.animationFillMode;t.style.animationFillMode="forwards",h=f.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=w)})}},g=v=>{v.target===t&&(a.current=ow(n.current))};return t.addEventListener("animationstart",g),t.addEventListener("animationcancel",m),t.addEventListener("animationend",m),()=>{f.clearTimeout(h),t.removeEventListener("animationstart",g),t.removeEventListener("animationcancel",m),t.removeEventListener("animationend",m)}}else u("ANIMATION_END")},[t,u]),{isPresent:["mounted","unmountSuspended"].includes(s),ref:ie.useCallback(h=>{h&&(n.current=getComputedStyle(h)),r(h)},[])}}function ow(e){return(e==null?void 0:e.animationName)||"none"}function zWe(e){var n,i;let t=(n=Object.getOwnPropertyDescriptor(e.props,"ref"))==null?void 0:n.get,r=t&&"isReactWarning"in t&&t.isReactWarning;return r?e.ref:(t=(i=Object.getOwnPropertyDescriptor(e,"ref"))==null?void 0:i.get,r=t&&"isReactWarning"in t&&t.isReactWarning,r?e.props.ref:e.props.ref||e.ref)}var sP="Radio",[VWe,oU]=XW(sP),[GWe,WWe]=VWe(sP),lU=ie.forwardRef((e,t)=>{const{__scopeRadio:r,name:n,checked:i=!1,required:a,disabled:o,value:s="on",onCheck:u,form:h,...f}=e,[m,g]=ie.useState(null),v=JI(t,w=>g(w)),b=ie.useRef(!1),x=m?h||!!m.closest("form"):!0;return I.jsxs(GWe,{scope:r,checked:i,disabled:o,children:[I.jsx(eP.button,{type:"button",role:"radio","aria-checked":i,"data-state":hU(i),"data-disabled":o?"":void 0,disabled:o,value:s,...f,ref:v,onClick:KI(e.onClick,w=>{i||u==null||u(),x&&(b.current=w.isPropagationStopped(),b.current||w.stopPropagation())})}),x&&I.jsx(UWe,{control:m,bubbles:!b.current,name:n,value:s,checked:i,required:a,disabled:o,form:h,style:{transform:"translateX(-100%)"}})]})});lU.displayName=sP;var cU="RadioIndicator",uU=ie.forwardRef((e,t)=>{const{__scopeRadio:r,forceMount:n,...i}=e,a=WWe(cU,r);return I.jsx(sU,{present:n||a.checked,children:I.jsx(eP.span,{"data-state":hU(a.checked),"data-disabled":a.disabled?"":void 0,...i,ref:t})})});uU.displayName=cU;var UWe=e=>{const{control:t,checked:r,bubbles:n=!0,...i}=e,a=ie.useRef(null),o=jWe(r),s=RWe(t);return ie.useEffect(()=>{const u=a.current,h=window.HTMLInputElement.prototype,m=Object.getOwnPropertyDescriptor(h,"checked").set;if(o!==r&&m){const g=new Event("click",{bubbles:n});m.call(u,r),u.dispatchEvent(g)}},[o,r,n]),I.jsx("input",{type:"radio","aria-hidden":!0,defaultChecked:r,...i,tabIndex:-1,ref:a,style:{...e.style,...s,position:"absolute",pointerEvents:"none",opacity:0,margin:0}})};function hU(e){return e?"checked":"unchecked"}var HWe=["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"],oP="RadioGroup",[XWe,IYe]=XW(oP,[sw,oU]),dU=sw(),fU=oU(),[YWe,ZWe]=XWe(oP),pU=ie.forwardRef((e,t)=>{const{__scopeRadioGroup:r,name:n,defaultValue:i,value:a,required:o=!1,disabled:s=!1,orientation:u,dir:h,loop:f=!0,onValueChange:m,...g}=e,v=dU(r),b=FWe(h),[x,w]=DWe({prop:a,defaultProp:i,onChange:m});return I.jsx(YWe,{scope:r,name:n,required:o,disabled:s,value:x,onValueChange:w,children:I.jsx(iU,{asChild:!0,...v,orientation:u,dir:b,loop:f,children:I.jsx(eP.div,{role:"radiogroup","aria-required":o,"aria-orientation":u,"data-disabled":s?"":void 0,dir:b,...g,ref:t})})})});pU.displayName=oP;var mU="RadioGroupItem",gU=ie.forwardRef((e,t)=>{const{__scopeRadioGroup:r,disabled:n,...i}=e,a=ZWe(mU,r),o=a.disabled||n,s=dU(r),u=fU(r),h=ie.useRef(null),f=JI(t,h),m=a.value===i.value,g=ie.useRef(!1);return ie.useEffect(()=>{const v=x=>{HWe.includes(x.key)&&(g.current=!0)},b=()=>g.current=!1;return document.addEventListener("keydown",v),document.addEventListener("keyup",b),()=>{document.removeEventListener("keydown",v),document.removeEventListener("keyup",b)}},[]),I.jsx(aU,{asChild:!0,...s,focusable:!o,active:m,children:I.jsx(lU,{disabled:o,required:a.required,checked:m,...u,...i,name:a.name,ref:f,onCheck:()=>a.onValueChange(i.value),onKeyDown:KI(v=>{v.key==="Enter"&&v.preventDefault()}),onFocus:KI(i.onFocus,()=>{var v;g.current&&((v=h.current)==null||v.click())})})})});gU.displayName=mU;var qWe="RadioGroupIndicator",yU=ie.forwardRef((e,t)=>{const{__scopeRadioGroup:r,...n}=e,i=fU(r);return I.jsx(uU,{...i,...n,ref:t})});yU.displayName=qWe;var vU=pU,xU=gU,KWe=yU;const lw=ie.forwardRef(({className:e,...t},r)=>I.jsx(vU,{className:gu("grid gap-2",e),...t,ref:r}));lw.displayName=vU.displayName;const xy=ie.forwardRef(({className:e,...t},r)=>I.jsx(xU,{ref:r,className:gu("aspect-square h-4 w-4 rounded-full border border-primary text-primary ring-offset-background focus:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",e),...t,children:I.jsx(KWe,{className:"flex items-center justify-center",children:I.jsx(Ine,{className:"h-2.5 w-2.5 fill-current text-current"})})}));xy.displayName=xU.displayName;function Mc({children:e,className:t}){return I.jsx("label",{className:`text-gray-800 dark:text-gray-300 ${t||""}`,children:e})}function JWe({activePanel:e,togglePanel:t,viewType:r,setViewType:n,dataSource:i,setDataSource:a,layerOptions:o=[],layerOpacity:s=[100],setLayerOpacity:u,layerEnabled:h=!0,setLayerEnabled:f}){return I.jsx("div",{className:rr("absolute top-16 sm:top-20 left-2 right-2 sm:left-1/2 sm:-translate-x-1/2 z-[1101] w-auto sm:w-80 transition-all duration-300 origin-top pointer-events-none",e==="layers"?"opacity-100 translate-y-0 pointer-events-auto":"opacity-0 -translate-y-10 pointer-events-none"),children:I.jsxs("div",{className:"bg-white/90 backdrop-blur-xl rounded-xl sm:rounded-2xl shadow-2xl overflow-hidden flex flex-col max-h-[80vh] border border-white/50",children:[I.jsxs("div",{className:"p-4 border-b border-border flex justify-between items-center bg-white/50",children:[I.jsxs("div",{children:[I.jsx("h2",{className:"font-bold text-foreground",children:"Raster Layers"}),I.jsx("p",{className:"text-xs text-muted-foreground",children:"Manage map overlays"})]}),I.jsxs("div",{className:"flex items-center gap-3",children:[I.jsx(o_,{checked:h,onCheckedChange:f}),I.jsx(_r,{variant:"ghost",size:"icon",className:"h-8 w-8 rounded-full",onClick:()=>t(null),children:I.jsx(gs,{className:"h-5 w-5"})})]})]}),I.jsxs("div",{className:"p-4 space-y-5 overflow-y-auto",children:[I.jsxs("div",{className:"space-y-3",children:[I.jsx(Mc,{className:"text-xs font-bold text-muted-foreground uppercase tracking-wider",children:"Layer Options"}),I.jsxs("div",{children:[I.jsx(Mc,{className:"text-xs font-bold text-muted-foreground uppercase mb-2 block",children:"View Type"}),I.jsxs(lw,{value:r,onValueChange:n,className:"grid grid-cols-2 gap-1.5 sm:gap-2",children:[I.jsxs(Mc,{htmlFor:"view-plot",className:rr("flex flex-col items-center p-3 border-2 rounded-lg cursor-pointer transition-all",r==="plot"?"border-green-500 bg-green-50/50 text-green-600":"border-border hover:border-green-500/50"),children:[I.jsx(xy,{value:"plot",id:"view-plot",className:"sr-only"}),I.jsx(ug,{className:"h-6 w-6 mb-1"}),I.jsx("span",{className:"text-xs font-medium",children:"Plot View"})]}),I.jsxs(Mc,{htmlFor:"view-map",className:rr("flex flex-col items-center p-3 border-2 rounded-lg cursor-pointer transition-all",r==="map"?"border-green-500 bg-green-50/50 text-green-600":"border-border hover:border-green-500/50"),children:[I.jsx(xy,{value:"map",id:"view-map",className:"sr-only"}),I.jsx(kne,{className:"h-6 w-6 mb-1"}),I.jsx("span",{className:"text-xs font-medium",children:"Map View"})]})]})]})]}),I.jsxs("div",{className:"space-y-2",children:[I.jsx(Mc,{className:"text-xs font-bold text-muted-foreground uppercase tracking-wider",children:"Data Source"}),I.jsx("div",{className:"border rounded-md overflow-hidden",children:I.jsx("div",{className:"max-h-[150px] overflow-y-auto",children:o.length===0?I.jsx("div",{className:"py-6 text-center text-sm text-muted-foreground",children:"No data source available."}):I.jsx("div",{className:"p-1",children:o.map(m=>I.jsxs("div",{onClick:()=>a(m),className:rr("relative flex w-full cursor-pointer select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none hover:bg-accent hover:text-accent-foreground",(i==null?void 0:i.value)===m.value&&"bg-accent text-accent-foreground"),children:[I.jsx(LS,{className:rr("mr-2 h-4 w-4",(i==null?void 0:i.value)===m.value?"opacity-100":"opacity-0")}),I.jsx("span",{children:m.label})]},m.value))})})})]}),I.jsxs("div",{className:"space-y-3 pt-2",children:[I.jsxs("div",{className:"flex justify-between items-center text-xs font-medium text-muted-foreground",children:[I.jsx("span",{children:"Opacity"}),I.jsxs("span",{children:[s[0],"%"]})]}),I.jsx(WW,{value:s,onValueChange:u,max:100,step:1})]})]})]})})}function QWe({error:e,errorInfo:t,onReset:r}){return I.jsxs("div",{children:[I.jsx("h2",{children:"Something went wrong!"}),I.jsx("p",{children:e==null?void 0:e.message}),I.jsx("details",{children:t==null?void 0:t.componentStack}),I.jsx(Vx,{onClick:r,children:"Try Again"})]})}class bU extends j.Component{constructor(r){super(r);NX(this,"handleReset",()=>{this.setState({hasError:!1,error:null,errorInfo:null}),this.props.onReset&&this.props.onReset()});this.state={hasError:!1,error:null,errorInfo:null}}static getDerivedStateFromError(r){return{hasError:!0,error:r}}componentDidCatch(r,n){this.setState({error:r,errorInfo:n})}render(){const{hasError:r,error:n,errorInfo:i}=this.state,a=this.props.ErrorFallback||QWe;return r?I.jsx(a,{error:n,errorInfo:i,onReset:this.handleReset}):this.props.children}}const eUe=({width:e=24,height:t=24,fill:r="#000"})=>I.jsxs("svg",{width:e,height:t,viewBox:"0 0 32 32",xmlns:"http://www.w3.org/2000/svg",fill:r,children:[I.jsx("path",{d:"M17,28V17h1a2.0023,2.0023,0,0,0,2-2V11a2.0023,2.0023,0,0,0-2-2H14a2.0023,2.0023,0,0,0-2,2v4a2.0023,2.0023,0,0,0,2,2h1V28H2v2H30V28ZM14,11h4l.0015,4H14Z"}),I.jsx("path",{d:"M9.3325,18.2168a7.0007,7.0007,0,0,1,0-10.4341l1.334,1.49a5,5,0,0,0,0,7.4537Z"}),I.jsx("path",{d:"M22.667,18.2168l-1.334-1.49a4.9995,4.9995,0,0,0,0-7.4537l1.334-1.49a7,7,0,0,1,0,10.4341Z"}),I.jsx("path",{d:"M6.3994,21.8008a11.0019,11.0019,0,0,1,0-17.6006L7.6,5.8a9.0009,9.0009,0,0,0,0,14.4014Z"}),I.jsx("path",{d:"M25.6006,21.8008l-1.2012-1.6a9.001,9.001,0,0,0,0-14.4019l1.2012-1.6a11.002,11.002,0,0,1,0,17.6011Z"})]}),tUe=j.lazy(()=>Promise.resolve().then(()=>mHe));function rUe({activePanel:e,togglePanel:t,markerType:r,setMarkerType:n,pawStatus:i,setPawStatus:a,markerTypeOptions:o=[],pawStatusOptions:s=[],showMarkers:u=!0,setShowMarkers:h,formatLabel:f}){const{mapRef:m}=j.useContext(qi),g=Kn(),[v,b]=j.useState(!1),{unfilteredMarkers:x,loading:w,handleDeleteMarker:T}=j.useContext(ys),{isConfirmed:C}=h1(),M=j.useCallback((k,D)=>{if(!(m!=null&&m.current)||!D)return;const{lat:V,lng:U}=D.location;m.current.flyTo({center:[U,V],zoom:14})},[m]),O=j.useCallback(async(k,D)=>{!D||!await C(g.formatMessage({id:"app.agviewer_map.delete_marker_confirm_message",defaultMessage:"Do you want to delete this marker?"}))||T(D.id)},[C,T,g]),P=j.useCallback(()=>{b(k=>!k)},[]);return I.jsx("div",{className:rr("absolute top-16 sm:top-20 left-2 right-2 sm:left-1/2 sm:-translate-x-1/2 z-[1101] w-auto sm:w-80 transition-all duration-300 origin-top pointer-events-none",e==="stations"?"opacity-100 translate-y-0 pointer-events-auto":"opacity-0 -translate-y-10 pointer-events-none"),children:I.jsxs("div",{className:"bg-white/90 backdrop-blur-xl rounded-xl sm:rounded-2xl shadow-2xl overflow-hidden flex flex-col max-h-[80vh] border border-white/50",children:[I.jsxs("div",{className:"p-4 border-b border-border flex justify-between items-center bg-white/50",children:[I.jsxs("div",{children:[I.jsx("h2",{className:"font-bold text-foreground",children:"Stations"}),I.jsx("p",{className:"text-xs text-muted-foreground",children:"Filter and manage markers"})]}),I.jsxs("div",{className:"flex items-center gap-3",children:[I.jsx(o_,{checked:u,onCheckedChange:h}),I.jsx(_r,{variant:"ghost",size:"icon",className:"h-8 w-8 rounded-full",onClick:()=>t(null),children:I.jsx(gs,{className:"h-5 w-5"})})]})]}),I.jsxs("div",{className:"p-4 space-y-4 overflow-y-auto",children:[I.jsxs("div",{children:[I.jsx(Mc,{className:"text-xs font-bold text-muted-foreground uppercase mb-2 block",children:"Marker Type"}),I.jsx(lw,{value:r||"",onValueChange:n,className:"grid grid-cols-3 gap-1.5 sm:gap-2",children:o.map(k=>I.jsxs(Mc,{htmlFor:`type-${k.value}`,className:rr("flex items-center justify-center py-2 px-3 text-xs font-medium rounded-lg border-2 cursor-pointer transition-all",(r||"")===k.value?"border-green-500 bg-green-50/50 text-green-600":"border-border hover:border-green-500/50"),children:[I.jsx(xy,{value:k.value,id:`type-${k.value}`,className:"sr-only"}),k.label]},k.value))})]}),I.jsxs("div",{children:[I.jsx(Mc,{className:"text-xs font-bold text-muted-foreground uppercase mb-2 block",children:"PAW Status"}),I.jsx(lw,{value:i||"",onValueChange:a,className:"grid grid-cols-2 sm:grid-cols-4 gap-1.5 sm:gap-2",children:s.map(k=>I.jsxs(Mc,{htmlFor:`paw-${k.value}`,className:rr("flex items-center justify-center py-2 px-2 text-xs font-medium rounded-lg border-2 cursor-pointer transition-all",(i||"")===k.value?"border-green-500 bg-green-50/50 text-green-600":"border-border hover:border-green-500/50"),children:[I.jsx(xy,{value:k.value,id:`paw-${k.value}`,className:"sr-only"}),k.label]},k.value))})]}),I.jsx(bU,{children:I.jsx(Mg,{open:v,setOpen:b,titleWithIcon:I.jsxs(I.Fragment,{children:[I.jsx(eUe,{}),I.jsx("span",{children:g.formatMessage({id:"app.agviewer_map.stations",defaultMessage:"Stations"})})]}),trigger:I.jsxs(_r,{variant:"outline",className:"w-full border-2 border-dashed hover:border-green-500 hover:text-green-600 hover:bg-green-50",onClick:()=>{b(!0),t(null)},children:[I.jsx(mh,{className:"h-4 w-4 mr-2"}),"Find Specific Station"]}),onClose:P,children:I.jsx(Gx,{className:"border-none shadow-md",children:I.jsx(j.Suspense,{fallback:I.jsx("div",{className:"flex justify-center items-center h-40",children:I.jsx(Ja,{})}),children:I.jsx(tUe,{markersData:x,loading:w,handleDeleteMarker:O,onMarkerClick:M,onClose:P,intl:g})})})})})]})]})})}function lP(e,t,{checkForDefaultPrevented:r=!0}={}){return function(i){if(e==null||e(i),r===!1||!i.defaultPrevented)return t==null?void 0:t(i)}}function nUe(e,t=[]){let r=[];function n(a,o){const s=ie.createContext(o),u=r.length;r=[...r,o];const h=m=>{var T;const{scope:g,children:v,...b}=m,x=((T=g==null?void 0:g[e])==null?void 0:T[u])||s,w=ie.useMemo(()=>b,Object.values(b));return I.jsx(x.Provider,{value:w,children:v})};h.displayName=a+"Provider";function f(m,g){var x;const v=((x=g==null?void 0:g[e])==null?void 0:x[u])||s,b=ie.useContext(v);if(b)return b;if(o!==void 0)return o;throw new Error(`\`${m}\` must be used within \`${a}\``)}return[h,f]}const i=()=>{const a=r.map(o=>ie.createContext(o));return function(s){const u=(s==null?void 0:s[e])||a;return ie.useMemo(()=>({[`__scope${e}`]:{...s,[e]:u}}),[s,u])}};return i.scopeName=e,[n,iUe(i,...t)]}function iUe(...e){const t=e[0];if(e.length===1)return t;const r=()=>{const n=e.map(i=>({useScope:i(),scopeName:i.scopeName}));return function(a){const o=n.reduce((s,{useScope:u,scopeName:h})=>{const m=u(a)[`__scope${h}`];return{...s,...m}},{});return ie.useMemo(()=>({[`__scope${t.scopeName}`]:o}),[o])}};return r.scopeName=t.scopeName,r}function _U(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function wU(...e){return t=>{let r=!1;const n=e.map(i=>{const a=_U(i,t);return!r&&typeof a=="function"&&(r=!0),a});if(r)return()=>{for(let i=0;i<n.length;i++){const a=n[i];typeof a=="function"?a():_U(e[i],null)}}}}function aUe(...e){return ie.useCallback(wU(...e),e)}var cP=globalThis!=null&&globalThis.document?ie.useLayoutEffect:()=>{};function sUe(e,t){return ie.useReducer((r,n)=>t[r][n]??r,e)}var SU=e=>{const{present:t,children:r}=e,n=oUe(t),i=typeof r=="function"?r({present:n.isPresent}):ie.Children.only(r),a=aUe(n.ref,lUe(i));return typeof r=="function"||n.isPresent?ie.cloneElement(i,{ref:a}):null};SU.displayName="Presence";function oUe(e){const[t,r]=ie.useState(),n=ie.useRef({}),i=ie.useRef(e),a=ie.useRef("none"),o=e?"mounted":"unmounted",[s,u]=sUe(o,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return ie.useEffect(()=>{const h=cw(n.current);a.current=s==="mounted"?h:"none"},[s]),cP(()=>{const h=n.current,f=i.current;if(f!==e){const g=a.current,v=cw(h);e?u("MOUNT"):v==="none"||(h==null?void 0:h.display)==="none"?u("UNMOUNT"):u(f&&g!==v?"ANIMATION_OUT":"UNMOUNT"),i.current=e}},[e,u]),cP(()=>{if(t){let h;const f=t.ownerDocument.defaultView??window,m=v=>{const x=cw(n.current).includes(v.animationName);if(v.target===t&&x&&(u("ANIMATION_END"),!i.current)){const w=t.style.animationFillMode;t.style.animationFillMode="forwards",h=f.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=w)})}},g=v=>{v.target===t&&(a.current=cw(n.current))};return t.addEventListener("animationstart",g),t.addEventListener("animationcancel",m),t.addEventListener("animationend",m),()=>{f.clearTimeout(h),t.removeEventListener("animationstart",g),t.removeEventListener("animationcancel",m),t.removeEventListener("animationend",m)}}else u("ANIMATION_END")},[t,u]),{isPresent:["mounted","unmountSuspended"].includes(s),ref:ie.useCallback(h=>{h&&(n.current=getComputedStyle(h)),r(h)},[])}}function cw(e){return(e==null?void 0:e.animationName)||"none"}function lUe(e){var n,i;let t=(n=Object.getOwnPropertyDescriptor(e.props,"ref"))==null?void 0:n.get,r=t&&"isReactWarning"in t&&t.isReactWarning;return r?e.ref:(t=(i=Object.getOwnPropertyDescriptor(e,"ref"))==null?void 0:i.get,r=t&&"isReactWarning"in t&&t.isReactWarning,r?e.props.ref:e.props.ref||e.ref)}var EU=ie.forwardRef((e,t)=>{const{children:r,...n}=e,i=ie.Children.toArray(r),a=i.find(uUe);if(a){const o=a.props.children,s=i.map(u=>u===a?ie.Children.count(o)>1?ie.Children.only(null):ie.isValidElement(o)?o.props.children:null:u);return I.jsx(uP,{...n,ref:t,children:ie.isValidElement(o)?ie.cloneElement(o,void 0,s):null})}return I.jsx(uP,{...n,ref:t,children:r})});EU.displayName="Slot";var uP=ie.forwardRef((e,t)=>{const{children:r,...n}=e;if(ie.isValidElement(r)){const i=dUe(r);return ie.cloneElement(r,{...hUe(n,r.props),ref:t?wU(t,i):i})}return ie.Children.count(r)>1?ie.Children.only(null):null});uP.displayName="SlotClone";var cUe=({children:e})=>I.jsx(I.Fragment,{children:e});function uUe(e){return ie.isValidElement(e)&&e.type===cUe}function hUe(e,t){const r={...t};for(const n in t){const i=e[n],a=t[n];/^on[A-Z]/.test(n)?i&&a?r[n]=(...s)=>{a(...s),i(...s)}:i&&(r[n]=i):n==="style"?r[n]={...i,...a}:n==="className"&&(r[n]=[i,a].filter(Boolean).join(" "))}return{...e,...r}}function dUe(e){var n,i;let t=(n=Object.getOwnPropertyDescriptor(e.props,"ref"))==null?void 0:n.get,r=t&&"isReactWarning"in t&&t.isReactWarning;return r?e.ref:(t=(i=Object.getOwnPropertyDescriptor(e,"ref"))==null?void 0:i.get,r=t&&"isReactWarning"in t&&t.isReactWarning,r?e.props.ref:e.props.ref||e.ref)}var fUe=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","span","svg","ul"],uw=fUe.reduce((e,t)=>{const r=ie.forwardRef((n,i)=>{const{asChild:a,...o}=n,s=a?EU:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),I.jsx(s,{...o,ref:i})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{}),pUe=ie.createContext(void 0);function mUe(e){const t=ie.useContext(pUe);return e||t||"ltr"}function gUe({prop:e,defaultProp:t,onChange:r=()=>{}}){const[n,i]=yUe({defaultProp:t,onChange:r}),a=e!==void 0,o=a?e:n,s=Bs(r),u=ie.useCallback(h=>{if(a){const m=typeof h=="function"?h(e):h;m!==e&&s(m)}else i(h)},[a,e,i,s]);return[o,u]}function yUe({defaultProp:e,onChange:t}){const r=ie.useState(e),[n]=r,i=ie.useRef(n),a=Bs(t);return ie.useEffect(()=>{i.current!==n&&(a(n),i.current=n)},[n,i,a]),r}var vUe=ie.useId||(()=>{}),xUe=0;function bUe(e){const[t,r]=ie.useState(vUe());return cP(()=>{e||r(n=>n??String(xUe++))},[e]),e||(t?`radix-${t}`:"")}var hP="Tabs",[_Ue,PYe]=nUe(hP,[sw]),CU=sw(),[wUe,dP]=_Ue(hP),TU=ie.forwardRef((e,t)=>{const{__scopeTabs:r,value:n,onValueChange:i,defaultValue:a,orientation:o="horizontal",dir:s,activationMode:u="automatic",...h}=e,f=mUe(s),[m,g]=gUe({prop:n,onChange:i,defaultProp:a});return I.jsx(wUe,{scope:r,baseId:bUe(),value:m,onValueChange:g,orientation:o,dir:f,activationMode:u,children:I.jsx(uw.div,{dir:f,"data-orientation":o,...h,ref:t})})});TU.displayName=hP;var AU="TabsList",MU=ie.forwardRef((e,t)=>{const{__scopeTabs:r,loop:n=!0,...i}=e,a=dP(AU,r),o=CU(r);return I.jsx(iU,{asChild:!0,...o,orientation:a.orientation,dir:a.dir,loop:n,children:I.jsx(uw.div,{role:"tablist","aria-orientation":a.orientation,...i,ref:t})})});MU.displayName=AU;var IU="TabsTrigger",PU=ie.forwardRef((e,t)=>{const{__scopeTabs:r,value:n,disabled:i=!1,...a}=e,o=dP(IU,r),s=CU(r),u=DU(o.baseId,n),h=NU(o.baseId,n),f=n===o.value;return I.jsx(aU,{asChild:!0,...s,focusable:!i,active:f,children:I.jsx(uw.button,{type:"button",role:"tab","aria-selected":f,"aria-controls":h,"data-state":f?"active":"inactive","data-disabled":i?"":void 0,disabled:i,id:u,...a,ref:t,onMouseDown:lP(e.onMouseDown,m=>{!i&&m.button===0&&m.ctrlKey===!1?o.onValueChange(n):m.preventDefault()}),onKeyDown:lP(e.onKeyDown,m=>{[" ","Enter"].includes(m.key)&&o.onValueChange(n)}),onFocus:lP(e.onFocus,()=>{const m=o.activationMode!=="manual";!f&&!i&&m&&o.onValueChange(n)})})})});PU.displayName=IU;var OU="TabsContent",kU=ie.forwardRef((e,t)=>{const{__scopeTabs:r,value:n,forceMount:i,children:a,...o}=e,s=dP(OU,r),u=DU(s.baseId,n),h=NU(s.baseId,n),f=n===s.value,m=ie.useRef(f);return ie.useEffect(()=>{const g=requestAnimationFrame(()=>m.current=!1);return()=>cancelAnimationFrame(g)},[]),I.jsx(SU,{present:i||f,children:({present:g})=>I.jsx(uw.div,{"data-state":f?"active":"inactive","data-orientation":s.orientation,role:"tabpanel","aria-labelledby":u,hidden:!g,id:h,tabIndex:0,...o,ref:t,style:{...e.style,animationDuration:m.current?"0s":void 0},children:g&&a})})});kU.displayName=OU;function DU(e,t){return`${e}-trigger-${t}`}function NU(e,t){return`${e}-content-${t}`}var SUe=TU,LU=MU,FU=PU,RU=kU;const EUe=SUe,jU=ie.forwardRef(({className:e,...t},r)=>I.jsx(LU,{ref:r,className:rr("inline-flex h-10 items-center justify-center rounded-md bg-muted p-1 text-muted-foreground",e),...t}));jU.displayName=LU.displayName;const hw=ie.forwardRef(({className:e,...t},r)=>I.jsx(FU,{ref:r,className:rr("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}));hw.displayName=FU.displayName;const dw=ie.forwardRef(({className:e,...t},r)=>I.jsx(RU,{ref:r,className:rr("mt-2 ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",e),...t}));dw.displayName=RU.displayName;function CUe({activePanel:e,togglePanel:t,farms:r=[],plots:n=[],markers:i=[],formatLabel:a,onAddFarm:o,onAddPlot:s,onAddStation:u,onFarmsChange:h}){var Yt,qt,er,Pr;const{unfilteredMarkers:f=[],loading:m,markersData:g}=j.useContext(ys)||{},{plots:v}=j.useContext(xs)||{},b=v||n,x=f||i,[w,T]=j.useState(!1),[C,M]=j.useState(!1),[O,P]=j.useState(null),[k,D]=j.useState(!1),[V,U]=j.useState(""),[X,z]=j.useState(""),[W,H]=j.useState(""),[G,B]=j.useState(!1),[Z,Q]=j.useState(!1),[ae,oe]=j.useState(null),[te,ve]=j.useState(!1),[ce,q]=j.useState(!1),[se,he]=j.useState(!1),[be,Ae]=j.useState({name:"",area:""}),[le,K]=j.useState(!1),[ue,ge]=j.useState(!1),[Y,xe]=j.useState(null),[pe,Me]=j.useState(!1),[ye,Ee]=j.useState(!1),[Ge,We]=j.useState(!1),[Te,rt]=j.useState({location_name:""});j.useMemo(()=>f.map(Oe=>({value:Oe.id,label:(Oe==null?void 0:Oe.name)||(Oe==null?void 0:Oe.title)||(Oe==null?void 0:Oe.label)||`Marker ${(Oe==null?void 0:Oe.id)||""}`})),[f]);const it=j.useMemo(()=>{if(!V.trim())return r;const Oe=V.toLowerCase();return r.filter(Ce=>{var de,Pe;return((de=Ce.label)==null?void 0:de.toLowerCase().includes(Oe))||((Pe=Ce.details)==null?void 0:Pe.toLowerCase().includes(Oe))})},[r,V]),Be=j.useMemo(()=>{if(!X.trim())return n;const Oe=X.toLowerCase();return n.filter(Ce=>{var Qe,nt,ct,et,yt,Ot,wt,Bt,Fe;const de=((nt=(Qe=Ce==null?void 0:Ce.options)==null?void 0:Qe.properties)==null?void 0:nt.name)||((ct=Ce==null?void 0:Ce.properties)==null?void 0:ct.name)||`Plot ${(Ce==null?void 0:Ce.id)||""}`,Pe=((yt=(et=Ce==null?void 0:Ce.options)==null?void 0:et.properties)==null?void 0:yt.farm_name)||((Ot=Ce==null?void 0:Ce.properties)==null?void 0:Ot.farm_name)||"Unknown Farm",Ne=((Bt=(wt=Ce==null?void 0:Ce.options)==null?void 0:wt.properties)==null?void 0:Bt.area)||((Fe=Ce==null?void 0:Ce.properties)==null?void 0:Fe.area)||"N/A";return de.toLowerCase().includes(Oe)||Pe.toLowerCase().includes(Oe)||String(Ne).toLowerCase().includes(Oe)})},[n,X]),je=j.useMemo(()=>{if(!W.trim())return x;const Oe=W.toLowerCase();return x.filter(Ce=>{var nt,ct,et;const de=((nt=Ce==null?void 0:Ce.properties)==null?void 0:nt.name)||(Ce==null?void 0:Ce.name)||`Station ${(Ce==null?void 0:Ce.id)||""}`,Pe=((ct=Ce==null?void 0:Ce.properties)==null?void 0:ct.farm_name)||(Ce==null?void 0:Ce.farm_name)||"Unknown Farm",Ne=((et=Ce==null?void 0:Ce.properties)==null?void 0:et.paw_status)||(Ce==null?void 0:Ce.paw_status)||"Unknown",Qe=a(Ne);return de.toLowerCase().includes(Oe)||Pe.toLowerCase().includes(Oe)||Ne.toLowerCase().includes(Oe)||Qe.toLowerCase().includes(Oe)})},[x,W,a]),$e=j.useCallback(()=>{P(null)},[]),He=j.useCallback(()=>{T(!1),setTimeout($e,200)},[$e]),at=j.useCallback(Oe=>{Oe&&(P(Oe),T(!0))},[]),Ze=j.useCallback(async Oe=>{if(!O)return;const Ce=b.filter(Pe=>{const Ne=Pe==null?void 0:Pe.farm;return Ne?(typeof Ne=="object"?Ne==null?void 0:Ne.id:Ne)==O.value:!1}),de=QL(Ce);await aC(O.value,Oe.name.trim(),Oe.marker_set||[],Oe.season_start_date||void 0,de,Oe.status,Oe.weather_station,Oe.unit_system),an.success("Farm updated successfully"),h&&await h()},[O,b,h]),ut=j.useCallback(Oe=>{P(Oe),M(!0)},[]),gt=j.useCallback(async()=>{if(O){D(!0);try{await sC(O.value),an.success("Farm deleted successfully"),M(!1),$e(),h&&await h()}catch{an.error("Failed to delete farm")}finally{D(!1)}}},[h,$e,O]),xt=j.useCallback(async Oe=>{var Ce,de,Pe,Ne,Qe,nt,ct,et,yt;if(Oe){oe(Oe),B(!0),ve(!0);try{const Ot=(Oe==null?void 0:Oe.id)||((de=(Ce=Oe==null?void 0:Oe.options)==null?void 0:Ce.properties)==null?void 0:de.id)||((Pe=Oe==null?void 0:Oe.options)==null?void 0:Pe.id),wt=((Qe=(Ne=Oe==null?void 0:Oe.options)==null?void 0:Ne.properties)==null?void 0:Qe.name)||((nt=Oe==null?void 0:Oe.properties)==null?void 0:nt.name)||(Oe==null?void 0:Oe.name)||"",Bt=((et=(ct=Oe==null?void 0:Oe.options)==null?void 0:ct.properties)==null?void 0:et.area)||((yt=Oe==null?void 0:Oe.properties)==null?void 0:yt.area)||(Oe==null?void 0:Oe.area)||"";Ae({name:wt,area:Bt?String(Bt):""})}catch{an.error("Failed to load plot details"),B(!1)}finally{ve(!1)}}},[]),It=j.useCallback(async()=>{var Oe,Ce,de,Pe;if(ae){if(!((Oe=be.name)!=null&&Oe.trim())){an.error("Please provide a plot name");return}q(!0);try{const Qe={id:(ae==null?void 0:ae.id)||((de=(Ce=ae==null?void 0:ae.options)==null?void 0:Ce.properties)==null?void 0:de.id)||((Pe=ae==null?void 0:ae.options)==null?void 0:Pe.id),name:be.name.trim()};be.area&&(Qe.area=parseFloat(be.area)||null),await e5(Qe),an.success("Plot updated successfully"),B(!1),Ae({name:"",area:""}),oe(null),h&&await h()}catch{an.error("Failed to update plot")}finally{q(!1)}}},[be.name,be.area,ae,h]),ht=j.useCallback(Oe=>{oe(Oe),Q(!0)},[]),Pt=j.useCallback(async()=>{var Oe,Ce,de;if(ae){he(!0);try{const Pe=(ae==null?void 0:ae.id)||((Ce=(Oe=ae==null?void 0:ae.options)==null?void 0:Oe.properties)==null?void 0:Ce.id)||((de=ae==null?void 0:ae.options)==null?void 0:de.id);await t5(Pe),an.success("Plot deleted successfully"),Q(!1),oe(null),h&&await h()}catch{an.error("Failed to delete plot")}finally{he(!1)}}},[ae,h]),Lt=j.useCallback(async Oe=>{var Ce,de;if(Oe){xe(Oe),K(!0),Me(!0);try{const Pe=(Oe==null?void 0:Oe.id)||((Ce=Oe==null?void 0:Oe.properties)==null?void 0:Ce.id),Ne=await v4(Pe);rt({location_name:(Ne==null?void 0:Ne.location_name)||((de=Oe==null?void 0:Oe.properties)==null?void 0:de.name)||(Oe==null?void 0:Oe.name)||""})}catch{an.error("Failed to load station details"),K(!1)}finally{Me(!1)}}},[]),Xt=j.useCallback(async()=>{var Oe,Ce;if(Y){if(!((Oe=Te.location_name)!=null&&Oe.trim())){an.error("Please provide a station name");return}Ee(!0);try{const de=(Y==null?void 0:Y.id)||((Ce=Y==null?void 0:Y.properties)==null?void 0:Ce.id),Pe={id:de,location_name:Te.location_name.trim()},Ne=await v4(de);await x4({...Ne,...Pe}),an.success("Station updated successfully"),K(!1),rt({location_name:""}),xe(null),h&&await h()}catch{an.error("Failed to update station")}finally{Ee(!1)}}},[Te.location_name,Y,h]),Ut=j.useCallback(Oe=>{xe(Oe),ge(!0)},[]),Dt=j.useCallback(async()=>{var Oe;if(Y){We(!0);try{const Ce=(Y==null?void 0:Y.id)||((Oe=Y==null?void 0:Y.properties)==null?void 0:Oe.id);await b4(Ce),an.success("Station deleted successfully"),ge(!1),xe(null),h&&await h()}catch{an.error("Failed to delete station")}finally{We(!1)}}},[Y,h]);return I.jsxs("div",{className:rr("absolute top-16 sm:top-20 left-2 right-2 sm:left-1/2 sm:-translate-x-1/2 z-[1101] w-auto sm:w-96 transition-all duration-300 origin-top pointer-events-none",e==="settings"?"opacity-100 translate-y-0 pointer-events-auto":"opacity-0 -translate-y-10 pointer-events-none"),children:[I.jsxs("div",{className:"bg-white/90 backdrop-blur-xl rounded-xl sm:rounded-2xl shadow-2xl overflow-hidden flex flex-col max-h-[85vh] border border-white/50",children:[I.jsxs("div",{className:"p-4 border-b border-border flex justify-between items-center bg-white/50",children:[I.jsxs("div",{children:[I.jsx("h2",{className:"font-bold text-foreground",children:"Data Management"}),I.jsx("p",{className:"text-xs text-muted-foreground",children:"Manage farms, plots & stations"})]}),I.jsx(_r,{variant:"ghost",size:"icon",className:"h-8 w-8 rounded-full",onClick:()=>t(null),children:I.jsx(gs,{className:"h-5 w-5"})})]}),I.jsxs(EUe,{defaultValue:"farms",className:"flex-1 flex flex-col",children:[I.jsxs(jU,{className:"w-full rounded-none border-b bg-muted/50 grid grid-cols-3",children:[I.jsx(hw,{value:"farms",className:"text-[10px] sm:text-xs font-bold uppercase tracking-wide px-2 sm:px-4",children:"Farms"}),I.jsx(hw,{value:"plots",className:"text-[10px] sm:text-xs font-bold uppercase tracking-wide px-2 sm:px-4",children:"Plots"}),I.jsx(hw,{value:"stations",className:"text-[10px] sm:text-xs font-bold uppercase tracking-wide px-2 sm:px-4",children:"Stations"})]}),I.jsxs(dw,{value:"farms",className:"flex-1 overflow-y-auto p-4 space-y-3 mt-0",children:[I.jsx("h3",{className:"font-semibold text-sm mb-3",children:"All Farms"}),I.jsxs("div",{className:"relative mb-3",children:[I.jsx(mh,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),I.jsx(Zo,{placeholder:"Search farms...",value:V,onChange:Oe=>U(Oe.target.value),className:"pl-9 h-9"})]}),I.jsx("div",{className:"space-y-2 mb-4 max-h-[350px] overflow-y-auto",children:it.length===0?I.jsx("div",{className:"py-6 text-center text-sm text-muted-foreground",children:V.trim()?"No farms found.":"No farms available."}):it.map(Oe=>I.jsx("div",{className:"bg-white/60 p-3 rounded-lg border border-border hover:border-green-500/50 transition-colors cursor-pointer group",children:I.jsxs("div",{className:"flex items-center justify-between",children:[I.jsxs("div",{className:"flex items-center gap-2",children:[I.jsx("div",{className:"w-8 h-8 bg-green-100 rounded-lg flex items-center justify-center",children:I.jsx(NS,{className:"h-4 w-4 text-green-600"})}),I.jsxs("div",{children:[I.jsx("p",{className:"text-sm font-medium",children:Oe.label}),I.jsx("p",{className:"text-xs text-muted-foreground",children:Oe.details})]})]}),I.jsxs("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity",children:[I.jsx(_r,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:()=>at(Oe),"aria-label":"Edit farm",children:I.jsx(RS,{className:"h-4 w-4"})}),I.jsx(_r,{variant:"ghost",size:"icon",className:"h-8 w-8 text-destructive hover:text-destructive",onClick:()=>ut(Oe),"aria-label":"Delete farm",children:I.jsx(qv,{className:"h-4 w-4"})})]})]})},Oe.value))}),I.jsxs(_r,{variant:"outline",className:"w-full border-2 border-dashed hover:border-green-500 hover:text-green-600 hover:bg-green-50",onClick:o,children:[I.jsx(hg,{className:"h-4 w-4 mr-2"}),"Add New Farm"]})]}),I.jsxs(dw,{value:"plots",className:"flex-1 overflow-y-auto p-4 space-y-3 mt-0",children:[I.jsx("h3",{className:"font-semibold text-sm mb-3",children:"All Plots"}),I.jsxs("div",{className:"relative mb-3",children:[I.jsx(mh,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),I.jsx(Zo,{placeholder:"Search plots...",value:X,onChange:Oe=>z(Oe.target.value),className:"pl-9 h-9"})]}),I.jsx("div",{className:"space-y-2 max-h-[350px] overflow-y-auto",children:Be.length===0?I.jsx("div",{className:"py-6 text-center text-sm text-muted-foreground",children:X.trim()?"No plots found.":"No plots available."}):Be.map(Oe=>{var Ne,Qe,nt,ct,et,yt,Ot,wt,Bt,Fe,Se;const Ce=((Qe=(Ne=Oe==null?void 0:Oe.options)==null?void 0:Ne.properties)==null?void 0:Qe.name)||((nt=Oe==null?void 0:Oe.properties)==null?void 0:nt.name)||`Plot ${(Oe==null?void 0:Oe.id)||""}`,de=((et=(ct=Oe==null?void 0:Oe.options)==null?void 0:ct.properties)==null?void 0:et.farm_name)||((yt=Oe==null?void 0:Oe.properties)==null?void 0:yt.farm_name)||"Unknown Farm",Pe=((wt=(Ot=Oe==null?void 0:Oe.options)==null?void 0:Ot.properties)==null?void 0:wt.area)||((Bt=Oe==null?void 0:Oe.properties)==null?void 0:Bt.area)||"N/A";return I.jsx("div",{className:"bg-white/60 p-3 rounded-lg border border-border hover:border-green-500/50 transition-colors cursor-pointer group",children:I.jsxs("div",{className:"flex items-center justify-between",children:[I.jsxs("div",{className:"flex items-center gap-2",children:[I.jsx("div",{className:"w-8 h-8 bg-blue-100 rounded-lg flex items-center justify-center",children:I.jsx(ug,{className:"h-4 w-4 text-blue-600"})}),I.jsxs("div",{children:[I.jsx("p",{className:"text-sm font-medium",children:Ce}),I.jsxs("p",{className:"text-xs text-muted-foreground",children:[de," • ",Pe]})]})]}),I.jsxs("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity",children:[I.jsx(_r,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:()=>xt(Oe),"aria-label":"Edit plot",children:I.jsx(RS,{className:"h-4 w-4"})}),I.jsx(_r,{variant:"ghost",size:"icon",className:"h-8 w-8 text-destructive hover:text-destructive",onClick:()=>ht(Oe),"aria-label":"Delete plot",children:I.jsx(qv,{className:"h-4 w-4"})})]})]})},(Oe==null?void 0:Oe.id)||((Se=(Fe=Oe==null?void 0:Oe.options)==null?void 0:Fe.properties)==null?void 0:Se.id))})}),I.jsxs(_r,{variant:"outline",className:"w-full border-2 border-dashed hover:border-green-500 hover:text-green-600 hover:bg-green-50",onClick:s,children:[I.jsx(hg,{className:"h-4 w-4 mr-2"}),"Add Plot"]})]}),I.jsxs(dw,{value:"stations",className:"flex-1 overflow-y-auto p-4 space-y-3 mt-0",children:[I.jsx("h3",{className:"font-semibold text-sm mb-3",children:"All Stations"}),I.jsxs("div",{className:"relative mb-3",children:[I.jsx(mh,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),I.jsx(Zo,{placeholder:"Search stations...",value:W,onChange:Oe=>H(Oe.target.value),className:"pl-9 h-9"})]}),I.jsx("div",{className:"space-y-2 max-h-[350px] overflow-y-auto",children:je.length===0?I.jsx("div",{className:"py-6 text-center text-sm text-muted-foreground",children:W.trim()?"No stations found.":"No stations available."}):je.map(Oe=>{var Qe,nt,ct,et;const Ce=((Qe=Oe==null?void 0:Oe.properties)==null?void 0:Qe.name)||(Oe==null?void 0:Oe.name)||`Station ${(Oe==null?void 0:Oe.id)||""}`,de=((nt=Oe==null?void 0:Oe.properties)==null?void 0:nt.farm_name)||(Oe==null?void 0:Oe.farm_name)||"Unknown Farm",Pe=((ct=Oe==null?void 0:Oe.properties)==null?void 0:ct.paw_status)||(Oe==null?void 0:Oe.paw_status)||"Unknown",Ne=Pe==="OPTIMAL"||Pe==="optimal"?"green":Pe==="STRESS_START"||Pe==="stress"?"orange":"gray";return I.jsx("div",{className:"bg-white/60 p-3 rounded-lg border border-border hover:border-green-500/50 transition-colors cursor-pointer group",children:I.jsxs("div",{className:"flex items-center justify-between",children:[I.jsxs("div",{className:"flex items-center gap-2",children:[I.jsx("div",{className:rr("w-8 h-8 rounded-lg flex items-center justify-center",Ne==="orange"&&"bg-orange-100",Ne==="green"&&"bg-green-100",Ne==="gray"&&"bg-gray-100"),children:I.jsx(Zv,{className:rr("h-4 w-4",Ne==="orange"&&"text-orange-600",Ne==="green"&&"text-green-600",Ne==="gray"&&"text-gray-600")})}),I.jsxs("div",{children:[I.jsx("p",{className:"text-sm font-medium",children:Ce}),I.jsxs("p",{className:"text-xs text-muted-foreground",children:[de," • ",a(Pe)]})]})]}),I.jsxs("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity",children:[I.jsx(_r,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:()=>Lt(Oe),"aria-label":"Edit station",children:I.jsx(RS,{className:"h-4 w-4"})}),I.jsx(_r,{variant:"ghost",size:"icon",className:"h-8 w-8 text-destructive hover:text-destructive",onClick:()=>Ut(Oe),"aria-label":"Delete station",children:I.jsx(qv,{className:"h-4 w-4"})})]})]})},(Oe==null?void 0:Oe.id)||((et=Oe==null?void 0:Oe.properties)==null?void 0:et.id))})}),I.jsxs(_r,{variant:"outline",className:"w-full border-2 border-dashed hover:border-green-500 hover:text-green-600 hover:bg-green-50",onClick:u,children:[I.jsx(hg,{className:"h-4 w-4 mr-2"}),"Add Station"]})]})]})]}),I.jsx(yz,{open:w,onOpenChange:T,farm:O?{id:O.value,name:O.label}:null,onSave:Ze,onClose:He}),I.jsx(vy,{isOpen:C,onClose:()=>M(!1),onConfirm:gt,onCancel:()=>M(!1),title:"Delete farm",message:`Are you sure you want to delete "${(O==null?void 0:O.label)||"this farm"}"?`,confirmText:k?"Deleting...":"Delete",cancelText:"Cancel",variant:"destructive"}),I.jsx(r_,{open:G,onOpenChange:Oe=>!Oe&&B(!1),children:I.jsxs(j0,{className:"w-[calc(100vw-2rem)] sm:max-w-lg",children:[I.jsxs(B0,{children:[I.jsx(Au,{children:"Edit Plot"}),I.jsx(i_,{children:"Update the plot name and area."})]}),I.jsxs("div",{className:"space-y-4",children:[I.jsxs("div",{className:"space-y-2",children:[I.jsx("p",{className:"text-sm font-medium text-foreground",children:"Plot Name"}),I.jsx(Zo,{value:be.name,onChange:Oe=>Ae(Ce=>({...Ce,name:Oe.target.value})),placeholder:"Plot name",disabled:te})]}),I.jsxs("div",{className:"space-y-2",children:[I.jsx("p",{className:"text-sm font-medium text-foreground",children:"Area"}),I.jsx(Zo,{type:"number",value:be.area,onChange:Oe=>Ae(Ce=>({...Ce,area:Oe.target.value})),placeholder:"Area (optional)",disabled:te})]})]}),I.jsxs(n_,{children:[I.jsx(_r,{variant:"outline",onClick:()=>B(!1),disabled:ce,children:"Cancel"}),I.jsx(_r,{onClick:It,disabled:ce||te,children:ce?"Saving...":"Save changes"})]})]})}),I.jsx(vy,{isOpen:Z,onClose:()=>Q(!1),onConfirm:Pt,onCancel:()=>Q(!1),title:"Delete plot",message:`Are you sure you want to delete "${((qt=(Yt=ae==null?void 0:ae.options)==null?void 0:Yt.properties)==null?void 0:qt.name)||((er=ae==null?void 0:ae.properties)==null?void 0:er.name)||(ae==null?void 0:ae.name)||"this plot"}"?`,confirmText:se?"Deleting...":"Delete",cancelText:"Cancel",variant:"destructive"}),I.jsx(r_,{open:le,onOpenChange:Oe=>!Oe&&K(!1),children:I.jsxs(j0,{className:"w-[calc(100vw-2rem)] sm:max-w-lg",children:[I.jsxs(B0,{children:[I.jsx(Au,{children:"Edit Station"}),I.jsx(i_,{children:"Update the station name."})]}),I.jsx("div",{className:"space-y-4",children:I.jsxs("div",{className:"space-y-2",children:[I.jsx("p",{className:"text-sm font-medium text-foreground",children:"Station Name"}),I.jsx(Zo,{value:Te.location_name,onChange:Oe=>rt(Ce=>({...Ce,location_name:Oe.target.value})),placeholder:"Station name",disabled:pe})]})}),I.jsxs(n_,{children:[I.jsx(_r,{variant:"outline",onClick:()=>K(!1),disabled:ye,children:"Cancel"}),I.jsx(_r,{onClick:Xt,disabled:ye||pe,children:ye?"Saving...":"Save changes"})]})]})}),I.jsx(vy,{isOpen:ue,onClose:()=>ge(!1),onConfirm:Dt,onCancel:()=>ge(!1),title:"Delete station",message:`Are you sure you want to delete "${((Pr=Y==null?void 0:Y.properties)==null?void 0:Pr.name)||(Y==null?void 0:Y.name)||"this station"}"?`,confirmText:Ge?"Deleting...":"Delete",cancelText:"Cancel",variant:"destructive"})]})}function TUe({selectedFarm:e,farmOpen:t,setFarmOpen:r,farms:n=[],handleFarmSelect:i,onAddFarm:a}){const[o,s]=j.useState(""),u=j.useMemo(()=>{if(!o.trim())return n;const f=o.toLowerCase();return n.filter(m=>{var g,v;return((g=m.label)==null?void 0:g.toLowerCase().includes(f))||((v=m.details)==null?void 0:v.toLowerCase().includes(f))})},[n,o]),h=(f,m)=>{i(e===m||e===f?null:f),r(!1),s("")};return I.jsxs(wx,{open:t,onOpenChange:r,children:[I.jsx(Sx,{asChild:!0,children:I.jsxs(_r,{variant:"ghost",className:"h-9 sm:h-10 px-2 sm:px-4 rounded-none flex items-center gap-1.5 sm:gap-3 hover:bg-white/50 text-foreground shrink-0",children:[I.jsx(NS,{className:"h-3.5 w-3.5 sm:h-4 sm:w-4 text-muted-foreground shrink-0"}),I.jsxs("div",{className:"flex flex-col items-start leading-none hidden sm:flex",children:[I.jsx("span",{className:"text-[10px] font-bold text-muted-foreground uppercase tracking-wider",children:"Farm"}),I.jsx("span",{className:"text-xs font-bold whitespace-nowrap max-w-[120px] lg:max-w-none truncate",children:e||"Select a farm"})]}),I.jsx(Jl,{className:"h-3 w-3 text-muted-foreground ml-1 shrink-0 hidden sm:!block"})]})}),I.jsx(kE,{className:"w-[calc(100vw-2rem)] sm:w-[280px] p-0 z-[1102]",align:"start",children:I.jsxs("div",{className:"flex flex-col",children:[I.jsxs("div",{className:"flex items-center border-b px-3",children:[I.jsx(mh,{className:"mr-2 h-4 w-4 shrink-0 opacity-50"}),I.jsx(Zo,{placeholder:"Search farm...",value:o,onChange:f=>s(f.target.value),className:"border-none focus-visible:ring-0 focus-visible:ring-offset-0 focus-visible:shadow-none h-11 bg-transparent px-0"})]}),I.jsx("div",{className:"max-h-[350px] overflow-y-auto",children:u.length===0?I.jsx("div",{className:"py-6 text-center text-sm text-muted-foreground",children:"No farm found."}):I.jsxs(I.Fragment,{children:[I.jsx("div",{className:"px-2 py-1.5 text-xs font-medium text-muted-foreground",children:"Farms"}),I.jsx("div",{className:"p-1",children:u.map(f=>I.jsxs("div",{onClick:()=>h(f.value,f.label),className:rr("relative flex w-full cursor-pointer select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none hover:bg-accent hover:text-accent-foreground",(e===f.label||e===f.value)&&"bg-accent text-accent-foreground"),children:[I.jsx(LS,{className:rr("mr-2 h-4 w-4",e===f.label||e===f.value?"opacity-100":"opacity-0")}),I.jsxs("div",{className:"flex flex-col",children:[I.jsx("span",{children:f.label}),I.jsx("span",{className:"text-xs text-muted-foreground",children:f.details})]})]},f.value))})]})}),I.jsx("div",{className:"h-px bg-border mx-1"}),I.jsx("div",{className:"p-2 border-t",children:I.jsxs(_r,{variant:"ghost",className:"w-full justify-start h-9 text-sm font-medium text-muted-foreground hover:text-green-600 hover:bg-green-50",onClick:a,children:[I.jsx(hg,{className:"h-4 w-4 mr-2"}),"Add New Farm"]})})]})})]})}function AUe({enabled:e=!0,handler:t,excludedSelectors:r=[],delay:n=0,eventType:i="mousedown"}){const a=j.useRef(null),o=j.useRef(null),s=j.useCallback(u=>{if(!a.current||!t)return;const h=u.target;if(a.current.contains(h))return;r.some(m=>{const g=h.closest(m);return g&&!a.current.contains(g)})||t(u)},[t,r]);return j.useEffect(()=>{if(!e)return;o.current&&clearTimeout(o.current);const u=()=>{document.addEventListener(i,s),(i==="mousedown"||i==="click")&&document.addEventListener("touchstart",s)};return n>0?o.current=setTimeout(u,n):u(),()=>{o.current&&clearTimeout(o.current),document.removeEventListener(i,s),(i==="mousedown"||i==="click")&&document.removeEventListener("touchstart",s)}},[e,n,i,s]),a}function MUe({mapRef:e}){const[t,r]=j.useState(null),[n,i]=j.useState(null),[a,o]=j.useState(!1),[s,u]=j.useState(""),[h,f]=j.useState(!1);zt(Ee=>Ee.setSidebarExpanded);const m=zt(Ee=>Ee.setViewMode),{markerFilters:g,setMarkerFilters:v,showMarkers:b,setShowMarkers:x,markers:w,unfilteredMarkers:T}=j.useContext(ys),{plots:C}=j.useContext(xs),{farmOptions:M,refreshFarms:O}=j.useContext(yu),P=zt(Ee=>Ee.rasterLayer),k=zt(Ee=>Ee.setRasterLayer),D=zt(Ee=>Ee.showCroppedImages),V=zt(Ee=>Ee.setShowCroppedImages),U=zt(Ee=>Ee.rasterOpacity),X=zt(Ee=>Ee.setRasterOpacity),{isVisible:z,setIsVisible:W}=j.useContext(yp),H=j.useCallback(Ee=>{const Ge=Dm("selected-farm");if(Ge&&Ee.length>0){const We=Ee.find(Te=>Te.value===Ge||Te.value==Ge);if(We){i(We.label),v(Te=>({...Te,farm_id:We.value}));return}}i(null),L2("selected-farm"),v(We=>({...We,farm_id:null}))},[v]);j.useEffect(()=>{M&&M.length>0&&H(M)},[M,H]);const G=j.useCallback(Ee=>{r(t===Ee?null:Ee)},[t]),B=j.useCallback(Ee=>{const Ge=M.find(rt=>rt.value===Ee);if(Ge?(i(Ge.label),Ld("selected-farm",Ee)):(i(null),L2("selected-farm")),o(!1),v({...g,farm_id:Ee||null}),!Ee||!(e!=null&&e.current))return;const We=C.filter(rt=>{const it=rt==null?void 0:rt.farm;return it?(typeof it=="object"?it==null?void 0:it.id:it)==Ee:!1});if(We.length>0){const rt=new Nm.LngLatBounds;let it=!1;if(We.forEach(Be=>{var $e;const je=(($e=Be==null?void 0:Be.options)==null?void 0:$e.geometry)||(Be==null?void 0:Be.geometry);if(je!=null&&je.coordinates){const He=je.type==="Polygon"?je.coordinates[0]:je.coordinates;Array.isArray(He)&&He.forEach(at=>{Array.isArray(at)&&at.length>=2&&(rt.extend([at[0],at[1]]),it=!0)})}}),it){const Be=e.current.getMap();Be&&Be.fitBounds(rt,{padding:100,maxZoom:15,essential:!0});return}}const Te=T==null?void 0:T.find(rt=>{var it;return((it=rt==null?void 0:rt.farm)==null?void 0:it.id)==Ee});if(Te!=null&&Te.lat&&(Te!=null&&Te.lng)){const rt=e.current.getMap();rt&&rt.flyTo({center:[Te.lng,Te.lat],essential:!0,zoom:12})}},[M,g,v,C,T,e]),Z=j.useCallback(()=>{O()},[O]),Q=j.useCallback(Ee=>!Ee||Ee===""?"All":Ee.charAt(0).toUpperCase()+Ee.slice(1).replace(/_/g," "),[]),ae=(g==null?void 0:g.type)||"",oe=(g==null?void 0:g.paw_status)||"",te=D?"plot":"map",ve=j.useCallback(Ee=>{V(Ee==="plot")},[V]),ce=P,q=j.useCallback(Ee=>{k(Ee)},[k]),se=[{value:"",label:"All"},{value:"station",label:"Station"},{value:"forecast",label:"Forecast"}],he=[{value:"",label:"All"},{value:"OPTIMAL",label:"Optimal"},{value:"STRESS_START",label:"Stress"},{value:"SEVERE_STRESS",label:"Severe"}],be=j.useCallback(Ee=>{v({...g,type:Ee})},[g,v]),Ae=j.useCallback(Ee=>{v({...g,paw_status:Ee})},[g,v]),le=j.useCallback(Ee=>{if(!(e!=null&&e.current))return;const Ge=e.current.getMap();Ge&&Ge.getStyle().layers.forEach(We=>{We.id.startsWith("croppedImageLayer-")&&Ge.setPaintProperty(We.id,"raster-opacity",Number(Ee/100))})},[e]),K=xh(le,500),ue=[U],ge=j.useCallback(Ee=>{const Ge=Ee[0];X(Ge),K(Ge)},[X,K]),Y=j.useCallback(()=>{m(Xr.ADD_NEW_FARM),r(null)},[m]),xe=j.useCallback(()=>{m(Xr.ADD_PLOT),r(null)},[m]),pe=j.useCallback(()=>{m(Xr.ADD_MARKER),r(null)},[m]),Me=j.useMemo(()=>{if(!s||s.trim()==="")return[];const Ee=s.toLowerCase().trim(),Ge=[],We=w||[];return M.forEach(Te=>{const rt=(Te.label||"").toLowerCase(),it=(Te.details||"").toLowerCase();(rt.includes(Ee)||it.includes(Ee))&&Ge.push({id:`farm-${Te.value}`,type:"farm",label:Te.label,subLabel:Te.details||"Farm",data:Te})}),C.forEach(Te=>{var je,$e,He,at,Ze,ut,gt,xt,It,ht,Pt,Lt,Xt,Ut,Dt,Yt,qt;const rt=((($e=(je=Te==null?void 0:Te.options)==null?void 0:je.properties)==null?void 0:$e.name)||((He=Te==null?void 0:Te.properties)==null?void 0:He.name)||`Plot ${(Te==null?void 0:Te.id)||""}`).toLowerCase(),it=(((Ze=(at=Te==null?void 0:Te.options)==null?void 0:at.properties)==null?void 0:Ze.farm_name)||((ut=Te==null?void 0:Te.properties)==null?void 0:ut.farm_name)||"Unknown Farm").toLowerCase(),Be=((xt=(gt=Te==null?void 0:Te.options)==null?void 0:gt.properties)==null?void 0:xt.area)||((It=Te==null?void 0:Te.properties)==null?void 0:It.area)||"N/A";if(rt.includes(Ee)||it.includes(Ee)){const er=((Pt=(ht=Te==null?void 0:Te.options)==null?void 0:ht.properties)==null?void 0:Pt.farm_name)||((Lt=Te==null?void 0:Te.properties)==null?void 0:Lt.farm_name)||"Unknown Farm";Ge.push({id:`plot-${(Te==null?void 0:Te.id)||((Ut=(Xt=Te==null?void 0:Te.options)==null?void 0:Xt.properties)==null?void 0:Ut.id)}`,type:"plot",label:((Yt=(Dt=Te==null?void 0:Te.options)==null?void 0:Dt.properties)==null?void 0:Yt.name)||((qt=Te==null?void 0:Te.properties)==null?void 0:qt.name)||`Plot ${(Te==null?void 0:Te.id)||""}`,subLabel:`${er} • ${Be}`,data:Te})}}),We.forEach(Te=>{var at,Ze,ut,gt,xt,It;const rt=((Te==null?void 0:Te.title)||"").toLowerCase(),it=((Te==null?void 0:Te.location_name)||"").toLowerCase(),Be=(((at=Te==null?void 0:Te.device)==null?void 0:at.name)||"").toLowerCase(),je=(((Ze=Te==null?void 0:Te.device)==null?void 0:Ze.serial)||"").toLowerCase(),$e=(((ut=Te==null?void 0:Te.farm)==null?void 0:ut.name)||(Te==null?void 0:Te.farm_name)||"Unknown Farm").toLowerCase(),He=(Te==null?void 0:Te.paw_status)||((gt=Te==null?void 0:Te.properties)==null?void 0:gt.paw_status)||"Unknown";if(rt.includes(Ee)||it.includes(Ee)||Be.includes(Ee)||je.includes(Ee)||$e.includes(Ee)){const ht=((xt=Te==null?void 0:Te.farm)==null?void 0:xt.name)||(Te==null?void 0:Te.farm_name)||"Unknown Farm";Ge.push({id:`station-${(Te==null?void 0:Te.id)||((It=Te==null?void 0:Te.properties)==null?void 0:It.id)}`,type:"station",label:(Te==null?void 0:Te.title)||(Te==null?void 0:Te.location_name)||`Station ${(Te==null?void 0:Te.id)||""}`,subLabel:`${ht} • ${Q(He)}`,data:Te})}}),Ge},[s,M,C,w,Q]),ye=j.useCallback(Ee=>{var Ge,We;if(e!=null&&e.current){if(Ee.type==="farm")B(Ee.data.value),f(!1),u("");else if(Ee.type==="plot"){const Te=Ee.data,rt=((Ge=Te==null?void 0:Te.options)==null?void 0:Ge.geometry)||(Te==null?void 0:Te.geometry);if(rt&&rt.coordinates){const it=rt.coordinates[0]||rt.coordinates;if(it&&it.length>0){let Be=0,je=0;const $e=it.filter(He=>He&&He.length>=2);if($e.forEach(He=>{const[at,Ze]=He;je+=at,Be+=Ze}),$e.length>0){const He=je/$e.length,at=Be/$e.length;e.current.flyTo({center:[He,at],zoom:14})}}}f(!1),u("")}else if(Ee.type==="station"){const Te=Ee.data,rt=(Te==null?void 0:Te.location)||((We=Te==null?void 0:Te.properties)==null?void 0:We.location);if(rt){const it=rt.lat||rt.latitude,Be=rt.lng||rt.longitude;it&&Be&&e.current.flyTo({center:[Be,it],zoom:14})}f(!1),u("")}}},[e,B,f,u]);return j.useEffect(()=>{if(!(e!=null&&e.current)||!h)return;const Ee=e.current.getMap();if(!Ee)return;const Ge=()=>{f(!1);const We=document.querySelector("[data-search-container]");if(We){const Te=We.querySelector('input[type="text"]');Te&&Te.blur()}};return Ee.on("click",Ge),Ee.on("touchstart",Ge),()=>{Ee.off("click",Ge),Ee.off("touchstart",Ge)}},[e,h,f]),I.jsx(IUe,{activePanel:t,togglePanel:G,selectedFarm:n,farmOpen:a,setFarmOpen:o,farms:M,handleFarmSelect:B,markerType:ae,pawStatus:oe,formatLabel:Q,searchQuery:s,setSearchQuery:u,isSearchFocused:h,setIsSearchFocused:f,dataSource:ce,setDataSource:q,viewType:te,setViewType:ve,layerOptions:tg,layerOpacity:ue,setLayerOpacity:ge,layerEnabled:z,setLayerEnabled:W,setMarkerType:be,setPawStatus:Ae,markerTypeOptions:se,pawStatusOptions:he,showMarkers:b,setShowMarkers:x,plots:C||[],markers:w||[],onAddFarm:Y,onAddPlot:xe,onAddStation:pe,searchResults:Me,onSearchResultClick:ye,onFarmsChange:Z})}function IUe({togglePanel:e,activePanel:t,selectedFarm:r,farmOpen:n,setFarmOpen:i,farms:a,handleFarmSelect:o,markerType:s,pawStatus:u,formatLabel:h,searchQuery:f,setSearchQuery:m,isSearchFocused:g,setIsSearchFocused:v,dataSource:b,setDataSource:x,viewType:w,setViewType:T,layerOptions:C=[],layerOpacity:M=[100],setLayerOpacity:O,layerEnabled:P=!0,setLayerEnabled:k,setMarkerType:D,setPawStatus:V,markerTypeOptions:U=[],pawStatusOptions:X=[],showMarkers:z=!0,setShowMarkers:W,plots:H=[],markers:G=[],onAddFarm:B,onAddPlot:Z,onAddStation:Q,onFarmsChange:ae,searchResults:oe=[],onSearchResultClick:te}){j.useContext(qi);const ve=j.useRef(null),ce=AUe({enabled:g,handler:()=>{v(!1),ve.current&&ve.current.blur()},excludedSelectors:[],delay:100});return I.jsxs(I.Fragment,{children:[I.jsx("div",{className:"absolute top-2 sm:top-4 left-2 right-2 sm:left-auto sm:right-auto w-auto sm:w-full z-[1100] flex justify-center pointer-events-none",children:I.jsxs("div",{className:"bg-white/90 backdrop-blur-xl border border-white/50 shadow-sm rounded-md flex items-center pointer-events-auto w-full sm:w-auto max-w-full overflow-visible flex-wrap sm:flex-nowrap",children:[I.jsx(_r,{variant:"ghost",size:"icon",className:"w-9 h-9 sm:w-10 sm:h-10 rounded-l-md rounded-r-none text-muted-foreground hover:bg-white/50 hover:text-foreground shrink-0",onClick:()=>e("settings"),"aria-label":"Settings",children:I.jsx(jne,{className:"h-4 w-4 sm:h-5 sm:w-5"})}),I.jsx("div",{className:"w-px h-5 sm:h-6 bg-border hidden sm:!block"}),I.jsxs(_r,{variant:"ghost",className:"h-9 sm:h-10 px-2 sm:px-4 rounded-none flex items-center gap-1.5 sm:gap-3 hover:bg-white/50 text-foreground shrink-0",onClick:()=>e("layers"),children:[I.jsx(ug,{className:"h-3.5 w-3.5 sm:h-4 sm:w-4 text-muted-foreground shrink-0"}),I.jsxs("div",{className:"flex flex-col items-start leading-none hidden sm:flex",children:[I.jsx("span",{className:"text-[10px] font-bold text-muted-foreground uppercase tracking-wider",children:"Layer"}),I.jsxs("span",{className:"text-xs font-bold whitespace-nowrap",children:[(b==null?void 0:b.label)||"Evapo"," ",I.jsxs("span",{className:"text-muted-foreground font-normal",children:["• ",w==="plot"?"Plot View":"Map View"]})]})]}),I.jsx(Jl,{className:"h-3 w-3 text-muted-foreground ml-1 shrink-0 hidden sm:!block"})]}),I.jsx("div",{className:"w-px h-5 sm:h-6 bg-border hidden sm:!block"}),I.jsxs(_r,{variant:"ghost",className:"h-9 sm:h-10 px-2 sm:px-4 rounded-none flex items-center gap-1.5 sm:gap-3 hover:bg-white/50 text-foreground shrink-0",onClick:()=>e("stations"),children:[I.jsx(Zv,{className:"h-3.5 w-3.5 sm:h-4 sm:w-4 text-muted-foreground shrink-0"}),I.jsxs("div",{className:"flex flex-col items-start leading-none hidden sm:flex",children:[I.jsx("span",{className:"text-[10px] font-bold text-muted-foreground uppercase tracking-wider",children:"Filter"}),I.jsxs("span",{className:"text-xs font-bold whitespace-nowrap",children:[h(s)," ",I.jsx("span",{className:"text-muted-foreground font-normal",children:"•"})," ",h(u)]})]}),I.jsx(Jl,{className:"h-3 w-3 text-muted-foreground ml-1 shrink-0 hidden sm:!block"})]}),I.jsx("div",{className:"w-px h-5 sm:h-6 bg-border hidden sm:!block"}),I.jsx(TUe,{selectedFarm:r,farmOpen:n,setFarmOpen:i,farms:a,handleFarmSelect:o,onAddFarm:B}),I.jsx("div",{className:"w-px h-5 sm:h-6 bg-border hidden sm:!block"}),I.jsxs("div",{ref:ce,"data-search-container":!0,className:"relative flex-1 sm:flex-none min-w-0 overflow-visible",children:[I.jsxs("div",{className:rr("flex items-center gap-2 px-2 sm:px-3 h-9 sm:h-10 rounded-r-md transition-all duration-300",g?"w-full sm:w-64 bg-white":"w-full sm:w-40 hover:bg-white/50"),children:[I.jsx(mh,{className:"h-3.5 w-3.5 sm:h-4 sm:w-4 text-muted-foreground shrink-0"}),I.jsx(Zo,{ref:ve,type:"text",placeholder:"Search...",value:f,onChange:q=>m(q.target.value),onFocus:()=>v(!0),className:"bg-transparent border-none focus-visible:ring-0 focus-visible:ring-offset-0 focus-visible:shadow-none text-xs sm:text-sm h-full placeholder:text-muted-foreground/70 px-0 w-full min-w-0"})]}),I.jsx(FGe,{isSearchFocused:g,searchQuery:f,searchResults:oe,onResultClick:te})]})]})}),I.jsx(JWe,{activePanel:t,togglePanel:e,viewType:w,setViewType:T,dataSource:b,setDataSource:x,layerOptions:C,layerOpacity:M,setLayerOpacity:O,layerEnabled:P,setLayerEnabled:k}),I.jsx(rUe,{activePanel:t,togglePanel:e,markerType:s,setMarkerType:D,pawStatus:u,setPawStatus:V,markerTypeOptions:U,pawStatusOptions:X,showMarkers:z,setShowMarkers:W,formatLabel:h}),I.jsx(CUe,{activePanel:t,togglePanel:e,farms:a,plots:H,markers:G,formatLabel:h,onAddFarm:B,onAddPlot:Z,onAddStation:Q,onFarmsChange:ae})]})}const BU=ie.forwardRef(({className:e,value:t,...r},n)=>{const i=Math.min(Math.max(t||0,0),100);return I.jsx("div",{ref:n,className:rr("relative h-4 w-full overflow-hidden rounded-full bg-secondary",e),...r,children:I.jsx("div",{className:"h-full bg-primary transition-all",style:{width:`${i}%`}})})});BU.displayName="Progress";function PUe(e){return j.useMemo(()=>{if(!e)return null;const t=e.stopped||0,r=e.running||0,n=e.pending||0,i=e.failed||0,a=t+r+n+i;if(a===0)return null;const o=t,s=a,u=o/s*100,h=Math.max(0,s-o),f=o>=s,m=(r>0||n>0)&&!f;return{daysGenerated:o,totalDays:s,percentage:u,daysRemaining:h,isComplete:f,isGenerating:m}},[e])}function OUe({className:e,loading:t,tasksStats:r}){const n=PUe(r);if(t)return I.jsx("div",{className:rr("bg-card/95 backdrop-blur-sm border border-border rounded-lg shadow-lg p-2 sm:p-3 min-w-[200px] sm:min-w-[280px] max-w-[calc(100vw-2rem)]",e),children:I.jsx("div",{className:"space-y-1.5 sm:space-y-2",children:I.jsxs("div",{className:"flex items-center gap-1.5 sm:gap-2",children:[I.jsx("div",{className:"w-1.5 h-1.5 sm:w-2 sm:h-2 rounded-full bg-muted-foreground animate-pulse flex-shrink-0"}),I.jsx("span",{className:"text-xs sm:text-sm font-medium text-foreground truncate",children:"Loading ET Data..."})]})})});if(!n)return I.jsx("div",{className:rr("bg-card/95 backdrop-blur-sm border border-border rounded-lg shadow-lg p-2 sm:p-3 min-w-[200px] sm:min-w-[280px] max-w-[calc(100vw-2rem)]",e),children:I.jsx("div",{className:"space-y-1.5 sm:space-y-2",children:I.jsxs("div",{className:"flex items-center gap-1.5 sm:gap-2",children:[I.jsx("div",{className:"w-1.5 h-1.5 sm:w-2 sm:h-2 rounded-full bg-chart-1 animate-pulse flex-shrink-0"}),I.jsx("span",{className:"text-xs sm:text-sm font-medium text-foreground truncate",children:"Generating ET Data"})]})})});const{daysGenerated:i,totalDays:a,percentage:o,daysRemaining:s,isComplete:u,isGenerating:h}=n;return I.jsx("div",{className:rr("bg-card/95 backdrop-blur-sm border border-border rounded-lg shadow-lg p-2 sm:p-3 min-w-[200px] sm:min-w-[280px] max-w-[calc(100vw-2rem)]",e),children:I.jsxs("div",{className:"space-y-1.5 sm:space-y-2",children:[I.jsx("div",{className:"flex items-center justify-between gap-1.5 sm:gap-2",children:I.jsxs("div",{className:"flex items-center gap-1.5 sm:gap-2 min-w-0 flex-1",children:[I.jsx("div",{className:rr("w-1.5 h-1.5 sm:w-2 sm:h-2 rounded-full flex-shrink-0",h?"bg-chart-1 animate-pulse":"bg-green-500")}),I.jsx("span",{className:"text-xs sm:text-sm font-medium text-foreground truncate",children:h?"Generating ET Data":"ET Data Ready"})]})}),I.jsx(BU,{value:o,className:"h-1.5 sm:h-2"}),I.jsxs("div",{className:"flex items-center justify-between gap-2 text-[10px] sm:text-xs",children:[I.jsxs("span",{className:"text-muted-foreground truncate",children:[i," of ",a," days"]}),I.jsx("span",{className:rr("font-medium flex-shrink-0",u?"text-green-500":"text-chart-1"),children:u?"100%":s>0?`${s} remaining`:`${Math.round(o)}%`})]})]})})}function kUe({className:e,mapRef:t}){const n=zt(v=>v.hoveredFarmId),{farms:i}=j.useContext(yu)||{},[a,o]=j.useState(null),[s,u]=j.useState(!1),h=j.useRef(null),f=j.useRef(null),m=j.useCallback(()=>{var X;if(!(t!=null&&t.current)||!n||!i||i.length===0)return!1;const v=t.current.getMap();if(!v||v.getZoom()<10)return!1;const x=v.getBounds();if(!x)return!1;const w=i.find(z=>(z==null?void 0:z.id)===n);if(!((X=w==null?void 0:w.options)!=null&&X.geometry))return!1;const T=Zl(w.options.geometry),[C,M,O,P]=T,[[k,D],[V,U]]=x.toArray();return C>=k&&O<=V&&M>=D&&P<=U},[t,n,i]),g=j.useCallback(()=>{if(f.current&&(clearTimeout(f.current),f.current=null),!n){o(null),u(!1),h.current=null;return}if(!m()){o(null),u(!1),h.current=null;return}n!==h.current&&(f.current=setTimeout(()=>{n!==h.current&&m()&&(h.current=n,u(!0),lC(n).then(v=>{h.current===n&&m()&&o(v)}).catch(v=>{h.current===n&&o(null)}).finally(()=>{h.current===n&&u(!1)}))},300))},[n,m]);return j.useEffect(()=>(g(),()=>{f.current&&(clearTimeout(f.current),f.current=null)}),[g]),j.useEffect(()=>{if(!(t!=null&&t.current)||!n)return;const v=t.current.getMap();if(!v)return;let b;const x=()=>{clearTimeout(b),b=setTimeout(()=>{g()},200)};return v.on("moveend",x),v.on("zoomend",x),()=>{clearTimeout(b),v.off("moveend",x),v.off("zoomend",x)}},[t,n,g]),j.useEffect(()=>{if(!n||!a||!m()||!((a.running||0)>0||(a.pending||0)>0))return;const b=setInterval(()=>{m()&&lC(n).then(x=>{m()&&o(x)}).catch(x=>{})},5e3);return()=>{clearInterval(b)}},[n,a,t,i,m]),n?I.jsx(OUe,{className:e,loading:s,tasksStats:a}):null}const $U=(e,t)=>{var n;return`${(n=RQ.find(i=>i.id===e))==null?void 0:n.url}?key=${t}`},zU=e=>{j.useEffect(()=>{if(!(e!=null&&e.current))return;const t=e.current.getMap();if(!(t!=null&&t.scrollZoom))return;const r=()=>{t.scrollZoom&&t.scrollZoom.disable()};return t.loaded()?r():t.once("load",r),()=>{t&&t.off("load",r)}},[e])},VU=e=>r=>{e(r?{start:r,end:r}:{start:void 0,end:void 0})};function DUe({style:e,configs:t}){const{settings:r}=j.useContext(rg),{mapRef:n,mapContainerRef:i}=j.useContext(qi),a=j.useRef(),o=QQ(),[s,u]=j.useState(o),h=zt(W=>W.viewMode),f=zt(W=>W.mapMode),m=zt(W=>W.cursor),g=zt(W=>W.setConfigs);zt(W=>W.sidebarExpanded),z0();const v=zt(W=>W.showCroppedImages),b=zt(W=>W.dateRange),x=zt(W=>W.setDateRange),w=zt(W=>W.dateRange2),T=zt(W=>W.setDateRange2),C=j.useCallback(W=>u(W.viewState),[]),M=j.useRef(null),O=j.useCallback(W=>{M.current&&clearTimeout(M.current),M.current=setTimeout(()=>{try{F2("map-viewport",W)}catch{}},1e3)},[]);j.useEffect(()=>{try{const W=YO("map-viewport");W&&u(W)}catch{}},[]),j.useEffect(()=>()=>{M.current&&clearTimeout(M.current)},[]);const P=j.useCallback(W=>{O(W.viewState)},[O]),k=j.useCallback(W=>{O(W.viewState)},[O]);j.useEffect(()=>{if(f)try{Ld("map-mode",f)}catch{}},[f]);const D=j.useMemo(()=>VU(x),[x]),V=j.useMemo(()=>VU(T),[T]),[U,X]=j.useState($U(r.basemap.id,t==null?void 0:t.VITE_MAPTILER_ACCESS_KEY));j.useEffect(()=>{X($U(r.basemap.id,t==null?void 0:t.VITE_MAPTILER_ACCESS_KEY))},[r]),j.useEffect(()=>{g(t)},[]),j.useEffect(()=>{},[b,w]),zU(n),zU(a);const z=j.useMemo(()=>({initialViewState:o,...s,onMove:C,onMoveEnd:P,onZoomEnd:k,style:{width:"100%",...e},mapStyle:typeof U=="string"?U:U.toJS(),attributionControl:!1,reuseMaps:!0,preserveDrawingBuffer:!0,cursor:m,scrollZoom:!1}),[o,s,C,P,k,e,U,m]);return o?I.jsx(zFe,{children:I.jsxs("div",{ref:i,style:{width:"100%",height:"80vh"},className:"flex flex-row relative",children:[I.jsxs(mD,{id:"myMap",ref:n,...z,children:[!v&&I.jsx(_W,{mapRef:n,dateRange:b}),f==Ds.NORMAL&&I.jsx(MUe,{mapRef:n}),f==Ds.NORMAL&&I.jsx("div",{className:"absolute top-16 sm:top-4 left-2 sm:left-4 right-2 sm:right-auto z-[1200] pointer-events-none",children:I.jsx("div",{className:"pointer-events-auto flex flex-col sm:flex-row gap-2 justify-start",children:I.jsx(kUe,{mapRef:n})})}),I.jsx("div",{className:"absolute top-0 left-0",children:f==Ds.COMPARISION_VIEW&&I.jsx(Ex,{compact:!0,onDateSelect:D,mapRef:n,dateRange:b,autoRefresh:!0,autoRefreshMinutes:5})}),f===Ds.NORMAL&&I.jsx(CW,{dateRange:b,mapRef:n}),f!==Ds.NORMAL&&I.jsx("div",{className:"absolute top-0 right-0 m-2",style:{zIndex:2},children:I.jsx(EW,{dateRange:b,mapRef:n,showButton:!1})}),h!==Xr.PICKER&&I.jsx("div",{className:"absolute bottom-4 left-4",style:{zIndex:3},children:I.jsx(_Fe,{})}),I.jsxs("div",{className:"absolute bottom-20 right-4 lg:bottom-4 lg:right-20 flex flex-col gap-4 items-end",style:{zIndex:10},children:[I.jsx(MW,{mapRef:n}),I.jsx("div",{className:"hidden lg:block",children:I.jsx(wW,{})})]}),I.jsx("div",{className:"absolute bottom-16 left-0 right-0 flex justify-center lg:hidden",style:{zIndex:10},children:I.jsx(wW,{})}),I.jsx("div",{className:"absolute bottom-4 left-0 right-0 flex justify-center items-center",style:{zIndex:3},children:I.jsx(dle,{mapRef:n,configs:t,onDateSelect:D})}),I.jsx(H7e,{}),h==Xr.EDIT_PLOT&&I.jsx(_Ge,{}),h==Xr.ADD_PLOT&&I.jsx(wGe,{}),h==Xr.ADD_MARKER&&I.jsx(SGe,{}),h==Xr.ADD_NEW_FARM&&I.jsx(EGe,{}),I.jsx($le,{}),I.jsx(Dme,{}),I.jsx(l7e,{mapRef:n}),I.jsx(R$,{mapRef:n,dateRange:b}),I.jsx(X7e,{}),I.jsx(TGe,{})]}),f===Ds.COMPARISION_VIEW&&I.jsxs(mD,{id:"myMap2",ref:a,...z,children:[!v&&I.jsx(_W,{mapRef:a,dateRange:w}),I.jsx("div",{className:"absolute top-0 left-0",children:I.jsx(Ex,{compact:!0,onDateSelect:V,mapRef:a,dateRange:w})}),I.jsx(CW,{dateRange:w,mapRef:a}),I.jsx("div",{className:"absolute bottom-4 right-20 flex flex-col gap-4 items-end",style:{zIndex:3},children:I.jsx(MW,{mapRef:a})}),I.jsx(R$,{mapRef:a,dateRange:w})]}),I.jsx(vGe,{})]})}):I.jsx(Ja,{})}var NUe={},GU={};(function(e){function t(T){"@babel/helpers - typeof";return t=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(C){return typeof C}:function(C){return C&&typeof Symbol=="function"&&C.constructor===Symbol&&C!==Symbol.prototype?"symbol":typeof C},t(T)}Object.defineProperty(e,"__esModule",{value:!0}),e.default=void 0;var r=a(j),n=["dispose","reject","resolve"];function i(T){if(typeof WeakMap!="function")return null;var C=new WeakMap,M=new WeakMap;return(i=function(P){return P?M:C})(T)}function a(T,C){if(T&&T.__esModule)return T;if(T===null||t(T)!=="object"&&typeof T!="function")return{default:T};var M=i(C);if(M&&M.has(T))return M.get(T);var O={},P=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var k in T)if(k!=="default"&&Object.prototype.hasOwnProperty.call(T,k)){var D=P?Object.getOwnPropertyDescriptor(T,k):null;D&&(D.get||D.set)?Object.defineProperty(O,k,D):O[k]=T[k]}return O.default=T,M&&M.set(T,O),O}function o(){return o=Object.assign||function(T){for(var C=1;C<arguments.length;C++){var M=arguments[C];for(var O in M)Object.prototype.hasOwnProperty.call(M,O)&&(T[O]=M[O])}return T},o.apply(this,arguments)}function s(T,C){return g(T)||m(T,C)||h(T,C)||u()}function u(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
1334
1334
  In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function h(T,C){if(T){if(typeof T=="string")return f(T,C);var M=Object.prototype.toString.call(T).slice(8,-1);if(M==="Object"&&T.constructor&&(M=T.constructor.name),M==="Map"||M==="Set")return Array.from(T);if(M==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(M))return f(T,C)}}function f(T,C){(C==null||C>T.length)&&(C=T.length);for(var M=0,O=new Array(C);M<C;M++)O[M]=T[M];return O}function m(T,C){var M=T==null?null:typeof Symbol<"u"&&T[Symbol.iterator]||T["@@iterator"];if(M!=null){var O=[],P=!0,k=!1,D,V;try{for(M=M.call(T);!(P=(D=M.next()).done)&&(O.push(D.value),!(C&&O.length===C));P=!0);}catch(U){k=!0,V=U}finally{try{!P&&M.return!=null&&M.return()}finally{if(k)throw V}}return O}}function g(T){if(Array.isArray(T))return T}function v(T,C){if(T==null)return{};var M=b(T,C),O,P;if(Object.getOwnPropertySymbols){var k=Object.getOwnPropertySymbols(T);for(P=0;P<k.length;P++)O=k[P],!(C.indexOf(O)>=0)&&Object.prototype.propertyIsEnumerable.call(T,O)&&(M[O]=T[O])}return M}function b(T,C){if(T==null)return{};var M={},O=Object.keys(T),P,k;for(k=0;k<O.length;k++)P=O[k],!(C.indexOf(P)>=0)&&(M[P]=T[P]);return M}var x=function(C){return function(M){var O=M.dispose,P=M.reject,k=M.resolve,D=v(M,n),V=(0,r.useState)(!0),U=s(V,2),X=U[0],z=U[1],W=function(){z(!1),O()},H=function(Z){z(!1),P(Z)},G=function(Z){z(!1),k(Z)};return r.default.createElement(C,o({cancel:H,dismiss:W,proceed:G,show:X},D))}},w=x;e.default=w})(GU);var WU={},fw={},by={},_y=Ma;if(process.env.NODE_ENV==="production")by.createRoot=_y.createRoot,by.hydrateRoot=_y.hydrateRoot;else{var pw=_y.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;by.createRoot=function(e,t){pw.usingClientEntryPoint=!0;try{return _y.createRoot(e,t)}finally{pw.usingClientEntryPoint=!1}},by.hydrateRoot=function(e,t,r){pw.usingClientEntryPoint=!0;try{return _y.hydrateRoot(e,t,r)}finally{pw.usingClientEntryPoint=!1}}}Object.defineProperty(fw,"__esModule",{value:!0}),fw.createDomTreeMounter=jUe;var LUe=RUe(j),FUe=by;function RUe(e){return e&&e.__esModule?e:{default:e}}function jUe(e){var t={},r={};function n(a,o,s){var u=Math.floor(Math.random()*1073741824).toString(16),h=(s||e||document.body).appendChild(document.createElement("div"));t[u]=h;var f=(0,FUe.createRoot)(h);return f.render(LUe.default.createElement(a,o)),r.mounted&&r.mounted(),u}function i(a){var o=t[a];delete t[a],o&&o.parentNode&&o.parentNode.removeChild(o)}return{mount:n,unmount:i,options:{}}}(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.default=e.createConfirmationCreater=void 0;var t=fw;function r(s,u){var h=Object.keys(s);if(Object.getOwnPropertySymbols){var f=Object.getOwnPropertySymbols(s);u&&(f=f.filter(function(m){return Object.getOwnPropertyDescriptor(s,m).enumerable})),h.push.apply(h,f)}return h}function n(s){for(var u=1;u<arguments.length;u++){var h=arguments[u]!=null?arguments[u]:{};u%2?r(Object(h),!0).forEach(function(f){i(s,f,h[f])}):Object.getOwnPropertyDescriptors?Object.defineProperties(s,Object.getOwnPropertyDescriptors(h)):r(Object(h)).forEach(function(f){Object.defineProperty(s,f,Object.getOwnPropertyDescriptor(h,f))})}return s}function i(s,u,h){return u in s?Object.defineProperty(s,u,{value:h,enumerable:!0,configurable:!0,writable:!0}):s[u]=h,s}var a=function(u){return function(h){var f=arguments.length>1&&arguments[1]!==void 0?arguments[1]:1e3,m=arguments.length>2?arguments[2]:void 0;return function(g){var v,b=new Promise(function(w,T){try{v=u.mount(h,n({reject:T,resolve:w,dispose:x},g),m)}catch(C){throw C}});function x(){setTimeout(function(){u.unmount(v)},f)}return b.then(function(w){return x(),w},function(w){return x(),Promise.reject(w)})}}};e.createConfirmationCreater=a;var o=a((0,t.createDomTreeMounter)());e.default=o})(WU);var mw={};function fP(e){"@babel/helpers - typeof";return fP=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},fP(e)}Object.defineProperty(mw,"__esModule",{value:!0}),mw.createMountPoint=ZUe,mw.createReactTreeMounter=YUe;var wy=$Ue(j),BUe=Ma;function UU(e){if(typeof WeakMap!="function")return null;var t=new WeakMap,r=new WeakMap;return(UU=function(i){return i?r:t})(e)}function $Ue(e,t){if(e&&e.__esModule)return e;if(e===null||fP(e)!=="object"&&typeof e!="function")return{default:e};var r=UU(t);if(r&&r.has(e))return r.get(e);var n={},i=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var a in e)if(a!=="default"&&Object.prototype.hasOwnProperty.call(e,a)){var o=i?Object.getOwnPropertyDescriptor(e,a):null;o&&(o.get||o.set)?Object.defineProperty(n,a,o):n[a]=e[a]}return n.default=e,r&&r.set(e,n),n}function pP(){return pP=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},pP.apply(this,arguments)}function HU(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(i){return Object.getOwnPropertyDescriptor(e,i).enumerable})),r.push.apply(r,n)}return r}function zUe(e){for(var t=1;t<arguments.length;t++){var r=arguments[t]!=null?arguments[t]:{};t%2?HU(Object(r),!0).forEach(function(n){VUe(e,n,r[n])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):HU(Object(r)).forEach(function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(r,n))})}return e}function VUe(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function GUe(e,t){return XUe(e)||HUe(e,t)||UUe(e,t)||WUe()}function WUe(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
1335
1335
  In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function UUe(e,t){if(e){if(typeof e=="string")return XU(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);if(r==="Object"&&e.constructor&&(r=e.constructor.name),r==="Map"||r==="Set")return Array.from(e);if(r==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return XU(e,t)}}function XU(e,t){(t==null||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function HUe(e,t){var r=e==null?null:typeof Symbol<"u"&&e[Symbol.iterator]||e["@@iterator"];if(r!=null){var n=[],i=!0,a=!1,o,s;try{for(r=r.call(e);!(i=(o=r.next()).done)&&(n.push(o.value),!(t&&n.length===t));i=!0);}catch(u){a=!0,s=u}finally{try{!i&&r.return!=null&&r.return()}finally{if(a)throw s}}return n}}function XUe(e){if(Array.isArray(e))return e}function YUe(e){var t={},r={};function n(o,s){var u=Math.floor(Math.random()*1073741824).toString(16);return t[u]={Component:o,props:s},r.mounted&&r.mounted(t),u}function i(o){delete t[o],r.mounted&&r.mounted(t)}function a(o){r.mounted=o}return{mount:n,unmount:i,options:{setMountedCallback:a,mountNode:e}}}function ZUe(e){return function(){var t=(0,wy.useState)({}),r=GUe(t,2),n=r[0],i=r[1];(0,wy.useEffect)(function(){return e.options.setMountedCallback(function(o){i(zUe({},o))})},[]);var a=wy.default.createElement(wy.default.Fragment,null,Object.keys(n).map(function(o){var s=n[o],u=s.Component,h=s.props;return wy.default.createElement(u,pP({key:o},h))}));return e.options.mountNode&&(a=(0,BUe.createPortal)(a,e.options.mountNode)),a}}(function(e){function t(h){"@babel/helpers - typeof";return t=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(f){return typeof f}:function(f){return f&&typeof Symbol=="function"&&f.constructor===Symbol&&f!==Symbol.prototype?"symbol":typeof f},t(h)}Object.defineProperty(e,"__esModule",{value:!0}),Object.defineProperty(e,"confirmable",{enumerable:!0,get:function(){return r.default}}),Object.defineProperty(e,"createConfirmation",{enumerable:!0,get:function(){return n.default}}),Object.defineProperty(e,"createConfirmationCreater",{enumerable:!0,get:function(){return n.createConfirmationCreater}}),Object.defineProperty(e,"createDomTreeMounter",{enumerable:!0,get:function(){return i.createDomTreeMounter}}),Object.defineProperty(e,"createMountPoint",{enumerable:!0,get:function(){return a.createMountPoint}}),Object.defineProperty(e,"createReactTreeMounter",{enumerable:!0,get:function(){return a.createReactTreeMounter}});var r=u(GU),n=s(WU),i=fw,a=mw;function o(h){if(typeof WeakMap!="function")return null;var f=new WeakMap,m=new WeakMap;return(o=function(v){return v?m:f})(h)}function s(h,f){if(h.__esModule)return h;if(h===null||t(h)!=="object"&&typeof h!="function")return{default:h};var m=o(f);if(m&&m.has(h))return m.get(h);var g={},v=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var b in h)if(b!=="default"&&Object.prototype.hasOwnProperty.call(h,b)){var x=v?Object.getOwnPropertyDescriptor(h,b):null;x&&(x.get||x.set)?Object.defineProperty(g,b,x):g[b]=h[b]}return g.default=h,m&&m.set(h,g),g}function u(h){return h&&h.__esModule?h:{default:h}}})(NUe);const qUe=j.forwardRef(({onClose:e,...t},r)=>I.jsx(_r,{ref:r,variant:"outline",size:"icon",onClick:e,...t,children:I.jsx(gs,{className:"w-5 h-5 action-icon"})})),YU=()=>{const{prompt:e="",isOpen:t=!0,proceed:r,cancel:n}=h1(),i=()=>{n()};return I.jsx(Tg,{open:t,onOpenChange:a=>{a||i()},children:I.jsxs(Ag,{children:[I.jsx(vf,{className:"fixed inset-0 bg-black opacity-30 z-[12100]"}),I.jsxs(xf,{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-[12101]",children:[I.jsx(ac,{className:"text-lg font-bold dark:text-gray-200",children:"Warning"}),I.jsx(wh,{className:"mt-2 text-sm text-gray-600 dark:text-gray-200",children:e}),I.jsxs("div",{className:"mt-4 flex justify-end space-x-2",children:[I.jsx(_r,{variant:"outline",onClick:n,children:"Cancel"}),I.jsx(_r,{variant:"destructive",onClick:()=>r(!0),children:"delete"})]}),I.jsx(bf,{asChild:!0,children:I.jsx(qUe,{className:"absolute top-2 right-2"})})]})]})})};YU.propTypes={show:Ft.bool,proceed:Ft.func,confirmation:Ft.string,options:Ft.object};const KUe=j.createContext();function JUe({children:e,defaultTheme:t="system",storageKey:r="vite-ui-theme",...n}){const[i,a]=j.useState(()=>Dm(r)||t);j.useEffect(()=>{const s=document.documentElement;s.classList.remove("light","dark"),i==="system"&&s&&window.matchMedia("(prefers-color-scheme: dark)").matches,s.classList.add("light")},[i]),j.useEffect(()=>{const s=window.matchMedia("(prefers-color-scheme: dark)"),u=()=>a(s.matches?"dark":"light");return u(),s.addEventListener("change",u),()=>s.removeEventListener("change",u)},[]);const o={theme:"light",setTheme:s=>{Ld(r,s),a(s)}};return I.jsx(KUe.Provider,{value:o,...n,children:e})}var QUe=(e,t,r,n,i,a,o,s)=>{let u=document.documentElement,h=["light","dark"];function f(v){(Array.isArray(e)?e:[e]).forEach(b=>{let x=b==="class",w=x&&a?i.map(T=>a[T]||T):i;x?(u.classList.remove(...w),u.classList.add(v)):u.setAttribute(b,v)}),m(v)}function m(v){s&&h.includes(v)&&(u.style.colorScheme=v)}function g(){return window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}if(n)f(n);else try{let v=localStorage.getItem(t)||r,b=o&&v==="system"?g():v;f(b)}catch{}},eHe=ie.createContext(void 0),tHe={setTheme:e=>{},themes:[]},rHe=()=>{var e;return(e=ie.useContext(eHe))!=null?e:tHe};ie.memo(({forcedTheme:e,storageKey:t,attribute:r,enableSystem:n,enableColorScheme:i,defaultTheme:a,value:o,themes:s,nonce:u,scriptProps:h})=>{let f=JSON.stringify([r,t,a,e,s,o,n,i]).slice(1,-1);return ie.createElement("script",{...h,suppressHydrationWarning:!0,nonce:typeof window>"u"?u:"",dangerouslySetInnerHTML:{__html:`(${QUe.toString()})(${f})`}})});const nHe=({...e})=>{const{theme:t="system"}=rHe();return I.jsx(Che,{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 iHe(e,t){if(Object.is(e,t))return!0;if(typeof e!="object"||e===null||typeof t!="object"||t===null)return!1;if(e instanceof Map&&t instanceof Map){if(e.size!==t.size)return!1;for(const[n,i]of e)if(!Object.is(i,t.get(n)))return!1;return!0}if(e instanceof Set&&t instanceof Set){if(e.size!==t.size)return!1;for(const n of e)if(!t.has(n))return!1;return!0}const r=Object.keys(e);if(r.length!==Object.keys(t).length)return!1;for(const n of r)if(!Object.prototype.hasOwnProperty.call(t,n)||!Object.is(e[n],t[n]))return!1;return!0}const{useRef:aHe}=j;function ZU(e){const t=aHe();return r=>{const n=e(r);return iHe(t.current,n)?t.current:t.current=n}}const sHe=()=>{try{return YO("agviewer_user_preferences")}catch{return{}}};function oHe(){const[e,t]=j.useState(!1),r=j.useRef(!1),n=j.useRef(null),i=j.useContext(yp),a=(i==null?void 0:i.isVisible)??!1,o=i==null?void 0:i.setIsVisible,s=zt(ZU(Z=>({setRasterOpacity:Z.setRasterOpacity,setRasterLayer:Z.setRasterLayer,setViewMode:Z.setViewMode,setShowCroppedImages:Z.setShowCroppedImages,setDateRange:Z.setDateRange,setSidebarExpanded:Z.setSidebarExpanded}))),u=zt(ZU(Z=>({rasterOpacity:Z.rasterOpacity,rasterLayer:Z.rasterLayer,viewMode:Z.viewMode,showCroppedImages:Z.showCroppedImages,dateRange:Z.dateRange,sidebarExpanded:Z.sidebarExpanded}))),{setRasterOpacity:h,setRasterLayer:f,setViewMode:m,setShowCroppedImages:g,setDateRange:v,setSidebarExpanded:b}=s,{rasterOpacity:x,rasterLayer:w,viewMode:T,showCroppedImages:C,dateRange:M,sidebarExpanded:O}=u,P=j.useContext(ys),k=j.useContext(xs),D=(P==null?void 0:P.showMarkers)??!0,V=P==null?void 0:P.setShowMarkers,U=(P==null?void 0:P.markerFilters)??{},X=P==null?void 0:P.setMarkerFilters,z=(k==null?void 0:k.showPlots)??!0,W=k==null?void 0:k.setShowPlots,H=j.useMemo(()=>{const Z=JSON.stringify(U);return n.current!==null&&n.current===Z?n.current:(n.current=Z,Z)},[U]);return j.useEffect(()=>{if(!r.current){r.current=!0;try{const Z=sHe();if(Z&&(Z.isRasterVisible!==void 0&&o&&o(Z.isRasterVisible),Z.rasterOpacity!==void 0&&h&&h(Z.rasterOpacity),Z.rasterLayer!==void 0&&f&&f(Z.rasterLayer),Z.viewMode!==void 0&&m&&m(Z.viewMode),Z.showCroppedImages!==void 0&&g&&g(Z.showCroppedImages),Z.dateRange!==void 0&&v&&v(Z.dateRange),Z.sidebarExpanded!==void 0&&b&&b(Z.sidebarExpanded),Z.showMarkers!==void 0&&V&&V(Z.showMarkers),Z.showPlots!==void 0&&W&&W(Z.showPlots),Z.markerFilters!==void 0&&X)){const Q={type:Z.markerFilters.type||"",paw_status:Z.markerFilters.paw_status||"",farm_id:Z.markerFilters.farm_id||"",batteryLevel:Z.markerFilters.batteryLevel||null};X(Q)}}catch{}finally{t(!0)}}},[]),j.useEffect(()=>{if(e)try{F2("agviewer_user_preferences",{rasterOpacity:x,rasterLayer:w,viewMode:T,showCroppedImages:C,dateRange:M,sidebarExpanded:O,showMarkers:D,showPlots:z,isRasterVisible:a,markerFilters:U})}catch{}},[e,u,D,z,a,H]),{initialized:e,saveCurrentPreferences:()=>{try{return F2("agviewer_user_preferences",{rasterOpacity:x,rasterLayer:w,viewMode:T,showCroppedImages:C,dateRange:M,sidebarExpanded:O,showMarkers:D,showPlots:z,isRasterVisible:a,markerFilters:U}),!0}catch{return!1}},clearSavedPreferences:()=>{try{return L2("agviewer_user_preferences"),!0}catch{return!1}}}}const lHe=j.createContext();function qU({children:e}){const t=oHe();return I.jsx(lHe.Provider,{value:t,children:e})}qU.propTypes={children:Ft.node.isRequired};const cHe={"app.agviewer_map.name":"Name","app.agviewer_map.station_label":"Station (device)","app.agviewer_map.farm_label":"Farm","app.agviewer_map.paw_graphs_label":"Paw Graphs","app.agviewer_map.more_graphs_label":"More Graphs","app.agviewer_map.latitude_label":"Latitude","app.agviewer_map.longitude_label":"Longitude","app.agviewer_map.diff_coords":"Use different coordinates","app.agviewer_map.use_custom_coordinates":"Use marker's coordinates","app.agviewer_map.cancel":"Cancel","app.agviewer_map.loading":"Loading...","app.agviewer_map.add_marker":"Add Marker","app.agviewer_map.all":"All","app.agviewer_map.optimal":"Optimal","app.agviewer_map.stress_start":"Stress Start","app.agviewer_map.severe_stress":"Severe Stress","app.agviewer_map.excess_water":"Excess Water","app.agviewer_map.stations":"Stations","app.agviewer_map.station":"Station","app.agviewer_map.forecast":"Forecast","app.agviewer_map.hide_markers":"Hide Markers","app.agviewer_map.show_markers":"Show Markers","app.agviewer_map.paw_status":"PAW Status","app.agviewer_map.select_status":"Select status","app.agviewer_map.farm":"Farm","app.agviewer_map.select_farm":"Select farm","app.agviewer_map.plots":"Plots","app.agviewer_map.hide_plots":"Hide Plots","app.agviewer_map.show_plots":"Show Plots","app.agviewer_map.delete_marker_confirm_message":"Do you want to delete this marker?","app.agviewer_map.find_station":"Find Station","app.agviewer_map.search_station":"Search Station","app.agviewer_map.focus_marker":"Focus on the marker","app.agviewer_map.delete_marker":"Delete Marker","app.agviewer_map.no_station_found":"No Station Found","app.agviewer_map.search_plots":"Search Plots","app.agviewer_map.focus_plot":"Focus on the plot","app.agviewer_map.delete_plot":"Delete plot","app.agviewer_map.no_plot_found":"No Plots Found for keyword:","app.agviewer_map.no_plots":"No Plots Available","app.agviewer_map.farm_success_message":"Farm Has been created successfully","app.agviewer_map.add_new_farm":"Add New Farm","app.agviewer_map.markers":"Markers","app.agviewer_map.add_farm":"Add Farm","app.agviewer_map.plot_success_message":"Plot created successfully","app.agviewer_map.plot_failed_message":"Could not create the plot","app.agviewer_map.add_new_plot":"Add New Plot","app.agviewer_map.create_plot":"Create Plot","app.agviewer_map.saving_changes":"Saving changes","app.agviewer_map.changes_saved_successfully":"Changes saved successfully","app.agviewer_map.edit_plot":"Edit plot","app.agviewer_map.save_changes":"Save Changes","app.agviewer_map.add_new_marker":"Add New Marker","app.agviewer_map.associated_device":"Associated Station (Device)","app.agviewer_map.sat_et":"Sat-ET","app.agviewer_map.disable_sat_et":"Disable Sat-ET","app.agviewer_map.enable_sat_et":"Enable Sat-ET","app.agviewer_map.change_shape":"Change Shape","app.agviewer_map.submitting":"Submitting...","app.agviewer_map.edit_marker":"Edit Marker","app.agviewer_map.change_view_mode":"Change view mode","app.agviewer_map.add_view_plot":"Add new plot","app.agviewer_map.add_new_station":"Add new station","app.agviewer_map.add_new_farm_title":"Add new farm","app.agviewer_map.restart_tour":"Restart User Guide","app.agviewer_map.date_selector":"Date Selector","app.agviewer_map.select_date":"Select Date","app.agviewer_map.available_days":"Available Days","app.agviewer_map.configurations":"Configurations","app.agviewer_map.raster_layer":"Raster Layer","app.agviewer_map.plot":"Plot","app.agviewer_map.map":"Map","app.agviewer_map.hide_layer":"Hide Layer","app.agviewer_map.show_layer":"Show Layer","app.agviewer_map.opacity":"Opacity","app.agviewer_map.layer_type":"Layer Type","app.agviewer_map.or_select_from_list":"OR SELECT FROM LIST","app.agviewer_map.plot_task_status":"Click the info icon or plot area to view the plot and task status for {plotName}.","app.agviewer_map.activate_picker_mode":"Activate picker mode","app.agviewer_map.plot_deletion_confirm_message":"Do you want to delete this plot?","app.agviewer_map.delete":"Delete","app.agviewer_map.close":"Close","app.agviewer_map.area":"Area ({unit})","app.agviewer_map.sat-et":"SAT-ET","app.agviewer_map.battery":"Battery","app.agviewer_map.avg_paw":"Average PAW","app.agviewer_map.crop":"Crop","app.agviewer_map.min":"min","app.agviewer_map.max":"max","app.agviewer_map.avg":"avg","app.agviewer_map.water":"water","app.agviewer_map.bare_soil":"Bare Soil","app.agviewer_map.low_vegetation":"Low Vegetation","app.agviewer_map.moderate_vegetation":"Moderate Vegetation","app.agviewer_map.healthy_vegetation":"Healthy Vegetation","app.agviewer_map.very_healthy_vegetation":"Very Healthy Vegetation","app.agviewer_map.dense_vegetation":"Dense Vegetation","app.agviewer_map.water_bodies":"Water Bodies","app.agviewer_map.sparse_vegetation":"Sparse Vegetation","app.agviewer_map.light_vegetation":"light veg","app.agviewer_map.irrigated":"irrigated","app.agviewer_map.very_low_et":"very low ET","app.agviewer_map.low_et":"low ET","app.agviewer_map.moderate_et":"moderate ET","app.agviewer_map.high_et":"high ET","app.agviewer_map.very_high_et":"very high ET","app.agviewer_map.ndvi":"NDVI","app.agviewer_map.evapotranspiration":"Evapotranspiration","app.agviewer_map.avg_et":"Avg ET","app.agviewer_map.avg_et_eto":"Avg ET + ETo","app.agviewer_map.min_et":"Min ET","app.agviewer_map.max_et":"Max ET","app.agviewer_map.std_dev":"StdDev","app.agviewer_map.eto_only":"ETo Only (Max ET)","app.agviewer_map.no_et_data_available":"No ET data available for selected date range","app.agviewer_map.very_dry":"Very Dry","app.agviewer_map.dry":"Dry","app.agviewer_map.moderate_moisture":"Moderate Moisture","app.agviewer_map.high_moisture":"High Moisture","app.agviewer_map.very_high_moisture":"Very High Moisture","app.agviewer_map.saturated":"Saturated","app.agviewer_map.water_body":"Water Body","app.agviewer_map.very_low":"Very Low","app.agviewer_map.low":"Low","app.agviewer_map.moderate":"Moderate","app.agviewer_map.high":"High","app.agviewer_map.very_high":"Very High","app.datelist.today":"Today","app.datelist.loading_more":"Loading more dates...","app.datelist.selected":"Selected:","app.agviewer_map.time_period":"Time Period:","app.agviewer_map.time_period_daily":"Daily","app.agviewer_map.time_period_weekly":"Weekly","app.agviewer_map.time_period_monthly":"Monthly"};function uHe({children:e}){let t=!0;try{Kn()}catch{t=!1}return t?e:I.jsx(_ne,{locale:"en",messages:cHe,children:e})}function KU({style:e,configs:t,markers:r,authToken:n}){return t&&(globalThis.__AGV_CONFIGS=t),j.useEffect(()=>{n&&YQ({Authorization:n})},[n]),I.jsx(O$,{children:I.jsx(uHe,{children:I.jsx(JUe,{defaultTheme:"light",children:I.jsx(uue,{delayDuration:200,children:I.jsx(eee,{children:I.jsx(kme,{children:I.jsx(aD,{children:I.jsx(VFe,{children:I.jsx(u5,{children:I.jsx(h5,{children:I.jsx(E4,{providedMarkers:r,children:I.jsx(qU,{children:I.jsxs(bU,{children:[I.jsx(DUe,{style:e,configs:t}),I.jsx(nHe,{richColors:!0}),I.jsx(YU,{})]})})})})})})})})})})})})})}KU.propTypes={style:Ft.object,configs:Ft.object,markers:Ft.array,authToken:Ft.string};const hHe=e=>I.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:20,height:20,viewBox:"0 0 20 20",fill:"none",...e,children:[I.jsx("path",{stroke:"#373737",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"m5.833 14.167 8.334-8.334"}),I.jsx("path",{stroke:"#000",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5.833 5.833h8.334v8.334"})]}),dHe=({marker:e,markerId:t,buttonClassName:r=""})=>{const[n,i]=j.useState(!1),{handleMarkerUpdate:a}=j.useContext(ys),o=Kn(),s=j.useCallback(()=>{i(h=>!h)},[]),u=h=>a(h);return I.jsx(Mg,{trigger:I.jsx(_r,{variant:"outline",size:"icon",tabIndex:-1,children:I.jsx($s,{text:o.formatMessage({id:"app.agviewer_map.edit_marker",defaultMessage:"Edit Marker"}),children:I.jsx(Ox,{className:"w-5 h-5 action-icon"})})}),title:o.formatMessage({id:"app.agviewer_map.edit_marker",defaultMessage:"Edit Marker"}),open:n,setOpen:i,headerClassName:"m-4",onClose:s,children:I.jsx(Gx,{children:I.jsx(DC,{marker:e,onSubmit:u,onCancel:s,submitButtonText:o.formatMessage({id:"app.agviewer_map.save_changes",defaultMessage:"Save Changes"})})})})},fHe=({marker:e,onMarkerClick:t,onDeleteMarker:r,markersData:n,intl:i})=>I.jsx("div",{className:"marker-item rounded-md hover:bg-gray-50 dark:hover:bg-gray-700 p-2 mb-2",children:I.jsx("div",{className:"marker-item-info",children:I.jsxs("div",{className:"flex justify-between items-center gap-2",children:[I.jsxs("div",{className:"flex items-center gap-2 flex-1 min-w-0",children:[I.jsx(Zv,{className:"h-4 w-4 text-primary flex-shrink-0"}),I.jsx("h5",{className:"text-sm font-medium text-gray-800 dark:text-gray-200 break-words leading-tight",children:e==null?void 0:e.title})]}),I.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[I.jsx($s,{text:i.formatMessage({id:"app.agviewer_map.focus_marker",defaultMessage:"Focus on the marker"}),children:I.jsx(Vx,{variant:"icon",className:"rounded-full p-1 hover:bg-gray-100 dark:hover:bg-gray-600",onClick:a=>t(a,e),"data-marker-id":e.id,children:I.jsx(hHe,{className:"w-4 h-4"})})}),I.jsx($s,{text:i.formatMessage({id:"app.agviewer_map.delete_marker",defaultMessage:"Delete Marker"}),children:I.jsx(Vx,{variant:"icon",className:"rounded-full p-1 hover:bg-gray-100 dark:hover:bg-gray-600",onClick:a=>r(a,e),"data-marker-id":e.id,children:I.jsx(qv,{className:"w-4 h-4 text-red-500"})})}),I.jsx(dHe,{marker:n.find(a=>a.id===e.id)})]})]})})});function pHe({markersData:e,loading:t,handleDeleteMarker:r,onMarkerClick:n,onClose:i,intl:a}){const[o,s]=j.useState(""),[u,h]=j.useState(""),[f,m]=j.useState(!1),[g,v]=j.useState(20),[b,x]=j.useState(!1),w=j.useRef(null),T=j.useCallback(xh(X=>{h(X),m(!1)},300),[]),C=j.useCallback(X=>{const z=X.target.value;s(z),m(!0),T(z)},[T]),M=j.useMemo(()=>!e||e.length===0?[]:e.map(X=>Ax(X)),[e]),O=j.useMemo(()=>{if(!u)return M;const X=u.toLowerCase();return M.filter(z=>{var W,H;return(H=(W=z==null?void 0:z.title)==null?void 0:W.toLowerCase())==null?void 0:H.includes(X)})},[M,u]),P=j.useMemo(()=>O.slice(0,g),[O,g]);j.useEffect(()=>{v(20)},[u]);const k=j.useCallback(()=>{b||g>=O.length||(x(!0),setTimeout(()=>{v(X=>Math.min(X+20,O.length)),x(!1)},300))},[b,g,O.length]),D=j.useCallback(X=>{const{scrollTop:z,scrollHeight:W,clientHeight:H}=X.target;z+H>=W-100&&!b&&g<O.length&&k()},[k,b,g,O.length]),V=j.useCallback((X,z)=>{n(X,z),i()},[n,i]),U=j.useCallback((X,z)=>{r(X,z)},[r]);return t?I.jsx("div",{className:"flex justify-center items-center h-40",children:I.jsx(Ja,{})}):I.jsxs("div",{className:"w-full",children:[I.jsxs("div",{className:"relative mb-4",children:[I.jsx(mh,{className:"w-4 h-4 text-gray-500 absolute left-3 top-1/2 transform -translate-y-1/2"}),I.jsx(sc,{className:"pl-9 w-full text-sm h-9",placeholder:a.formatMessage({id:"app.agviewer_map.search_station",defaultMessage:"Search Station"}),value:o,onChange:C}),f&&I.jsx("div",{className:"absolute right-3 top-1/2 transform -translate-y-1/2",children:I.jsx("div",{className:"animate-spin rounded-full h-4 w-4 border-b-2 border-primary"})})]}),I.jsx("div",{ref:w,className:"overflow-y-auto h-[350px]",onScroll:D,children:O.length===0?I.jsx("div",{className:"flex items-center justify-center h-20 p-4",children:I.jsx("h5",{className:"text-sm text-gray-500 dark:text-gray-400",children:o?a.formatMessage({id:"app.agviewer_map.no_station_found",defaultMessage:"No Station Found"}):a.formatMessage({id:"app.agviewer_map.no_station_found",defaultMessage:"No Station Found"})})}):I.jsxs(I.Fragment,{children:[P.map(X=>I.jsx(fHe,{marker:X,onMarkerClick:V,onDeleteMarker:U,markersData:e,intl:a},X.id)),b&&I.jsx("div",{className:"flex justify-center items-center py-4",children:I.jsxs("div",{className:"flex items-center gap-2",children:[I.jsx("div",{className:"animate-spin rounded-full h-4 w-4 border-b-2 border-primary"}),I.jsx("span",{className:"text-sm text-gray-500 dark:text-gray-400",children:"Loading more..."})]})}),g>=O.length&&O.length>0&&I.jsx("div",{className:"flex justify-center items-center py-4",children:I.jsx("span",{className:"text-sm text-gray-500 dark:text-gray-400",children:a.formatMessage({id:"app.agviewer_map.all_results_loaded",defaultMessage:"All results loaded"})})})]})})]})}const mHe=Object.freeze(Object.defineProperty({__proto__:null,default:pHe},Symbol.toStringTag,{value:"Module"}));us.AgvMap=KU,Object.defineProperty(us,Symbol.toStringTag,{value:"Module"})});