import"./hoisted.DebOr7RK.js";import"./hoisted.GAmqZOM-.js";import"./hoisted.CpFF9U1J.js";const v=e=>e.normalize("NFD").replace(/[\u0300-\u036f]/g,"").toLowerCase().replace(/[^\p{L}\p{N}]+/gu," ").trim();function B(e,t=[]){const i=new Set(t.map(v));return e.map(([r,c,a,l])=>({name:r,country:c,region:a,preferred:i.has(v(r)),search:v([r,l,a,c].join(" ")),key:v(r)}))}function T(e,t,i=8){const r=v(t);if(r.length<2)return[];const c=r.split(" ");return e.filter(a=>c.every(l=>a.search.split(" ").some(y=>y.startsWith(l)))).map(a=>({place:a,score:a.key===r?0:a.key.startsWith(r)?a.preferred?.5:1:2})).sort((a,l)=>a.score-l.score).slice(0,i).map(({place:a})=>a)}const n=document.querySelector("#activity-city"),d=document.querySelector("#activity-places"),w=document.querySelector("#place-status");let E,u=[],g=-1,A=0;n.removeAttribute("list");n.setAttribute("role","combobox");n.setAttribute("aria-autocomplete","list");n.setAttribute("aria-controls",d.id);n.setAttribute("aria-expanded","false");function f(){A++,d.hidden=!0,g=-1,n.setAttribute("aria-expanded","false"),n.removeAttribute("aria-activedescendant")}function $(e){const t=u[e];t&&(n.value=`${t.name}, ${t.country}`,f(),n.dispatchEvent(new Event("change",{bubbles:!0})),n.dispatchEvent(new CustomEvent("place-selected",{bubbles:!0})))}function j(e){g=e,Array.from(d.children).forEach((i,r)=>i.setAttribute("aria-selected",String(r===e)));const t=d.children[e];t&&(n.setAttribute("aria-activedescendant",t.id),t.scrollIntoView({block:"nearest"}))}async function q(){const e=++A,t=n.value.trim();if(t.length===1){f(),w.textContent="Type one more letter for city suggestions.";return}w.textContent="Finding cities…";try{E??=fetch("/data/activity-places.json").then(r=>{if(!r.ok)throw new Error("City index unavailable");return r.json()}).then(r=>B(r,Array.from(document.querySelectorAll("#activity-cities option")).map(c=>c.value))).catch(r=>{throw E=void 0,r});const i=await E;if(e!==A||document.activeElement!==n)return;u=t?T(i,t):["Paris","London","Rome","Dubai","New York City","Boston","Barcelona","Phuket"].map(r=>i.find(c=>c.name===r)).filter(r=>!!r),g=-1,n.removeAttribute("aria-activedescendant"),d.replaceChildren(...u.map((r,c)=>{const a=document.createElement("li");a.id=`activity-place-${c}`,a.setAttribute("role","option"),a.setAttribute("aria-selected","false"),a.dataset.index=String(c);const l=document.createElement("strong");l.textContent=r.name;const y=document.createElement("span");return y.textContent=[r.region,r.country].filter(Boolean).join(", "),a.append(l,y),a})),d.hidden=u.length===0,n.setAttribute("aria-expanded",String(u.length>0)),w.textContent=u.length?`${u.length} city suggestions. Use the up and down arrow keys to choose.`:"No matching city. You can still search for the place you entered."}catch{if(e!==A)return;f(),w.textContent="City suggestions are unavailable. You can still enter a place and search."}}n.addEventListener("input",q);n.addEventListener("focus",q);n.addEventListener("click",q);n.addEventListener("keydown",e=>{if(e.key==="Escape"){f();return}d.hidden||(e.key==="ArrowDown"||e.key==="ArrowUp"?(e.preventDefault(),j((g+(e.key==="ArrowDown"?1:g<0?0:-1)+u.length)%u.length)):e.key==="Enter"&&g>=0?(e.preventDefault(),$(g)):e.key==="Tab"&&f())});n.addEventListener("blur",f);d.addEventListener("pointerdown",e=>{e.preventDefault()});d.addEventListener("click",e=>{if(!(e.target instanceof Element))return;const t=e.target.closest("[data-index]");t&&$(Number(t.dataset.index))});n.form?.addEventListener("submit",f);document.addEventListener("click",e=>{e.target instanceof Element&&e.target.closest("a[data-category], a[data-destination]")&&f()});const N=document.querySelector("#activity-finder"),m=document.querySelector("#activity-city"),s=document.querySelector("#activity-type"),h=document.querySelector("#activity-results"),L=document.querySelector("#activity-status");let k=0,S,p;function O(e){document.querySelectorAll("[data-current-city]").forEach(t=>{t.textContent=e}),document.querySelectorAll("a[data-category]").forEach(t=>{t.href=`/activities/?${new URLSearchParams({city:e,type:t.dataset.category})}#activity-results`})}function b(e=!0){const t=m.value.trim().slice(0,100);if(!t){m.value="",m.reportValidity();return}m.value=t,O(t);const i=[t,s.value].filter(Boolean).join(" "),r=++k;clearTimeout(S),p?.disconnect(),h.setAttribute("aria-busy","true"),document.querySelectorAll("a[data-category]").forEach(o=>{o.dataset.category===s.value?o.setAttribute("aria-current","true"):o.removeAttribute("aria-current")});const c=h.querySelector(".gyg-native"),a=document.createElement("div");a.className="gyg-native";for(const o of["data-gyg-partner-id","data-gyg-locale-code","data-gyg-number-of-items","data-gyg-cmp","data-gyg-hide-join-affiliate-program"]){const C=c.getAttribute(o);C!==null&&a.setAttribute(o,C)}a.setAttribute("data-gyg-widget","activities"),a.setAttribute("data-gyg-href","https://widget.getyourguide.com/default/activities.frame"),a.setAttribute("data-gyg-q",i);const l=()=>{r===k&&(clearTimeout(S),p?.disconnect(),h.removeAttribute("aria-busy"),L.textContent=`Showing ${s.value?s.selectedOptions[0]?.textContent?.toLowerCase():"activities"} in ${t}.`)};p=new MutationObserver(()=>{const o=a.querySelector("iframe");o&&!o.dataset.activityLoadBound&&(o.dataset.activityLoadBound="true",o.addEventListener("load",l,{once:!0}))}),p.observe(a,{childList:!0}),c.replaceWith(a),S=setTimeout(()=>{r===k&&(p?.disconnect(),h.removeAttribute("aria-busy"),L.textContent=`Activities for ${t} are taking longer to load. You can browse the same search on GetYourGuide below.`)},15e3),h.querySelector("h2").textContent=`Explore activities in ${t}`;const y=h.querySelector(".gyg-fallback a"),x=new URL(y.href);if(x.searchParams.set("q",i),y.href=x.href,y.textContent=`Browse activities in ${t} on GetYourGuide ↗`,L.textContent=`Loading ${s.value?s.selectedOptions[0]?.textContent?.toLowerCase():"activities"} in ${t}…`,e){const o=new URL(location.href);o.searchParams.set("city",t),s.value?o.searchParams.set("type",s.value):o.searchParams.delete("type"),history.replaceState(null,"",o)}}document.addEventListener("click",e=>{if(!(e instanceof MouseEvent)||e.button!==0||e.metaKey||e.ctrlKey||e.shiftKey||e.altKey||!(e.target instanceof Element))return;const t=e.target.closest("a[data-category], a[data-destination]");if(!t)return;e.preventDefault(),m.value=t.dataset.destination??(m.value.trim()||"Phuket");const i=t.dataset.searchTerm??t.dataset.category??"";Array.from(s.options).some(r=>r.value===i)||s.add(new Option(i,i)),s.value=i,b(),h.scrollIntoView({behavior:matchMedia("(prefers-reduced-motion: reduce)").matches?"instant":"smooth",block:"start"})});s.addEventListener("change",()=>b());m.addEventListener("place-selected",()=>b());N.addEventListener("submit",e=>{e.preventDefault(),b()});const D=new URLSearchParams(location.search),P=D.get("city")?.trim().slice(0,100);if(P){m.value=P;const e=D.get("type")??"";e&&!Array.from(s.options).some(t=>t.value===e)&&s.add(new Option(e.slice(0,100),e.slice(0,100))),s.value=e.slice(0,100),b(!1)}