import{i as e}from"./chunk-aKtaBQYM.js";import{Et as t,Ft as n,G as r,K as i,L as a,Mt as o,f as s,ft as c,gt as l,it as u,lt as d,ot as f,st as p,t as m,vt as h}from"./mui-BgU4WrXF.js";import{t as g}from"./List-C_tzGiQy.js";import{t as _}from"./Skeleton-DLSq3aej.js";import{n as v}from"./Menu-CRiQ3s6A.js";import{t as y}from"./TextField-DctlzLY-.js";import{At as b,Ot as x,Xt as S,pt as C}from"./index-bel1r0Sr.js";import{n as w,r as T}from"./MapView-Bhqzv-Oc.js";var E=e(n(),1),D=h();function O(e={}){let{themeId:t,defaultTheme:n,defaultClassName:r=`MuiBox-root`,generateClassName:i}=e,a=l(`div`,{shouldForwardProp:e=>e!==`theme`&&e!==`sx`&&e!==`as`})(c);return E.forwardRef(function(e,o){let s=d(n),{className:c,component:l=`div`,...u}=e;return(0,D.jsx)(a,{as:l,ref:o,className:f(c,i?i(r):r),theme:t&&s[t]||s,...u})})}var k=u(`MuiBox`,[`root`]),A=O({themeId:t,defaultTheme:i(),defaultClassName:k.root,generateClassName:p.generate}),j=e(T(),1),M=()=>{let e=r();return(0,E.useEffect)(()=>{let t=new j.default.GeolocateControl({positionOptions:{enableHighAccuracy:!0,timeout:5e3},trackUserLocation:!1});return w.addControl(t,e.direction===`rtl`?`top-left`:`top-right`),()=>w.removeControl(t)},[e.direction]),null},N=S(),P=a((0,D.jsx)(`path`,{d:`M19.3 16.9c.4-.7.7-1.5.7-2.4 0-2.5-2-4.5-4.5-4.5S11 12 11 14.5s2 4.5 4.5 4.5c.9 0 1.7-.3 2.4-.7l3.2 3.2 1.4-1.4zm-3.8.1c-1.4 0-2.5-1.1-2.5-2.5s1.1-2.5 2.5-2.5 2.5 1.1 2.5 2.5-1.1 2.5-2.5 2.5M12 20v2C6.48 22 2 17.52 2 12S6.48 2 12 2c4.84 0 8.87 3.44 9.8 8h-2.07c-.64-2.46-2.4-4.47-4.73-5.41V5c0 1.1-.9 2-2 2h-2v2c0 .55-.45 1-1 1H8v2h2v3H9l-4.79-4.79C4.08 10.79 4 11.38 4 12c0 4.41 3.59 8 8 8`}),`TravelExplore`),F=m()(e=>({button:{"&&":{display:`flex`,alignItems:`center`,justifyContent:`center`,color:`#333`}},panel:{width:e.spacing(40),maxHeight:e.spacing(50),display:`flex`,flexDirection:`column`},input:{padding:e.spacing(1)},results:{overflowY:`auto`}})),I=()=>{let e=r(),t=o(),n=C(),{classes:i}=F(),[a,c]=(0,E.useState)(null),[l,u]=(0,E.useState)(``),[d,f]=(0,E.useState)([]),[p,m]=(0,E.useState)(!1);(0,E.useEffect)(()=>{l.trim()||(f([]),m(!1));let e=new AbortController,n=setTimeout(async()=>{m(!0);try{let t=`https://nominatim.openstreetmap.org/search?q=${encodeURIComponent(l)}&format=geojson&addressdetails=1`;f((await(await fetch(t,{signal:e.signal})).json()).features||[])}catch(e){e.name!==`AbortError`&&t(s.push(e.message))}finally{m(!1)}},300);return()=>{e.abort(),clearTimeout(n)}},[l,t]),(0,E.useEffect)(()=>{let t,n,r={onAdd:()=>{t=document.createElement(`div`),t.className=`maplibregl-ctrl maplibregl-ctrl-group`;let e=document.createElement(`button`);return e.type=`button`,e.className=`maplibregl-ctrl-icon ${i.button}`,e.onclick=()=>c(e),t.appendChild(e),n=(0,N.createRoot)(e),n.render((0,D.jsx)(P,{fontSize:`small`})),t},onRemove:()=>{queueMicrotask(()=>n.unmount()),t.remove()}};return w.addControl(r,e.direction===`rtl`?`top-left`:`top-right`),()=>w.removeControl(r)},[e.direction,i.button]);let h=e=>{let[t,n,r,i]=e.bbox;w.fitBounds([[t,n],[r,i]],{padding:40}),c(null),u(``),f([])};return(0,D.jsx)(v,{anchorEl:a,open:!!a,onClose:()=>c(null),anchorOrigin:{vertical:`bottom`,horizontal:`right`},transformOrigin:{vertical:`top`,horizontal:`right`},children:(0,D.jsxs)(A,{className:i.panel,children:[(0,D.jsx)(A,{className:i.input,children:(0,D.jsx)(y,{autoFocus:!0,fullWidth:!0,size:`small`,placeholder:n(`sharedSearch`),value:l,onChange:e=>u(e.target.value)})}),(0,D.jsx)(g,{className:i.results,dense:!0,disablePadding:!0,children:p?Array.from({length:3},(e,t)=>(0,D.jsx)(b,{disabled:!0,children:(0,D.jsx)(x,{primary:(0,D.jsx)(_,{width:`100%`})})},t)):d.map(e=>(0,D.jsx)(b,{onClick:()=>h(e),children:(0,D.jsx)(x,{primary:e.properties.display_name})},e.properties.place_id))})]})})};export{M as n,I as t};