import{i as e}from"./chunk-aKtaBQYM.js";import{Mt as t,N as n,Q as r,Rt as i,St as a,Vt as o,Y as s,f as c,ft as l,ht as u,pt as d,t as f,ut as p,vt as m,wt as h}from"./mui-B6lh3XSP.js";import{t as g}from"./List-D4mHuGFJ.js";import{n as _}from"./Menu-H5c4_g_O.js";import{t as v}from"./TextField-DOdnjCrL.js";import{t as y}from"./Skeleton-C-luRk4q.js";import{B as b,I as x,It as S,P as C,Rt as w,_n as T,yt as E}from"./index-KVuxnkWj.js";var D=e(o(),1),O=h();function k(e={}){let{themeId:t,defaultTheme:n,defaultClassName:r=`MuiBox-root`,generateClassName:i}=e,o=a(`div`,{shouldForwardProp:e=>e!==`theme`&&e!==`sx`&&e!==`as`})(m);return D.forwardRef(function(e,a){let s=u(n),{className:c,component:d=`div`,...f}=e;return(0,O.jsx)(o,{as:d,ref:a,className:l(c,i?i(r):r),theme:t&&s[t]||s,...f})})}var A=p(`MuiBox`,[`root`]),j=k({themeId:t,defaultTheme:r(),defaultClassName:A.root,generateClassName:d.generate}),M=e(b(),1),N=()=>{let e=s();return(0,D.useEffect)(()=>{let t=new M.default.GeolocateControl({positionOptions:{enableHighAccuracy:!0,timeout:5e3},trackUserLocation:!1});return x.addControl(t,e.direction===`rtl`?`top-left`:`top-right`),()=>x.removeControl(t)},[e.direction]),null},P=T(),F=n((0,O.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`),I=f()(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`}})),L=()=>{let e=s(),t=i(),n=E(),{classes:r}=I(),[a,o]=(0,D.useState)(null),[l,u]=(0,D.useState)(``),[d,f]=(0,D.useState)([]),[p,m]=(0,D.useState)(!1);(0,D.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(c.push(e.message))}finally{m(!1)}},300);return()=>{e.abort(),clearTimeout(n)}},[l,t]),(0,D.useEffect)(()=>{let t,n,i={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 ${r.button}`,e.onclick=()=>o(e),t.appendChild(e),n=(0,P.createRoot)(e),n.render((0,O.jsx)(F,{fontSize:`small`})),t},onRemove:()=>{queueMicrotask(()=>n.unmount()),t.remove()}};return x.addControl(i,e.direction===`rtl`?`top-left`:`top-right`),()=>x.removeControl(i)},[e.direction,r.button]);let h=e=>{let[t,n,r,i]=e.bbox;x.fitBounds([C(t,n),C(r,i)],{padding:40}),o(null),u(``),f([])};return(0,O.jsx)(_,{anchorEl:a,open:!!a,onClose:()=>o(null),anchorOrigin:{vertical:`bottom`,horizontal:`right`},transformOrigin:{vertical:`top`,horizontal:`right`},children:(0,O.jsxs)(j,{className:r.panel,children:[(0,O.jsx)(j,{className:r.input,children:(0,O.jsx)(v,{autoFocus:!0,fullWidth:!0,size:`small`,placeholder:n(`sharedSearch`),value:l,onChange:e=>u(e.target.value)})}),(0,O.jsx)(g,{className:r.results,dense:!0,disablePadding:!0,children:p?Array.from({length:3},(e,t)=>(0,O.jsx)(w,{disabled:!0,children:(0,O.jsx)(S,{primary:(0,O.jsx)(y,{width:`100%`})})},t)):d.map(e=>(0,O.jsx)(w,{onClick:()=>h(e),children:(0,O.jsx)(S,{primary:e.properties.display_name})},e.properties.place_id))})]})})};export{N as n,L as t};