@mapfirst.ai/core 0.0.21 → 0.0.23
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.
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.global.js +2 -2
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";var N=Object.defineProperty;var ne=Object.getOwnPropertyDescriptor;var se=Object.getOwnPropertyNames;var oe=Object.prototype.hasOwnProperty;var pe=(n,e)=>{for(var t in e)N(n,t,{get:e[t],enumerable:!0})},le=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of se(e))!oe.call(n,a)&&a!==t&&N(n,a,{get:()=>e[a],enumerable:!(r=ne(e,a))||r.enumerable});return n};var ce=n=>le(N({},"__esModule",{value:!0}),n);var Ae={};pe(Ae,{MapFirstCore:()=>z,PropertiesFetchError:()=>_,convertToApiFilters:()=>Q,fetchProperties:()=>ae,processApiFilters:()=>
|
|
2
|
-
`);function q(n,e,t,r){var g,m,y;if(typeof document=="undefined")return null;let a=n.marker,i=a.type===e,o=t===a.tripadvisor_id,s=a.type==="Accommodation"&&((m=(g=a.pricing)==null?void 0:g.offer)==null?void 0:m.availability)!=="available",p=document.createElement("div");p.className="mapfirst-dot-marker-container",p.style.zIndex=o?"20":i?"3":"1";let h=document.createElement("div");return h.className=s?"mapfirst-dot-marker-button mapfirst-dot-marker-button-pending":`mapfirst-dot-marker-button mapfirst-dot-marker-button-active${o?" mapfirst-dot-marker-selected":i?"":" mapfirst-dot-marker-non-primary"}`,h.title=(y=a.name)!=null?y:String(a.tripadvisor_id),h.addEventListener("click",b=>{b.stopPropagation(),s||r==null||r(a)}),p.appendChild(h),p}var me='<svg viewBox="0 0 24 24" width="32" height="32" fill="currentColor"><path d="M12 3.953a7.442 7.442 0 1 0 .001 14.884A7.442 7.442 0 0 0 12 3.953m0 14.05a6.61 6.61 0 1 1 0-13.218 6.61 6.61 0 0 1 0 13.219M10.343 11.9a.91.91 0 1 1-1.821 0 .91.91 0 0 1 1.821 0m5.134 0a.91.91 0 1 1-1.821 0 .91.91 0 0 1 1.82 0m.82-1.897.84-.913h-1.863A5.8 5.8 0 0 0 12 8.08a5.77 5.77 0 0 0-3.27 1.008H6.862l.84.913a2.567 2.567 0 1 0 3.475 3.78l.823.896.823-.895a2.568 2.568 0 1 0 3.474-3.78m-6.865 3.634a1.738 1.738 0 1 1 0-3.476 1.738 1.738 0 0 1 0 3.476M12 11.85c0-1.143-.832-2.124-1.929-2.543A5 5 0 0 1 12 8.92a5 5 0 0 1 1.928.386c-1.096.42-1.927 1.4-1.927 2.543m2.566 1.787a1.738 1.738 0 1 1 .001-3.476 1.738 1.738 0 0 1 0 3.476m-8.456 3.719s-.377-.946-1.396-1.903c-1.02-.957-2.303-1.132-2.303-1.132s.457 1.02 1.54 2.04c1.086 1.017 2.159.995 2.159.995m2.568 1.41s-.524-.511-1.479-.883-1.861-.191-1.861-.191.598.54 1.615.935c1.016.397 1.725.139 1.725.139m2.493.505s-.545-.224-1.357-.196-1.415.47-1.415.47.608.222 1.473.193 1.3-.467 1.3-.467m-6.186-4.203s-.175-1.008-.974-2.154c-.8-1.147-2.015-1.578-2.015-1.578s.238 1.098 1.089 2.319c.85 1.22 1.9 1.413 1.9 1.413m-1.003-3.071s.195-1.021-.134-2.393c-.328-1.371-1.294-2.21-1.294-2.21s-.17 1.128.18 2.589c.35 1.46 1.248 2.014 1.248 2.014"></path><path d="M17.887 17.355s.377-.946 1.396-1.903c1.02-.957 2.303-1.132 2.303-1.132s-.457 1.02-1.54 2.04c-1.086 1.017-2.159.995-2.159.995m-2.567 1.41s.524-.511 1.479-.883 1.861-.191 1.861-.191-.598.54-1.615.935c-1.016.397-1.725.139-1.725.139m-2.493.505s.545-.224 1.357-.196 1.415.47 1.415.47-.608.222-1.473.193-1.3-.467-1.3-.467m6.186-4.203s.175-1.008.974-2.154c.8-1.147 2.015-1.578 2.015-1.578s-.238 1.098-1.089 2.319c-.85 1.22-1.9 1.413-1.9 1.413m1.003-3.071s-.195-1.021.133-2.393c.33-1.371 1.293-2.21 1.293-2.21s.17 1.128-.18 2.589c-.349 1.46-1.246 2.014-1.246 2.014M12 20.047a.413.413 0 1 0 0-.827.413.413 0 0 0 0 .827"></path></svg>',de='<svg viewBox="0 0 24 24" width="32" height="32"><path d="M12 3.953a7.442 7.442 0 1 0 .001 14.884A7.442 7.442 0 0 0 12 3.953m0 14.05a6.61 6.61 0 1 1 0-13.218 6.61 6.61 0 0 1 0 13.219M10.343 11.9a.91.91 0 1 1-1.821 0 .91.91 0 0 1 1.821 0m5.134 0a.91.91 0 1 1-1.821 0 .91.91 0 0 1 1.82 0m.82-1.897.84-.913h-1.863A5.8 5.8 0 0 0 12 8.08a5.77 5.77 0 0 0-3.27 1.008H6.862l.84.913a2.567 2.567 0 1 0 3.475 3.78l.823.896.823-.895a2.568 2.568 0 1 0 3.474-3.78m-6.865 3.634a1.738 1.738 0 1 1 0-3.476 1.738 1.738 0 0 1 0 3.476M12 11.85c0-1.143-.832-2.124-1.929-2.543A5 5 0 0 1 12 8.92a5 5 0 0 1 1.928.386c-1.096.42-1.927 1.4-1.927 2.543m2.566 1.787a1.738 1.738 0 1 1 .001-3.476 1.738 1.738 0 0 1 0 3.476m-8.456 3.719s-.377-.946-1.396-1.903c-1.02-.957-2.303-1.132-2.303-1.132s.457 1.02 1.54 2.04c1.086 1.017 2.159.995 2.159.995m2.568 1.41s-.524-.511-1.479-.883-1.861-.191-1.861-.191.598.54 1.615.935c1.016.397 1.725.139 1.725.139m2.493.505s-.545-.224-1.357-.196-1.415.47-1.415.47.608.222 1.473.193 1.3-.467 1.3-.467m-6.186-4.203s-.175-1.008-.974-2.154c-.8-1.147-2.015-1.578-2.015-1.578s.238 1.098 1.089 2.319c.85 1.22 1.9 1.413 1.9 1.413m-1.003-3.071s.195-1.021-.134-2.393c-.328-1.371-1.294-2.21-1.294-2.21s-.17 1.128.18 2.589c.35 1.46 1.248 2.014 1.248 2.014"></path><path d="M17.887 17.355s.377-.946 1.396-1.903c1.02-.957 2.303-1.132 2.303-1.132s-.457 1.02-1.54 2.04c-1.086 1.017-2.159.995-2.159.995m-2.567 1.41s.524-.511 1.479-.883 1.861-.191 1.861-.191-.598.54-1.615.935c-1.016.397-1.725.139-1.725.139m-2.493.505s.545-.224 1.357-.196 1.415.47 1.415.47-.608.222-1.473.193-1.3-.467-1.3-.467m6.186-4.203s.175-1.008.974-2.154c.8-1.147 2.015-1.578 2.015-1.578s-.238 1.098-1.089 2.319c-.85 1.22-1.9 1.413-1.9 1.413m1.003-3.071s-.195-1.021.133-2.393c.33-1.371 1.293-2.21 1.293-2.21s.17 1.128-.18 2.589c-.349 1.46-1.246 2.014-1.246 2.014M12 20.047a.413.413 0 1 0 0-.827.413.413 0 0 0 0 .827"></path></svg>',ue='<svg viewBox="0 0 24 24" width="20" height="20" fill="currentColor"><path fill-rule="evenodd" clip-rule="evenodd" d="M14.051 6.549v.003l1.134 1.14 3.241-3.25.003-.002 1.134 1.136-3.243 3.252 1.134 1.14a1 1 0 0 0 .09-.008c.293-.05.573-.324.72-.474l.005-.006 2.596-2.603L22 8.016l-2.597 2.604a3.73 3.73 0 0 1-1.982 1.015 4.3 4.3 0 0 1-3.162-.657l-.023-.016-.026-.018-1.366 1.407 8.509 8.512L20.219 22l-.002-.002-6.654-6.663-2.597 2.76-7.3-7.315C1.967 8.948 1.531 6.274 2.524 4.198c.241-.504.566-.973.978-1.386l8.154 8.416 1.418-1.423-.039-.045c-.858-1.002-1.048-2.368-.62-3.595a4.15 4.15 0 0 1 .983-1.561L16 2l1.135 1.138-2.598 2.602-.047.045c-.16.151-.394.374-.433.678zM3.809 5.523c-.362 1.319-.037 2.905 1.06 4.103L10.93 15.7l1.408-1.496zM2.205 20.697 3.34 21.84l4.543-4.552-1.135-1.143z"/></svg>',he='<svg viewBox="0 0 24 24" width="20" height="20" fill="currentColor"><path fill-rule="evenodd" clip-rule="evenodd" d="M7.56 7.5H3.75a.25.25 0 0 0-.25.25v10c0 .138.112.25.25.25h16.5a.25.25 0 0 0 .25-.25v-10a.25.25 0 0 0-.25-.25h-3.81l-2-2H9.56zM8.94 4h6.12l2 2h3.19c.966 0 1.75.784 1.75 1.75v10a1.75 1.75 0 0 1-1.75 1.75H3.75A1.75 1.75 0 0 1 2 17.75v-10C2 6.784 2.784 6 3.75 6h3.19z"/><path fill-rule="evenodd" clip-rule="evenodd" d="M12 9.25a2.75 2.75 0 1 0 0 5.5 2.75 2.75 0 0 0 0-5.5M7.75 12a4.25 4.25 0 1 1 8.5 0 4.25 4.25 0 0 1-8.5 0"/></svg>';function G(n,e,t,r){var b,d,u,f,l,M,x,L;if(typeof document=="undefined")return null;let a=n.marker,i=a.type===e,o=t===a.tripadvisor_id,c=a.type==="Accommodation",s=(d=(b=a.pricing)==null?void 0:b.offer)==null?void 0:d.displayPrice,p=c&&!s,h=(()=>{if(a.rating===void 0||a.rating===null)return null;let k=typeof a.rating=="number"?a.rating:Number(a.rating);return Number.isNaN(k)||k<=0?null:k.toFixed(1)})(),g=document.createElement("div");g.className="mapfirst-marker-root",g.style.zIndex=o?"20":i?"12":"11";let m=document.createElement("div");if(m.className=p?"mapfirst-marker-pill mapfirst-marker-pill-pending":`mapfirst-marker-pill mapfirst-marker-pill-active${o?" mapfirst-marker-selected":i?"":" mapfirst-marker-non-primary"}`,m.title=(u=a.name)!=null?u:String(a.tripadvisor_id),!p&&((f=a.awards)!=null&&f.length||h)){let k=document.createElement("div");if(k.className="mapfirst-marker-badge",i||(k.style.opacity="0.2"),k.className="mapfirst-marker-badge",(l=a.awards)!=null&&l.length&&a.awards[0].type){let A=document.createElement("div");A.className="mapfirst-marker-award-container";let C=document.createElement("div");C.className="mapfirst-marker-award-back",C.innerHTML=de;let v=document.createElement("div");v.className=`mapfirst-marker-award-dot mapfirst-marker-award-dot-type-${a.awards[0].type}`;let P=document.createElement("div");P.className="mapfirst-marker-award-front",P.innerHTML=me,A.appendChild(C),A.appendChild(v),A.appendChild(P),k.appendChild(A)}else h&&(k.className="mapfirst-marker-badge mapfirst-marker-rating-badge",k.textContent=h);m.appendChild(k)}let y=document.createElement("span");return y.className="mapfirst-marker-content",c?y.textContent=(L=(x=(M=a.pricing)==null?void 0:M.offer)==null?void 0:x.displayPrice)!=null?L:"\u2014":a.type==="Eat & Drink"?y.innerHTML=ue:a.type==="Attraction"&&(y.innerHTML=he),m.appendChild(y),m.addEventListener("click",k=>{k.stopPropagation(),p||r==null||r(a)}),g.appendChild(m),g}function V(n,e,t,r){let a=n;a.style.zIndex=t?"20":e?"12":"11";let i=a.querySelector(".mapfirst-marker-pill");i&&(r?i.className="mapfirst-marker-pill mapfirst-marker-pill-pending":i.className=`mapfirst-marker-pill mapfirst-marker-pill-active${t?" mapfirst-marker-selected":e?"":" mapfirst-marker-non-primary"}`);let o=a.querySelector(".mapfirst-marker-badge");o instanceof HTMLElement&&(o.style.opacity=!e&&!t?"0.2":"")}function U(n,e,t,r){let a=n;a.style.zIndex=t?"20":e?"3":"1";let i=a.querySelector(".mapfirst-dot-marker-button");i&&(r?i.className="mapfirst-dot-marker-button mapfirst-dot-marker-button-pending":i.className=`mapfirst-dot-marker-button mapfirst-dot-marker-button-active${t?" mapfirst-dot-marker-selected":e?"":" mapfirst-dot-marker-non-primary"}`)}function K(n){let e=n.match(/^(?:primary|dot)-(\d+)-/);return e?parseInt(e[1],10):null}var I=class{constructor(e,t){this.markerCache=new Map;this.primaryType="Accommodation";this.selectedMarkerId=null;this.mapInstance=e,this.onMarkerClick=t}render(e,t,r){var i,o,c,s;t&&t!==this.primaryType&&(this.primaryType=t),r!==void 0&&(this.selectedMarkerId=r);let a=new Set(e.map(p=>p.key));for(let[p,h]of this.markerCache.entries())a.has(p)||(this.removeMarkerFromMap(h.marker),this.markerCache.delete(p));for(let p of e){let h=fe(p.marker.location);if(!h)continue;let g=this.markerCache.get(p.key);if(g)try{this.updateMarkerPosition(g.marker,h)}catch{this.removeMarkerFromMap(g.marker),this.markerCache.delete(p.key),this.createAndAddMarker(p,h)}else{let m=p.marker.tripadvisor_id,y,b;for(let[d,u]of this.markerCache.entries())if(K(d)===m&&u.kind===p.kind){y=u,b=d;break}if(y&&b){let d=p.marker.type===this.primaryType,u=this.selectedMarkerId===p.marker.tripadvisor_id,f=p.marker.type==="Accommodation",l=p.kind==="primary"?f&&!((o=(i=p.marker.pricing)==null?void 0:i.offer)!=null&&o.displayPrice):f&&((s=(c=p.marker.pricing)==null?void 0:c.offer)==null?void 0:s.availability)!=="available",M=this.getMarkerElement(y.marker);M&&(p.kind==="primary"?V(M,d,u,l):U(M,d,u,l)),this.updateMarkerZIndex(y.marker,p,d,u),this.markerCache.delete(b),this.markerCache.set(p.key,y);try{this.updateMarkerPosition(y.marker,h)}catch{}}else this.createAndAddMarker(p,h)}}}destroy(){for(let e of this.markerCache.values())this.removeMarkerFromMap(e.marker);this.markerCache.clear()}createAndAddMarker(e,t){let r=e.kind==="primary"?G(e,this.primaryType,this.selectedMarkerId,this.onMarkerClick):q(e,this.primaryType,this.selectedMarkerId,this.onMarkerClick);if(!r)return;let a=e.marker.type===this.primaryType,i=this.selectedMarkerId===e.marker.tripadvisor_id;try{let o=this.createMarker(r,t,e,a,i);o&&this.markerCache.set(e.key,{key:e.key,marker:o,kind:e.kind,parentId:e.kind==="dot"?e.parentId:void 0})}catch(o){console.error("Error creating marker",o)}}updateMarkerZIndex(e,t,r,a){}};function fe(n){return typeof(n==null?void 0:n.lon)!="number"||typeof(n==null?void 0:n.lat)!="number"||Number.isNaN(n.lon)||Number.isNaN(n.lat)?null:{lon:n.lon,lat:n.lat}}var w=class extends I{constructor(e){var t;super(e.mapInstance,e.onMarkerClick),this.MarkerCtor=(t=e.maplibregl)==null?void 0:t.Marker}render(e,t,r){this.MarkerCtor&&super.render(e,t,r)}createMarker(e,t,r){return this.MarkerCtor?new this.MarkerCtor({element:e,anchor:r.kind==="primary"?"bottom":"center"}).setLngLat([t.lon,t.lat]).addTo(this.mapInstance):null}removeMarkerFromMap(e){try{e.remove()}catch{}}updateMarkerPosition(e,t){e.setLngLat([t.lon,t.lat])}getMarkerElement(e){return e.getElement()}};var B=class extends I{constructor(e){super(e.mapInstance,e.onMarkerClick),this.google=e.google}render(e,t,r){var a,i;if(!((i=(a=this.google)==null?void 0:a.marker)!=null&&i.AdvancedMarkerElement)){console.warn("AdvancedMarkerElement not available");return}super.render(e,t,r)}createMarker(e,t,r,a,i){var c,s;if(!((s=(c=this.google)==null?void 0:c.marker)!=null&&s.AdvancedMarkerElement))return null;let o=r.kind==="primary"?i?20:a?12:11:i?20:a?3:1;return new this.google.marker.AdvancedMarkerElement({map:this.mapInstance,position:{lat:t.lat,lng:t.lon},content:e,zIndex:o})}removeMarkerFromMap(e){try{e.map=null}catch(t){console.error("Error removing marker",t)}}updateMarkerPosition(e,t){e.position={lat:t.lat,lng:t.lon}}getMarkerElement(e){let t=e.content;return t instanceof HTMLElement?t:null}updateMarkerZIndex(e,t,r,a){let i=t.kind==="primary"?a?20:r?12:11:a?20:r?3:1;e.zIndex=i}};var E=class extends I{constructor(e){var t;super(e.mapInstance,e.onMarkerClick),this.MarkerCtor=(t=e.mapboxgl)==null?void 0:t.Marker}render(e,t,r){this.MarkerCtor&&super.render(e,t,r)}createMarker(e,t,r){return this.MarkerCtor?new this.MarkerCtor({element:e,anchor:r.kind==="primary"?"bottom":"center"}).setLngLat([t.lon,t.lat]).addTo(this.mapInstance):null}removeMarkerFromMap(e){try{e.remove()}catch{}}updateMarkerPosition(e,t){e.setLngLat([t.lon,t.lat])}getMarkerElement(e){return e.getElement()}};var S=class{constructor(e){this.map=e}getMap(){return this.map}setupImpressionTracking(e){if(typeof window=="undefined"||!window.IntersectionObserver)return;let t=this.getContainer();if(!t)return;let r=new IntersectionObserver(o=>{o.forEach(c=>{c.isIntersecting&&(e(),r.disconnect())})},{threshold:.1});r.observe(t);let a=()=>r.disconnect(),i=this.cleanup.bind(this);this.cleanup=()=>{a(),i()}}};var R=class extends S{constructor(t){super(t);this.cleanupFns=[]}initialize(t){return this.markerManager=new w({mapInstance:this.map,maplibregl:t.maplibregl,onMarkerClick:t.onMarkerClick}),t.onRefresh&&this.attachEventListeners(t.onRefresh),t.onMapMoveEnd&&this.attachBoundsTracking(t.onMapMoveEnd),this.markerManager}attachBoundsTracking(t){if(!this.map||typeof this.map.on!="function")return;let r=()=>{let i=this.getMapBounds();t(i)},a=()=>{let i=this.getMapBounds();t(i)};this.map.loaded&&this.map.loaded()?a():(this.map.once("load",a),this.cleanupFns.push(()=>{typeof this.map.off=="function"&&this.map.off("load",a)})),this.map.on("moveend",r),this.cleanupFns.push(()=>{typeof this.map.off=="function"&&this.map.off("moveend",r)})}attachEventListeners(t){if(!this.map||typeof this.map.on!="function")return;["move","zoom","dragend","pitch","rotate"].forEach(a=>{this.map.on(a,t),this.cleanupFns.push(()=>{typeof this.map.off=="function"&&this.map.off(a,t)})})}getMarkerManager(){return this.markerManager}getContainer(){var t,r;return((r=(t=this.map)==null?void 0:t.getContainer)==null?void 0:r.call(t))||null}cleanup(){for(let t of this.cleanupFns)try{t()}catch{}this.cleanupFns.length=0}getMap(){return this.map}getCenter(){let t=this.map.getCenter();return{lng:t.lng,lat:t.lat}}getZoom(){return this.map.getZoom()}getBearing(){return this.map.getBearing()}getPitch(){return this.map.getPitch()}getMapBounds(){let t=this.map.getBounds(),r=t.getSouthWest(),a=t.getNorthEast();return{sw:{lat:r.lat,lng:r.lng},ne:{lat:a.lat,lng:a.lng}}}project(t){return this.map.project({lng:t[0],lat:t[1]})}on(t,r){this.map.on(t,r)}off(t,r){this.map.off(t,r)}resize(){this.map.resize()}remove(){this.cleanup(),this.map.remove()}};var F=class extends S{constructor(t){super(t);this.cleanupFns=[];this.initializeOverlayView()}initialize(t){return this.markerManager=new B({mapInstance:this.map,google:t.google,onMarkerClick:t.onMarkerClick}),t.onRefresh&&this.attachEventListeners(t.onRefresh),t.onMapMoveEnd&&this.attachBoundsTracking(t.onMapMoveEnd,t.google),this.markerManager}attachBoundsTracking(t,r){if(!this.map)return;let a=()=>{let o=this.getMapBounds();t(o)};a();let i=r.event.addListener(this.map,"idle",a);this.cleanupFns.push(()=>{r.event.removeListener(i)})}attachEventListeners(t){let r=["center_changed","zoom_changed","drag","heading_changed","tilt_changed"],a=[];r.forEach(i=>{let o=this.map.addListener(i,t);a.push(o)}),this.cleanupFns.push(()=>{a.forEach(i=>{try{i.remove()}catch{}})})}getMarkerManager(){return this.markerManager}getContainer(){var t,r;return((r=(t=this.map)==null?void 0:t.getDiv)==null?void 0:r.call(t))||null}cleanup(){for(let t of this.cleanupFns)try{t()}catch{}this.cleanupFns.length=0}initializeOverlayView(){var a;let t=(a=globalThis.google)==null?void 0:a.maps;if(!t)return;let r=t.OverlayView;r&&(this.overlayView=new r,this.overlayView.draw=function(){},this.overlayView.setMap(this.map))}getMap(){return this.map}getCenter(){let t=this.map.getCenter();return t?{lng:t.lng(),lat:t.lat()}:{lng:0,lat:0}}getZoom(){var t;return(t=this.map.getZoom())!=null?t:0}getBearing(){var t;return(t=this.map.getHeading())!=null?t:0}getPitch(){var t;return(t=this.map.getTilt())!=null?t:0}getMapBounds(){let t=this.map.getBounds();if(!t)return{sw:{lat:0,lng:0},ne:{lat:0,lng:0}};let r=t.getSouthWest(),a=t.getNorthEast();return{sw:{lat:r.lat(),lng:r.lng()},ne:{lat:a.lat(),lng:a.lng()}}}project(t){var c;if(!this.overlayView)return{x:0,y:0};let r=this.overlayView.getProjection();if(!r)return{x:0,y:0};let a=(c=globalThis.google)==null?void 0:c.maps;if(!a)return{x:0,y:0};let i=new a.LatLng(t[1],t[0]),o=r.fromLatLngToContainerPixel(i);return o?{x:o.x,y:o.y}:{x:0,y:0}}on(t,r){this.map.addListener(t,r)}off(t,r){var i;let a=(i=globalThis.google)==null?void 0:i.maps;a!=null&&a.event&&a.event.clearListeners(this.map,t)}resize(){var r;let t=(r=globalThis.google)==null?void 0:r.maps;t!=null&&t.event&&t.event.trigger(this.map,"resize")}remove(){this.cleanup(),this.overlayView&&(this.overlayView.setMap(null),this.overlayView=null)}};var D=class extends S{constructor(t){super(t);this.cleanupFns=[]}initialize(t){return this.markerManager=new E({mapInstance:this.map,mapboxgl:t.mapboxgl,onMarkerClick:t.onMarkerClick}),t.onRefresh&&this.attachEventListeners(t.onRefresh),t.onMapMoveEnd&&this.attachBoundsTracking(t.onMapMoveEnd),this.markerManager}attachBoundsTracking(t){if(!this.map||typeof this.map.on!="function")return;let r=()=>{let i=this.getMapBounds();t(i)},a=()=>{let i=this.getMapBounds();t(i)};this.map.loaded&&this.map.loaded()?a():(this.map.once("load",a),this.cleanupFns.push(()=>{typeof this.map.off=="function"&&this.map.off("load",a)})),this.map.on("moveend",r),this.cleanupFns.push(()=>{typeof this.map.off=="function"&&this.map.off("moveend",r)})}attachEventListeners(t){if(!this.map||typeof this.map.on!="function")return;["move","zoom","dragend","pitch","rotate"].forEach(a=>{this.map.on(a,t),this.cleanupFns.push(()=>{typeof this.map.off=="function"&&this.map.off(a,t)})})}getMarkerManager(){return this.markerManager}getContainer(){var t,r;return((r=(t=this.map)==null?void 0:t.getContainer)==null?void 0:r.call(t))||null}cleanup(){for(let t of this.cleanupFns)try{t()}catch{}this.cleanupFns.length=0}getMap(){return this.map}getCenter(){let t=this.map.getCenter();return{lng:t.lng,lat:t.lat}}getZoom(){return this.map.getZoom()}getBearing(){return this.map.getBearing()}getPitch(){return this.map.getPitch()}getMapBounds(){let t=this.map.getBounds(),r=t.getSouthWest(),a=t.getNorthEast();return{sw:{lat:r.lat,lng:r.lng},ne:{lat:a.lat,lng:a.lng}}}project(t){return this.map.project({lng:t[0],lat:t[1]})}on(t,r){this.map.on(t,r)}off(t,r){this.map.off(t,r)}resize(){this.map.resize()}remove(){this.cleanup(),this.map.remove()}};function J(n){let e=n.getCenter();return{longitude:e.lng,latitude:e.lat,zoom:n.getZoom(),bearing:n.getBearing(),pitch:n.getPitch()}}var ye=[{zoom:6,threshold:120},{zoom:8,threshold:108},{zoom:10,threshold:92},{zoom:12,threshold:80},{zoom:14,threshold:68},{zoom:16,threshold:56}];function Y(n){for(let e of ye)if(n<=e.zoom)return e.threshold;return 48}function H({primaryType:n,markers:e,map:t,selectedMarkerId:r,zoom:a,collisionThresholdPx:i,dotCollisionThresholdPx:o}){if(!e.length)return[];if(!t)return e.map(d=>({kind:"primary",marker:d,key:`primary-${d.tripadvisor_id}`}));let c=e.map((d,u)=>{let f=d.location;if(typeof(f==null?void 0:f.lon)!="number"||typeof(f==null?void 0:f.lat)!="number")return null;let{x:l,y:M}=t.project([f.lon,f.lat]);return{marker:d,index:u,x:l,y:M}}).filter(d=>!!d);if(!c.length)return[];let s=Y(a),p=be(a),h=c.map((d,u)=>u),g=d=>h[d]===d?d:(h[d]=g(h[d]),h[d]),m=(d,u)=>{let f=g(d),l=g(u);f!==l&&(h[l]=f)};for(let d=0;d<c.length;d+=1)for(let u=d+1;u<c.length;u+=1){let f=c[d].x-c[u].x,l=c[d].y-c[u].y;Math.hypot(f,l)<=s&&m(d,u)}let y=new Map;for(let d of c){let u=g(d.index),f=y.get(u);f?f.push(d):y.set(u,[d])}let b=[];return y.forEach(d=>{var A,C;if(d.length===1){let[{marker:v}]=d,P=v.type===n,T=r===v.tripadvisor_id;b.push({kind:"primary",marker:v,key:`primary-${v.tripadvisor_id}-p${P?1:0}-s${T?1:0}-${(A=v.pricing)==null?void 0:A.availability}`});return}let u=[...d].sort((v,P)=>ke(P.marker,v.marker,n)),[f,...l]=u,M=f.marker.type===n,x=r===f.marker.tripadvisor_id;if(b.push({kind:"primary",marker:f.marker,key:`primary-${f.marker.tripadvisor_id}-p${M?1:0}-s${x?1:0}-${(C=f.marker.pricing)==null?void 0:C.availability}`}),!l.length)return;let L=[],k=[];if(l.forEach(v=>{var P;if(r&&v.marker.tripadvisor_id===r){let T=v.marker.type===n;b.push({kind:"primary",marker:v.marker,key:`primary-${v.marker.tripadvisor_id}-p${T?1:0}-s1-${(P=v.marker.pricing)==null?void 0:P.availability}`});return}ge(f,v)<=p?L.push(v):k.push(v)}),L.forEach(v=>{var T;let P=v.marker.type===n;b.push({kind:"dot",marker:v.marker,key:`dot-${v.marker.tripadvisor_id}-p${P?1:0}-s0-${(T=v.marker.pricing)==null?void 0:T.availability}`,parentId:f.marker.tripadvisor_id})}),k.length){let v=H({markers:k.map(P=>P.marker),map:t,selectedMarkerId:r,zoom:a,primaryType:n,collisionThresholdPx:i,dotCollisionThresholdPx:o});b.push(...v)}}),b}function ge(n,e){return Math.hypot(n.x-e.x,n.y-e.y)}function be(n){let e=Y(n);return Math.max(48,e)}function ke(n,e,t){var s,p;let r=n.type===t,a=e.type===t;if(r&&!a)return 1;if(!r&&a)return-1;let i=Z(n)-Z(e);if(i!==0)return i;let o=W(n)-W(e);if(o!==0)return o;let c=((s=n.reviews)!=null?s:0)-((p=e.reviews)!=null?p:0);return c!==0?c:n.tripadvisor_id-e.tripadvisor_id}function Z(n){if(typeof n.rating=="number")return n.rating;if(n.rating===void 0||n.rating===null)return-1/0;let e=Number(n.rating);return Number.isNaN(e)?-1/0:e}function W(n){var t,r,a;if(!((r=(t=n.pricing)==null?void 0:t.offer)!=null&&r.price))return-1/0;let e=Number(((a=n.pricing.offer.displayPrice)!=null?a:"0").replace(/[^0-9.,-]+/g,"").replace(/,/g,""));return Number.isNaN(e)?-1/0:e}function X(n){let e=[];return n.amenities&&Array.isArray(n.amenities)&&n.amenities.forEach(t=>{e.push({id:`amenity-${t}`,label:t,type:"amenity",value:t})}),n.hotelStyle&&Array.isArray(n.hotelStyle)&&n.hotelStyle.forEach(t=>{e.push({id:`hotelStyle-${t}`,label:t,type:"hotelStyle",value:t})}),n.price&&e.push({id:"priceRange",label:"Price Range",type:"priceRange",value:`${n.price.min}-${n.price.max}`,priceRange:n.price}),typeof n.minRating=="number"&&Number.isFinite(n.minRating)&&e.push({id:"minRating",label:`${n.minRating}+`,type:"minRating",value:String(n.minRating),numericValue:n.minRating}),typeof n.starRating=="number"&&Number.isFinite(n.starRating)&&e.push({id:"starRating",label:`${n.starRating} Stars`,type:"starRating",value:String(n.starRating),numericValue:n.starRating}),n.transformed_query&&e.push({id:"transformed_query",label:n.transformed_query,type:"transformed_query",value:n.transformed_query}),n.selected_restaurant_price_levels&&e.push({id:"selected_restaurant_price_levels",label:n.selected_restaurant_price_levels.join(", "),type:"selected_restaurant_price_levels",value:n.selected_restaurant_price_levels.join(", "),priceLevels:n.selected_restaurant_price_levels}),e}function Q(n){return n.map(e=>{let t={id:e.id,label:typeof e.label=="string"?e.label:String(e.label||""),type:e.type,value:e.value};if(e.numericValue!==void 0&&(t.numericValue=e.numericValue),e.priceRange){let r=e.priceRange.min,a=e.priceRange.max;r!==void 0&&(t.priceRange={min:r,...a!==void 0&&{max:a}})}return e.priceLevels&&(t.priceLevels=e.priceLevels),t})}var Me={prod:"https://api.mapfirst.ai",test:"https://api.mapfirst.ai/test"},_=class extends Error{constructor({message:e,status:t,code:r}){super(e),this.name="PropertiesFetchError",this.status=t,this.code=r}};async function ae(n,e,{signal:t}={}){var a,i;let r=await fetch(n,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e),signal:t});if(!r.ok){let o=`Unexpected response: ${r.status}`,c;try{let s=await r.json();o=(i=(a=s.detail)!=null?a:s.error)!=null?i:o,c=s.code}catch{}throw new _({message:o,status:r.status,code:c})}return await r.json()}function ee(n){return typeof n=="string"?n:n.toISOString().slice(0,10)}async function ve(n,e,t){try{await fetch(`${n}/${e}/impressions`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({timestamp:new Date().toISOString(),type:"map_view",...t})})}catch(r){console.debug("Failed to track map impression:",r)}}var te="Accommodation";function Pe(){let e=new Date(Date.now()+864e6),t=(6-e.getDay()+7)%7,r=new Date(e.getTime()+t*864e5),a=r.getDay(),i=a===0?6:6-a,o=new Date(r.getTime()+(i+1)*864e5);return{checkIn:r,checkOut:o}}var z=class{constructor(e){this.options=e;this.adapter=null;this.properties=[];this.selectedMarkerId=null;this.destroyed=!1;this.clusterItems=[];this.isMapAttached=!1;var a,i,o,c,s,p,h,g,m,y,b,d,u,f,l,M,x;if(this.properties=[...(a=e.properties)!=null?a:[]],this.primaryType=e.primaryType,this.selectedMarkerId=(i=e.selectedMarkerId)!=null?i:null,this.useApi=(o=e.useApi)!=null?o:!0,this.environment=(c=e.environment)!=null?c:"prod",this.apiUrl=(s=e.apiUrl)!=null?s:Me[this.environment],this.apiKey=(p=e.apiKey)!=null?p:"default",this.requestBody=e.requestBody,this.currentPlatform=e.platform,!this.useApi&&e.platform&&e.platform!=="maplibre")throw new Error("When useApi is false, only maplibre platform is supported. Google Maps and Mapbox require API usage.");let t=re(e);this.fitBoundsPadding={top:(g=(h=e.fitBoundsPadding)==null?void 0:h.top)!=null?g:t?0:50,bottom:(y=(m=e.fitBoundsPadding)==null?void 0:m.bottom)!=null?y:t?0:160,left:(d=(b=e.fitBoundsPadding)==null?void 0:b.left)!=null?d:t?0:50,right:(f=(u=e.fitBoundsPadding)==null?void 0:u.right)!=null?f:t?0:50};let r=Pe();this.state={center:[0,0],zoom:0,bounds:null,pendingBounds:null,tempBounds:null,properties:this.properties,primary:(l=this.primaryType)!=null?l:te,selectedPropertyId:this.selectedMarkerId,initialLoading:!0,isSearching:!1,firstCallDone:!1,filters:{checkIn:r.checkIn,checkOut:r.checkOut,numAdults:2,numRooms:1,...((M=e.initialLocationData)==null?void 0:M.currency)&&{currency:e.initialLocationData.currency}},activeLocation:{country:"",location_id:null,locationName:"",coordinates:[0,0]},isFlyToAnimating:!1,...e.state},this.callbacks=(x=e.callbacks)!=null?x:{},this.hasMapInstance(e)&&(this.adapter=this.createAdapter(e),this.isMapAttached=!0,this.refresh()),e.initialLocationData?this.initializeFromLocationData(e.initialLocationData):this.requestBody&&this.isMapAttached&&this.autoLoadProperties()}hasMapInstance(e){return!!("adapter"in e&&e.adapter||"mapInstance"in e&&e.mapInstance)}async initializeFromLocationData(e){if(!this.useApi){console.warn("initializeFromLocationData requires API usage. Set useApi to true.");return}try{let{city:t,country:r,query:a,currency:i}=e,o={filters:this.getFilters(),initial:!0};if(t&&r||r){let c=await fetch(`${this.apiUrl}/geo-lookup?country=${encodeURIComponent(r)}${t?`&city=${encodeURIComponent(t)}`:""}`);if(c.ok){let s=await c.json(),p=t;s.location_name&&s.path3_name&&s.location_name===s.path3_name&&(p=void 0),s.location_name&&(p=s.location_name);let h=s.path3_name||r;o={...o,city:p,country:h,location_id:s.location_id,longitude:s.longitude,latitude:s.latitude},this.setActiveLocation({city:p,country:h,location_id:s.location_id,locationName:p&&h?`${p}, ${h}`:h||"",coordinates:[s.latitude,s.longitude]}),this.setState({center:[s.latitude,s.longitude],zoom:12})}else this.handleError(new Error(`Geo mapping fetch failed: ${c.statusText}`),"initializeFromLocationData")}else a&&(o.query=a);this.requestBody=o,this.isMapAttached&&await this.autoLoadProperties()}catch(t){this.handleError(t,"initializeFromLocationData")}}async autoLoadProperties(){if(!this.useApi){console.warn("autoLoadProperties requires API usage. Set useApi to true.");return}if(!this.requestBody)return;let e={filters:this.getFilters(),initial:!0,...this.requestBody};await this.runPropertiesSearch({body:e,onError:t=>{var r,a;this.handleError(t,"autoLoadProperties"),(a=(r=this.callbacks).onPropertiesLoadError)==null||a.call(r,t)}})}attachMap(e,t){if(!this.useApi&&t.platform!=="maplibre")throw new Error("When useApi is false, only maplibre platform is supported. Google Maps and Mapbox require API usage.");if(this.isMapAttached&&(console.warn("Map is already attached. Destroying previous adapter."),this.adapter)){let a=this.adapter.getMarkerManager();a==null||a.destroy(),this.adapter.cleanup()}let r={...this.options,platform:t.platform,mapInstance:e,maplibregl:t.maplibregl,google:t.google,mapboxgl:t.mapboxgl,onMarkerClick:t.onMarkerClick};this.currentPlatform=t.platform,this.adapter=this.createAdapter(r),this.isMapAttached=!0,this.refresh(),this.requestBody&&!this.state.firstCallDone&&this.autoLoadProperties()}createAdapter(e){return xe(e)&&e.mapInstance?this.initializeAdapter(new R(e.mapInstance),{maplibregl:e.maplibregl,onMarkerClick:e.onMarkerClick}):re(e)&&e.mapInstance?this.initializeAdapter(new F(e.mapInstance),{google:e.google,onMarkerClick:e.onMarkerClick}):Le(e)&&e.mapInstance?this.initializeAdapter(new D(e.mapInstance),{mapboxgl:e.mapboxgl,onMarkerClick:e.onMarkerClick}):"adapter"in e&&e.adapter?e.adapter:null}initializeAdapter(e,t){var a;let r=(a=this.options.autoSelectOnClick)!=null?a:!0;return e.initialize({...t,onMarkerClick:i=>{var o;i.location&&this.flyMapTo(i.location.lon,i.location.lat,14),i.type!==this.primaryType&&this.setPrimaryType(i.type),r&&this.setSelectedMarker(i.tripadvisor_id===this.selectedMarkerId?null:i.tripadvisor_id),(o=t.onMarkerClick)==null||o.call(t,i)},onRefresh:()=>this.refresh(),onMapMoveEnd:i=>{this.state.tempBounds===null?(this.setTempBounds(i),this.setPendingBounds(null)):this.handleMapMoveEnd(i)}}),this.useApi&&e.setupImpressionTracking(()=>{ve(this.apiUrl,this.apiKey||"default",{platform:this.currentPlatform,environment:this.environment})}),e}_setProperties(e){var t,r;this.ensureAlive(),this.properties=[...e.filter(a=>{var i;return a.type==="Accommodation"?((i=a.pricing)==null?void 0:i.availability)!=="unavailable":!0})],this.updateState({properties:this.properties}),(r=(t=this.callbacks).onPropertiesChange)==null||r.call(t,e),this.refresh()}addProperty(e){var t,r;this.ensureAlive(),this.properties=[...this.properties,e],this.updateState({properties:this.properties}),(r=(t=this.callbacks).onPropertiesChange)==null||r.call(t,this.properties),this.refresh()}clearProperties(){var e,t;this.ensureAlive(),this.properties=[],this.updateState({properties:[]}),(t=(e=this.callbacks).onPropertiesChange)==null||t.call(e,[]),this.refresh()}setPrimaryType(e){var t,r;this.ensureAlive(),this.primaryType!==e&&(this.primaryType=e,this.updateState({primary:e}),(r=(t=this.callbacks).onPrimaryTypeChange)==null||r.call(t,e),this.refresh())}setSelectedMarker(e){var t,r;if(this.ensureAlive(),this.selectedMarkerId!==e){if(e!==null){let a=this.properties.find(i=>i.tripadvisor_id===e);a&&a.type!==this.primaryType&&this.setPrimaryType(a.type)}this.selectedMarkerId=e,this.updateState({selectedPropertyId:e}),(r=(t=this.callbacks).onSelectedPropertyChange)==null||r.call(t,e),this.refresh()}}getState(){return{...this.state}}handleError(e,t="MapFirstCore"){let r=e instanceof Error?e.message:String(e),a=e instanceof Error?e:new Error(r);console.error(`[${t}]`,r),this.callbacks.onError&&this.callbacks.onError(a,t)}updateState(e){this.state={...this.state,...e}}setState(e){var r,a,i,o,c,s,p,h,g,m,y,b,d,u,f,l;let t={...this.state};this.updateState(e),e.center!==void 0&&e.center!==t.center&&((a=(r=this.callbacks).onCenterChange)==null||a.call(r,e.center,this.state.zoom)),e.zoom!==void 0&&e.zoom!==t.zoom&&((o=(i=this.callbacks).onZoomChange)==null||o.call(i,e.zoom)),e.bounds!==void 0&&e.bounds!==t.bounds&&((s=(c=this.callbacks).onBoundsChange)==null||s.call(c,e.bounds)),e.pendingBounds!==void 0&&e.pendingBounds!==t.pendingBounds&&((h=(p=this.callbacks).onPendingBoundsChange)==null||h.call(p,e.pendingBounds)),e.filters!==void 0&&e.filters!==t.filters&&((m=(g=this.callbacks).onFiltersChange)==null||m.call(g,e.filters)),e.activeLocation!==void 0&&e.activeLocation!==t.activeLocation&&((b=(y=this.callbacks).onActiveLocationChange)==null||b.call(y,e.activeLocation)),e.initialLoading!==void 0&&e.initialLoading!==t.initialLoading&&((u=(d=this.callbacks).onLoadingStateChange)==null||u.call(d,e.initialLoading)),e.isSearching!==void 0&&e.isSearching!==t.isSearching&&((l=(f=this.callbacks).onSearchingStateChange)==null||l.call(f,e.isSearching))}setFilters(e){this.setState({filters:e})}setActiveLocation(e){this.setState({activeLocation:e})}setBounds(e){this.setState({bounds:e})}setPendingBounds(e){this.setState({pendingBounds:e})}setTempBounds(e){this.setState({tempBounds:e})}setLoading(e){this.setState({initialLoading:e})}setSearching(e){this.setState({isSearching:e})}setFlyToAnimating(e){this.setState({isFlyToAnimating:e})}handleMapMoveEnd(e){if(this.state.isFlyToAnimating){this.setState({isFlyToAnimating:!1,tempBounds:e,pendingBounds:null});return}let t=this.state.tempBounds;if(!t){this.setState({tempBounds:e,pendingBounds:e});return}let r=.01;Math.abs(e.sw.lat-t.sw.lat)>r||Math.abs(e.sw.lng-t.sw.lng)>r||Math.abs(e.ne.lat-t.ne.lat)>r||Math.abs(e.ne.lng-t.ne.lng)>r?this.setState({pendingBounds:e}):this.setState({pendingBounds:null})}flyMapTo(e,t,r,a=!0){if(this.ensureAlive(),this.setState({center:[t,e]}),typeof r=="number"&&this.setState({zoom:r}),!this.adapter)return;let i=this.adapter.getMap();if(i){if(this.currentPlatform==="google"){this.setFlyToAnimating(!1),i.setCenter({lat:t,lng:e}),r!==null&&typeof r=="number"&&i.setZoom(r!=null?r:13);return}if(a===!1){this.setFlyToAnimating(!1),i.jumpTo&&i.jumpTo({center:[e,t],...r!==null&&{zoom:r!=null?r:13}});return}this.setFlyToAnimating(!0),i.flyTo&&i.flyTo({center:[e,t],...r!==null&&{zoom:r!=null?r:13}})}}flyToPOIs(e,t,r=!0){var o,c;if(this.ensureAlive(),!this.adapter)return;let a=this.adapter.getMap();if(!a)return;let i=e;if((!i||i.length===0)&&(i=this.properties.filter(s=>s.location!==void 0&&(t!==void 0?s.type===t:!0)).map(s=>({lat:s.location.lat,lng:s.location.lon}))),!(!i||i.length===0)){if(i.length===1){let s=i[0];this.currentPlatform==="google"?(a.setCenter({lat:s.lat,lng:s.lng}),a.setZoom(13)):a.flyTo&&a.flyTo({center:[s.lng,s.lat],zoom:13})}else if(this.currentPlatform==="google"){let s=(c=(o=window.google)==null?void 0:o.maps)==null?void 0:c.LatLngBounds;if(s){let p=new s;i.forEach(h=>{p.extend({lat:h.lat,lng:h.lng})}),r&&this.setFlyToAnimating(!0),a.fitBounds(p,this.fitBoundsPadding)}}else if(a.fitBounds){let s=[[i[0].lng,i[0].lat],[i[0].lng,i[0].lat]];i.forEach(p=>{s[0][0]=Math.min(s[0][0],p.lng),s[0][1]=Math.min(s[0][1],p.lat),s[1][0]=Math.max(s[1][0],p.lng),s[1][1]=Math.max(s[1][1],p.lat)}),r&&this.setFlyToAnimating(!0),a.fitBounds(s,{padding:this.fitBoundsPadding,animate:r})}}}getFilters(){let e={...this.state.filters};return e.checkIn instanceof Date&&(e.checkIn=ee(e.checkIn)),e.checkOut instanceof Date&&(e.checkOut=ee(e.checkOut)),e}async loadProperties({fetchFn:e,onSuccess:t,onError:r}){this.ensureAlive(),this.setLoading(!0),this.setSearching(!0),this.clearProperties();try{let a=await e();if(this._setProperties(a),!this.primaryType&&a.length>0){let i=a.reduce((c,s)=>(c[s.type]=(c[s.type]||0)+1,c),{}),o=Object.entries(i).reduce((c,s)=>i[c[0]]>i[s[0]]?c:s)[0];this.setPrimaryType(o)}this.setState({firstCallDone:!0}),t==null||t(a)}catch(a){this.clearProperties(),r==null||r(a)}finally{this.setSearching(!1),this.setLoading(!1),this.setState({firstCallDone:!0})}}async pollForPricing({pollingLink:e,maxAttempts:t=15,delayMs:r=2e3,isCancelled:a,price:i,limit:o}){var g,m,y,b,d;if(this.ensureAlive(),!this.useApi)return console.warn("pollForPricing requires API usage. Set useApi to true."),{completed:!1};if(!e)return{completed:!1};let c=!1,s,p=this.getFilters();o&&(p.limit=o);let h={filters:p,pollingLink:e};for(let u=0;u<t;u++){if(a!=null&&a())return{completed:c,pollData:s};try{let f=await fetch(`${this.apiUrl}/ta-polling?pollingNumber=${u}`,{method:"POST",body:JSON.stringify(h),headers:{"Content-Type":"application/json"}});if(!f.ok)throw new _({message:`Poll failed: ${f.status}`,status:f.status});if(s=await f.json(),a!=null&&a())return{completed:c,pollData:s};let l=(m=(g=s==null?void 0:s.success)==null?void 0:g.results)!=null?m:[];if(l.length>0&&this.setProperties(M=>{let x=new Set(l.map(k=>k.tripadvisor_id)),L=M.filter(k=>k.type!=="Accommodation"||x.has(k.tripadvisor_id));return l.forEach(k=>{var C,v,P,T,$,j;if(!k.location)return;(v=(C=k.pricing)==null?void 0:C.offer)!=null&&v.price&&i&&(((T=(P=k.pricing)==null?void 0:P.offer)==null?void 0:T.price)<(i==null?void 0:i.min)||((j=($=k.pricing)==null?void 0:$.offer)==null?void 0:j.price)>(i==null?void 0:i.max))&&(k.pricing.availability="unavailable");let A=L.findIndex(ie=>ie.tripadvisor_id===k.tripadvisor_id);A>=0?L[A]=k:L.push(k)}),L}),(y=s==null?void 0:s.success)!=null&&y.isComplete){c=!0;break}}catch(f){this.handleError(f,"pollForPricing"),(d=(b=this.callbacks).onPropertiesLoadError)==null||d.call(b,f);break}u<t-1&&await new Promise(f=>setTimeout(f,r))}return{completed:c,pollData:s}}setProperties(e){let t=e(this.properties);this._setProperties(t)}mostCommonTypeFromProperties(e){let t=e.reduce((r,a)=>(r[a.type]=(r[a.type]||0)+1,r),{});return Object.entries(t).reduce((r,a)=>t[r[0]]>t[a[0]]?r:a)[0]}async runPropertiesSearch({body:e,beforeApplyProperties:t,smartFiltersClearable:r,onError:a}){var i,o,c,s,p,h,g;if(this.ensureAlive(),!this.useApi)return console.warn("runPropertiesSearch requires API usage. Set useApi to true."),a==null||a(new Error("API usage is disabled")),null;this.setState({firstCallDone:!1}),this.setSearching(!0),this.clearProperties();try{let m=await ae(`${this.apiUrl}/properties`,e);this.updateActiveLocationFromResponse(m);let y=null,b=30,d=m.filters.primary_type;if(t){let l=t(m);y=(i=l.price)!=null?i:null,b=(o=l.limit)!=null?o:30}let u=m.properties.some(l=>!!l.location),f=y?m.properties.map(l=>{var M;return(M=l.pricing)!=null&&M.offer?{...l,pricing:{...l.pricing,availability:l.pricing.offer.price&&(l.pricing.offer.price<y.min||l.pricing.offer.price>y.max)?"unavailable":l.pricing.availability}}:l}):m.properties;if(this._setProperties(f),u&&this.flyToPOIs(m.properties.filter(l=>!!l.location&&(m.filters.primary_type?l.type===m.filters.primary_type:!0)).map(l=>({lat:l.location.lat,lng:l.location.lon})),void 0,e.initial!==!0),m.filters.primary_type&&m.properties.filter(l=>{var M;return l.type===m.filters.primary_type&&(l.type==="Accommodation"?((M=l.pricing)==null?void 0:M.availability)!=="unavailable":!0)}).length>0)d=m.filters.primary_type,this.setPrimaryType(m.filters.primary_type);else if(m.properties.length>0){let l=this.mostCommonTypeFromProperties(m.properties);this.setPrimaryType(l),d=l}if(this.setState({firstCallDone:!0}),m.isComplete===!1&&m.pollingLink){let{completed:l,pollData:M}=await this.pollForPricing({pollingLink:m.pollingLink,...y&&{price:y},...b&&{limit:b}});if(l&&((c=M==null?void 0:M.success)!=null&&c.results)&&M.success.results.filter(x=>{var L;return x.type===m.filters.primary_type&&(x.type==="Accommodation"?((L=x.pricing)==null?void 0:L.availability)!=="unavailable":!0)}).length===0&&d&&d!==m.filters.primary_type){let x=this.mostCommonTypeFromProperties(m.properties);this.setPrimaryType(x)}}return u||(m.properties.some(l=>!!l.location)?this.flyToPOIs(m.properties.filter(l=>!!l.location&&(m.filters.primary_type?l.type===m.filters.primary_type:!0)).map(l=>({lat:l.location.lat,lng:l.location.lon})),void 0,e.initial!==!0):(s=m.filters.location)!=null&&s.latitude&&((p=m.filters.location)!=null&&p.longitude)&&this.flyMapTo(m.filters.location.longitude,m.filters.location.latitude,12,e.initial!==!0)),m}catch(m){return this.handleError(m,"runPropertiesSearch"),a==null||a(m),(g=(h=this.callbacks).onPropertiesLoadError)==null||g.call(h,m),this.clearProperties(),this.setState({firstCallDone:!0}),null}finally{this.setSearching(!1),this.setState({firstCallDone:!0})}}async performBoundsSearch(){var i;if(this.ensureAlive(),!this.useApi)return console.warn("performBoundsSearch requires API usage. Set useApi to true."),null;if(!this.state.pendingBounds)return null;let e=this.getFilters(),t={bounds:this.state.pendingBounds,filters:e},r=(i=e==null?void 0:e.price)!=null?i:void 0,a=await this.runPropertiesSearch({body:t,beforeApplyProperties:()=>({price:r!=null?r:null})});return a&&(this.setBounds(this.state.pendingBounds),this.setTempBounds(this.state.pendingBounds),this.setPendingBounds(null)),a}updateActiveLocationFromResponse(e){var c,s,p,h;let t=(c=e.location_id)!=null?c:null,r=(p=(s=e.filters.location)==null?void 0:s.city)!=null?p:void 0,a=((h=e.filters.location)==null?void 0:h.country)||"",i=e.filters.location?[e.filters.location.latitude,e.filters.location.longitude]:void 0;if(!i)return;let o=this.state.activeLocation;(t!==(o==null?void 0:o.location_id)||r!==(o==null?void 0:o.city)||a!==(o==null?void 0:o.country))&&this.setActiveLocation({city:r,country:a,location_id:t,locationName:r&&a?`${r}, ${a}`:a||"",coordinates:i})}async runSmartFilterSearch({query:e,filters:t,onProcessFilters:r,onError:a}){if(this.ensureAlive(),!this.useApi)return console.warn("runSmartFilterSearch requires API usage. Set useApi to true."),a==null||a(new Error("API usage is disabled")),null;let i=this.getFilters(),o=this.getState();if(t&&t.length>0){let s=new Set,p=new Set,h,g,m,y,b,d;t.forEach(u=>{var f,l,M;switch(u.type){case"amenity":s.add(u.value);break;case"hotelStyle":p.add(u.value);break;case"priceRange":u.priceRange&&(h={min:u.priceRange.min,max:(f=u.priceRange.max)!=null?f:0});break;case"minRating":g=(l=u.numericValue)!=null?l:Number(u.value);break;case"starRating":m=(M=u.numericValue)!=null?M:Number(u.value);break;case"primary_type":y=u.propertyType;break;case"transformed_query":b=u.value;break;case"selected_restaurant_price_levels":d=u.priceLevels;break}}),i={...i,...s.size>0&&{amenities:Array.from(s)},...p.size>0&&{hotelStyle:Array.from(p)},...h&&{price:h},...g!==void 0&&{minRating:g},...m!==void 0&&{starRating:m},...y&&{primary_type:y},...b&&{transformed_query:b},...d&&{selected_restaurant_price_levels:d}}}else e||(i.minRating=4);let c={filters:i,...e&&{query:e},...o.bounds?{bounds:o.bounds}:o.activeLocation.location_id?{location_id:o.activeLocation.location_id}:o.activeLocation.coordinates?{latitude:o.activeLocation.coordinates[0],longitude:o.activeLocation.coordinates[1]}:{}};return this.runPropertiesSearch({body:c,beforeApplyProperties:r?s=>{var h,g;let p=r(s.filters,s.location_id);return{price:(h=p.price)!=null?h:null,limit:(g=p.limit)!=null?g:30}}:void 0,smartFiltersClearable:!!e,onError:a})}getClusters(){return this.ensureAlive(),[...this.clusterItems]}setUseApi(e,t=!0){this.ensureAlive(),this.useApi=e,!e&&this.currentPlatform&&this.currentPlatform!=="maplibre"&&console.warn("When useApi is false, only maplibre platform is supported. Please switch to maplibre."),e||this.clearProperties(),e&&t&&(this.options.initialLocationData?this.initializeFromLocationData(this.options.initialLocationData):this.requestBody&&this.isMapAttached&&this.autoLoadProperties())}setApiKey(e){this.ensureAlive();let t=this.apiKey;this.apiKey=e||"default",t!==this.apiKey&&this.isMapAttached&&(this.refresh(),this.useApi&&(this.options.initialLocationData?this.initializeFromLocationData(this.options.initialLocationData):this.requestBody&&this.autoLoadProperties()))}getApiKey(){return this.apiKey}refresh(){var a,i,o;if(this.ensureAlive(),!this.adapter)return;let e=this.safeExtractViewState(),t=this.resolvePrimaryType();this.clusterItems=H({primaryType:t,markers:this.properties,map:this.adapter,selectedMarkerId:this.selectedMarkerId,zoom:(a=e==null?void 0:e.zoom)!=null?a:0}),this.adapter.getMarkerManager().render(this.clusterItems,t,this.selectedMarkerId),(o=(i=this.options).onClusterUpdate)==null||o.call(i,this.clusterItems,e)}destroy(){this.destroyed||(this.adapter&&(this.adapter.getMarkerManager().destroy(),this.adapter.cleanup()),this.clusterItems=[],this.properties=[],this.destroyed=!0,this.isMapAttached=!1)}resolvePrimaryType(){var e,t,r;return(r=(t=this.primaryType)!=null?t:(e=this.properties.find(a=>a.type))==null?void 0:e.type)!=null?r:te}safeExtractViewState(){if(!this.adapter)return null;try{return J(this.adapter)}catch{return null}}ensureAlive(){if(this.destroyed)throw new Error("MapFirstCore instance has been destroyed")}};function xe(n){return n.platform==="maplibre"}function re(n){return n.platform==="google"}function Le(n){return n.platform==="mapbox"}0&&(module.exports={MapFirstCore,PropertiesFetchError,convertToApiFilters,fetchProperties,processApiFilters});
|
|
1
|
+
"use strict";var N=Object.defineProperty;var ne=Object.getOwnPropertyDescriptor;var se=Object.getOwnPropertyNames;var oe=Object.prototype.hasOwnProperty;var pe=(n,e)=>{for(var t in e)N(n,t,{get:e[t],enumerable:!0})},le=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of se(e))!oe.call(n,a)&&a!==t&&N(n,a,{get:()=>e[a],enumerable:!(r=ne(e,a))||r.enumerable});return n};var ce=n=>le(N({},"__esModule",{value:!0}),n);var Ae={};pe(Ae,{MapFirstCore:()=>z,PropertiesFetchError:()=>_,convertToApiFilters:()=>Q,fetchProperties:()=>ae,processApiFilters:()=>Y});module.exports=ce(Ae);function O(n,{insertAt:e}={}){if(!n||typeof document=="undefined")return;let t=document.head||document.getElementsByTagName("head")[0],r=document.createElement("style");r.type="text/css",e==="top"&&t.firstChild?t.insertBefore(r,t.firstChild):t.appendChild(r),r.styleSheet?r.styleSheet.cssText=n:r.appendChild(document.createTextNode(n))}O(`.mapfirst-marker-root{display:flex;z-index:20;flex-direction:column;align-items:center;pointer-events:auto}.mapfirst-marker-pill{border:2px solid;border-radius:999px;padding:8px;font-size:16px;font-weight:600;font-family:system-ui,-apple-system,sans-serif;box-shadow:0 4px 6px #6b728080;display:flex;align-items:center;justify-content:center;position:relative;transition:transform .2s;transform-origin:center bottom}.mapfirst-marker-pill-pending{background:#ffffff80;backdrop-filter:blur(4px);border-color:transparent;cursor:default}.mapfirst-marker-pill-active{background:#012b11;border-color:#fff;color:#fff;cursor:pointer}.mapfirst-marker-pill-active.mapfirst-marker-non-primary{background:#ffffffb3;border-color:#03852e80;color:#03852e80;padding:4px}.mapfirst-marker-pill-active.mapfirst-marker-selected{background:#fff;border-color:#03852e;color:#03852e;transform:scale(1.2)}.mapfirst-marker-pill-active:hover{transform:scale(1.2)}.mapfirst-marker-badge{position:absolute;top:-12px;right:-20px}.mapfirst-marker-award-container{position:relative;width:32px;height:32px}.mapfirst-marker-award-back{position:absolute;stroke:#f5f5f5;stroke-width:2px}.mapfirst-marker-award-dot{position:absolute;top:6.2px;left:6.3px;width:18.5px;height:18.5px;border-radius:50%;z-index:1}.mapfirst-marker-award-dot-type-0{background:#ffef0e}.mapfirst-marker-award-dot-type-1{background:#01ea5b}.mapfirst-marker-award-front{position:relative;z-index:2;color:#012b11}.mapfirst-marker-rating-badge{display:flex;align-items:center;justify-content:center;border-radius:999px;background:#03852e;color:#fff;font-size:12px;line-height:1;box-shadow:0 2px 4px #0003;padding:2px 6px;border:2px solid #ffffff;font-weight:400}.mapfirst-marker-content{display:flex;align-items:center}.mapfirst-dot-marker-container{display:flex;z-index:10;align-items:center;justify-content:center;pointer-events:auto}.mapfirst-dot-marker-button{width:20px;height:20px;border-radius:999px;border:2px solid #ffffff;box-shadow:0 2px 4px #6b728066;transition:transform .2s;outline:none;transform-origin:center center}.mapfirst-dot-marker-button-pending{background:#d1d5db;cursor:default}.mapfirst-dot-marker-button-active{background:#012b11;cursor:pointer}.mapfirst-dot-marker-button-active.mapfirst-dot-marker-non-primary{background:#ffffffb3;border-color:#03852e33}.mapfirst-dot-marker-button-active.mapfirst-dot-marker-selected{background:#fff;border-color:#03852e}.mapfirst-dot-marker-button-active:hover{transform:scale(1.2)}.mapfirst-dot-marker-button-active:focus{outline:2px solid #ffffff;outline-offset:2px}
|
|
2
|
+
`);function q(n,e,t,r){var g,m,y;if(typeof document=="undefined")return null;let a=n.marker,i=a.type===e,o=t===a.tripadvisor_id,s=a.type==="Accommodation"&&((m=(g=a.pricing)==null?void 0:g.offer)==null?void 0:m.availability)!=="available",p=document.createElement("div");p.className="mapfirst-dot-marker-container",p.style.zIndex=o?"20":i?"3":"1";let h=document.createElement("div");return h.className=s?"mapfirst-dot-marker-button mapfirst-dot-marker-button-pending":`mapfirst-dot-marker-button mapfirst-dot-marker-button-active${o?" mapfirst-dot-marker-selected":i?"":" mapfirst-dot-marker-non-primary"}`,h.title=(y=a.name)!=null?y:String(a.tripadvisor_id),h.addEventListener("click",b=>{b.stopPropagation(),s||r==null||r(a)}),p.appendChild(h),p}var me='<svg viewBox="0 0 24 24" width="32" height="32" fill="currentColor"><path d="M12 3.953a7.442 7.442 0 1 0 .001 14.884A7.442 7.442 0 0 0 12 3.953m0 14.05a6.61 6.61 0 1 1 0-13.218 6.61 6.61 0 0 1 0 13.219M10.343 11.9a.91.91 0 1 1-1.821 0 .91.91 0 0 1 1.821 0m5.134 0a.91.91 0 1 1-1.821 0 .91.91 0 0 1 1.82 0m.82-1.897.84-.913h-1.863A5.8 5.8 0 0 0 12 8.08a5.77 5.77 0 0 0-3.27 1.008H6.862l.84.913a2.567 2.567 0 1 0 3.475 3.78l.823.896.823-.895a2.568 2.568 0 1 0 3.474-3.78m-6.865 3.634a1.738 1.738 0 1 1 0-3.476 1.738 1.738 0 0 1 0 3.476M12 11.85c0-1.143-.832-2.124-1.929-2.543A5 5 0 0 1 12 8.92a5 5 0 0 1 1.928.386c-1.096.42-1.927 1.4-1.927 2.543m2.566 1.787a1.738 1.738 0 1 1 .001-3.476 1.738 1.738 0 0 1 0 3.476m-8.456 3.719s-.377-.946-1.396-1.903c-1.02-.957-2.303-1.132-2.303-1.132s.457 1.02 1.54 2.04c1.086 1.017 2.159.995 2.159.995m2.568 1.41s-.524-.511-1.479-.883-1.861-.191-1.861-.191.598.54 1.615.935c1.016.397 1.725.139 1.725.139m2.493.505s-.545-.224-1.357-.196-1.415.47-1.415.47.608.222 1.473.193 1.3-.467 1.3-.467m-6.186-4.203s-.175-1.008-.974-2.154c-.8-1.147-2.015-1.578-2.015-1.578s.238 1.098 1.089 2.319c.85 1.22 1.9 1.413 1.9 1.413m-1.003-3.071s.195-1.021-.134-2.393c-.328-1.371-1.294-2.21-1.294-2.21s-.17 1.128.18 2.589c.35 1.46 1.248 2.014 1.248 2.014"></path><path d="M17.887 17.355s.377-.946 1.396-1.903c1.02-.957 2.303-1.132 2.303-1.132s-.457 1.02-1.54 2.04c-1.086 1.017-2.159.995-2.159.995m-2.567 1.41s.524-.511 1.479-.883 1.861-.191 1.861-.191-.598.54-1.615.935c-1.016.397-1.725.139-1.725.139m-2.493.505s.545-.224 1.357-.196 1.415.47 1.415.47-.608.222-1.473.193-1.3-.467-1.3-.467m6.186-4.203s.175-1.008.974-2.154c.8-1.147 2.015-1.578 2.015-1.578s-.238 1.098-1.089 2.319c-.85 1.22-1.9 1.413-1.9 1.413m1.003-3.071s-.195-1.021.133-2.393c.33-1.371 1.293-2.21 1.293-2.21s.17 1.128-.18 2.589c-.349 1.46-1.246 2.014-1.246 2.014M12 20.047a.413.413 0 1 0 0-.827.413.413 0 0 0 0 .827"></path></svg>',de='<svg viewBox="0 0 24 24" width="32" height="32"><path d="M12 3.953a7.442 7.442 0 1 0 .001 14.884A7.442 7.442 0 0 0 12 3.953m0 14.05a6.61 6.61 0 1 1 0-13.218 6.61 6.61 0 0 1 0 13.219M10.343 11.9a.91.91 0 1 1-1.821 0 .91.91 0 0 1 1.821 0m5.134 0a.91.91 0 1 1-1.821 0 .91.91 0 0 1 1.82 0m.82-1.897.84-.913h-1.863A5.8 5.8 0 0 0 12 8.08a5.77 5.77 0 0 0-3.27 1.008H6.862l.84.913a2.567 2.567 0 1 0 3.475 3.78l.823.896.823-.895a2.568 2.568 0 1 0 3.474-3.78m-6.865 3.634a1.738 1.738 0 1 1 0-3.476 1.738 1.738 0 0 1 0 3.476M12 11.85c0-1.143-.832-2.124-1.929-2.543A5 5 0 0 1 12 8.92a5 5 0 0 1 1.928.386c-1.096.42-1.927 1.4-1.927 2.543m2.566 1.787a1.738 1.738 0 1 1 .001-3.476 1.738 1.738 0 0 1 0 3.476m-8.456 3.719s-.377-.946-1.396-1.903c-1.02-.957-2.303-1.132-2.303-1.132s.457 1.02 1.54 2.04c1.086 1.017 2.159.995 2.159.995m2.568 1.41s-.524-.511-1.479-.883-1.861-.191-1.861-.191.598.54 1.615.935c1.016.397 1.725.139 1.725.139m2.493.505s-.545-.224-1.357-.196-1.415.47-1.415.47.608.222 1.473.193 1.3-.467 1.3-.467m-6.186-4.203s-.175-1.008-.974-2.154c-.8-1.147-2.015-1.578-2.015-1.578s.238 1.098 1.089 2.319c.85 1.22 1.9 1.413 1.9 1.413m-1.003-3.071s.195-1.021-.134-2.393c-.328-1.371-1.294-2.21-1.294-2.21s-.17 1.128.18 2.589c.35 1.46 1.248 2.014 1.248 2.014"></path><path d="M17.887 17.355s.377-.946 1.396-1.903c1.02-.957 2.303-1.132 2.303-1.132s-.457 1.02-1.54 2.04c-1.086 1.017-2.159.995-2.159.995m-2.567 1.41s.524-.511 1.479-.883 1.861-.191 1.861-.191-.598.54-1.615.935c-1.016.397-1.725.139-1.725.139m-2.493.505s.545-.224 1.357-.196 1.415.47 1.415.47-.608.222-1.473.193-1.3-.467-1.3-.467m6.186-4.203s.175-1.008.974-2.154c.8-1.147 2.015-1.578 2.015-1.578s-.238 1.098-1.089 2.319c-.85 1.22-1.9 1.413-1.9 1.413m1.003-3.071s-.195-1.021.133-2.393c.33-1.371 1.293-2.21 1.293-2.21s.17 1.128-.18 2.589c-.349 1.46-1.246 2.014-1.246 2.014M12 20.047a.413.413 0 1 0 0-.827.413.413 0 0 0 0 .827"></path></svg>',ue='<svg viewBox="0 0 24 24" width="20" height="20" fill="currentColor"><path fill-rule="evenodd" clip-rule="evenodd" d="M14.051 6.549v.003l1.134 1.14 3.241-3.25.003-.002 1.134 1.136-3.243 3.252 1.134 1.14a1 1 0 0 0 .09-.008c.293-.05.573-.324.72-.474l.005-.006 2.596-2.603L22 8.016l-2.597 2.604a3.73 3.73 0 0 1-1.982 1.015 4.3 4.3 0 0 1-3.162-.657l-.023-.016-.026-.018-1.366 1.407 8.509 8.512L20.219 22l-.002-.002-6.654-6.663-2.597 2.76-7.3-7.315C1.967 8.948 1.531 6.274 2.524 4.198c.241-.504.566-.973.978-1.386l8.154 8.416 1.418-1.423-.039-.045c-.858-1.002-1.048-2.368-.62-3.595a4.15 4.15 0 0 1 .983-1.561L16 2l1.135 1.138-2.598 2.602-.047.045c-.16.151-.394.374-.433.678zM3.809 5.523c-.362 1.319-.037 2.905 1.06 4.103L10.93 15.7l1.408-1.496zM2.205 20.697 3.34 21.84l4.543-4.552-1.135-1.143z"/></svg>',he='<svg viewBox="0 0 24 24" width="20" height="20" fill="currentColor"><path fill-rule="evenodd" clip-rule="evenodd" d="M7.56 7.5H3.75a.25.25 0 0 0-.25.25v10c0 .138.112.25.25.25h16.5a.25.25 0 0 0 .25-.25v-10a.25.25 0 0 0-.25-.25h-3.81l-2-2H9.56zM8.94 4h6.12l2 2h3.19c.966 0 1.75.784 1.75 1.75v10a1.75 1.75 0 0 1-1.75 1.75H3.75A1.75 1.75 0 0 1 2 17.75v-10C2 6.784 2.784 6 3.75 6h3.19z"/><path fill-rule="evenodd" clip-rule="evenodd" d="M12 9.25a2.75 2.75 0 1 0 0 5.5 2.75 2.75 0 0 0 0-5.5M7.75 12a4.25 4.25 0 1 1 8.5 0 4.25 4.25 0 0 1-8.5 0"/></svg>';function G(n,e,t,r){var b,d,u,f,l,M,x,L;if(typeof document=="undefined")return null;let a=n.marker,i=a.type===e,o=t===a.tripadvisor_id,c=a.type==="Accommodation",s=(d=(b=a.pricing)==null?void 0:b.offer)==null?void 0:d.displayPrice,p=c&&!s,h=(()=>{if(a.rating===void 0||a.rating===null)return null;let k=typeof a.rating=="number"?a.rating:Number(a.rating);return Number.isNaN(k)||k<=0?null:k.toFixed(1)})(),g=document.createElement("div");g.className="mapfirst-marker-root",g.style.zIndex=o?"20":i?"12":"11";let m=document.createElement("div");if(m.className=p?"mapfirst-marker-pill mapfirst-marker-pill-pending":`mapfirst-marker-pill mapfirst-marker-pill-active${o?" mapfirst-marker-selected":i?"":" mapfirst-marker-non-primary"}`,m.title=(u=a.name)!=null?u:String(a.tripadvisor_id),!p&&((f=a.awards)!=null&&f.length||h)){let k=document.createElement("div");if(k.className="mapfirst-marker-badge",i||(k.style.opacity="0.2"),k.className="mapfirst-marker-badge",(l=a.awards)!=null&&l.length&&a.awards[0].type){let A=document.createElement("div");A.className="mapfirst-marker-award-container";let C=document.createElement("div");C.className="mapfirst-marker-award-back",C.innerHTML=de;let v=document.createElement("div");v.className=`mapfirst-marker-award-dot mapfirst-marker-award-dot-type-${a.awards[0].type}`;let P=document.createElement("div");P.className="mapfirst-marker-award-front",P.innerHTML=me,A.appendChild(C),A.appendChild(v),A.appendChild(P),k.appendChild(A)}else h&&(k.className="mapfirst-marker-badge mapfirst-marker-rating-badge",k.textContent=h);m.appendChild(k)}let y=document.createElement("span");return y.className="mapfirst-marker-content",c?y.textContent=(L=(x=(M=a.pricing)==null?void 0:M.offer)==null?void 0:x.displayPrice)!=null?L:"\u2014":a.type==="Eat & Drink"?y.innerHTML=ue:a.type==="Attraction"&&(y.innerHTML=he),m.appendChild(y),m.addEventListener("click",k=>{k.stopPropagation(),p||r==null||r(a)}),g.appendChild(m),g}function V(n,e,t,r){let a=n;a.style.zIndex=t?"20":e?"12":"11";let i=a.querySelector(".mapfirst-marker-pill");i&&(r?i.className="mapfirst-marker-pill mapfirst-marker-pill-pending":i.className=`mapfirst-marker-pill mapfirst-marker-pill-active${t?" mapfirst-marker-selected":e?"":" mapfirst-marker-non-primary"}`);let o=a.querySelector(".mapfirst-marker-badge");o instanceof HTMLElement&&(o.style.opacity=!e&&!t?"0.2":"")}function K(n,e,t,r){let a=n;a.style.zIndex=t?"20":e?"3":"1";let i=a.querySelector(".mapfirst-dot-marker-button");i&&(r?i.className="mapfirst-dot-marker-button mapfirst-dot-marker-button-pending":i.className=`mapfirst-dot-marker-button mapfirst-dot-marker-button-active${t?" mapfirst-dot-marker-selected":e?"":" mapfirst-dot-marker-non-primary"}`)}function U(n){let e=n.match(/^(?:primary|dot)-(\d+)-/);return e?parseInt(e[1],10):null}var I=class{constructor(e,t){this.markerCache=new Map;this.primaryType="Accommodation";this.selectedMarkerId=null;this.mapInstance=e,this.onMarkerClick=t}render(e,t,r){var i,o,c,s;t&&t!==this.primaryType&&(this.primaryType=t),r!==void 0&&(this.selectedMarkerId=r);let a=new Set(e.map(p=>p.key));for(let[p,h]of this.markerCache.entries())a.has(p)||(this.removeMarkerFromMap(h.marker),this.markerCache.delete(p));for(let p of e){let h=fe(p.marker.location);if(!h)continue;let g=this.markerCache.get(p.key);if(g)try{this.updateMarkerPosition(g.marker,h)}catch{this.removeMarkerFromMap(g.marker),this.markerCache.delete(p.key),this.createAndAddMarker(p,h)}else{let m=p.marker.tripadvisor_id,y,b;for(let[d,u]of this.markerCache.entries())if(U(d)===m&&u.kind===p.kind){y=u,b=d;break}if(y&&b){let d=p.marker.type===this.primaryType,u=this.selectedMarkerId===p.marker.tripadvisor_id,f=p.marker.type==="Accommodation",l=p.kind==="primary"?f&&!((o=(i=p.marker.pricing)==null?void 0:i.offer)!=null&&o.displayPrice):f&&((s=(c=p.marker.pricing)==null?void 0:c.offer)==null?void 0:s.availability)!=="available",M=this.getMarkerElement(y.marker);M&&(p.kind==="primary"?V(M,d,u,l):K(M,d,u,l)),this.updateMarkerZIndex(y.marker,p,d,u),this.markerCache.delete(b),this.markerCache.set(p.key,y);try{this.updateMarkerPosition(y.marker,h)}catch{}}else this.createAndAddMarker(p,h)}}}destroy(){for(let e of this.markerCache.values())this.removeMarkerFromMap(e.marker);this.markerCache.clear()}createAndAddMarker(e,t){let r=e.kind==="primary"?G(e,this.primaryType,this.selectedMarkerId,this.onMarkerClick):q(e,this.primaryType,this.selectedMarkerId,this.onMarkerClick);if(!r)return;let a=e.marker.type===this.primaryType,i=this.selectedMarkerId===e.marker.tripadvisor_id;try{let o=this.createMarker(r,t,e,a,i);o&&this.markerCache.set(e.key,{key:e.key,marker:o,kind:e.kind,parentId:e.kind==="dot"?e.parentId:void 0})}catch(o){console.error("Error creating marker",o)}}updateMarkerZIndex(e,t,r,a){}};function fe(n){return typeof(n==null?void 0:n.lon)!="number"||typeof(n==null?void 0:n.lat)!="number"||Number.isNaN(n.lon)||Number.isNaN(n.lat)?null:{lon:n.lon,lat:n.lat}}var w=class extends I{constructor(e){var t;super(e.mapInstance,e.onMarkerClick),this.MarkerCtor=(t=e.maplibregl)==null?void 0:t.Marker}render(e,t,r){this.MarkerCtor&&super.render(e,t,r)}createMarker(e,t,r){return this.MarkerCtor?new this.MarkerCtor({element:e,anchor:r.kind==="primary"?"bottom":"center"}).setLngLat([t.lon,t.lat]).addTo(this.mapInstance):null}removeMarkerFromMap(e){try{e.remove()}catch{}}updateMarkerPosition(e,t){e.setLngLat([t.lon,t.lat])}getMarkerElement(e){return e.getElement()}};var B=class extends I{constructor(e){super(e.mapInstance,e.onMarkerClick),this.google=e.google}render(e,t,r){var a,i;if(!((i=(a=this.google)==null?void 0:a.marker)!=null&&i.AdvancedMarkerElement)){console.warn("AdvancedMarkerElement not available");return}super.render(e,t,r)}createMarker(e,t,r,a,i){var c,s;if(!((s=(c=this.google)==null?void 0:c.marker)!=null&&s.AdvancedMarkerElement))return null;let o=r.kind==="primary"?i?20:a?12:11:i?20:a?3:1;return new this.google.marker.AdvancedMarkerElement({map:this.mapInstance,position:{lat:t.lat,lng:t.lon},content:e,zIndex:o})}removeMarkerFromMap(e){try{e.map=null}catch(t){console.error("Error removing marker",t)}}updateMarkerPosition(e,t){e.position={lat:t.lat,lng:t.lon}}getMarkerElement(e){let t=e.content;return t instanceof HTMLElement?t:null}updateMarkerZIndex(e,t,r,a){let i=t.kind==="primary"?a?20:r?12:11:a?20:r?3:1;e.zIndex=i}};var E=class extends I{constructor(e){var t;super(e.mapInstance,e.onMarkerClick),this.MarkerCtor=(t=e.mapboxgl)==null?void 0:t.Marker}render(e,t,r){this.MarkerCtor&&super.render(e,t,r)}createMarker(e,t,r){return this.MarkerCtor?new this.MarkerCtor({element:e,anchor:r.kind==="primary"?"bottom":"center"}).setLngLat([t.lon,t.lat]).addTo(this.mapInstance):null}removeMarkerFromMap(e){try{e.remove()}catch{}}updateMarkerPosition(e,t){e.setLngLat([t.lon,t.lat])}getMarkerElement(e){return e.getElement()}};var S=class{constructor(e){this.map=e}getMap(){return this.map}setupImpressionTracking(e){if(typeof window=="undefined"||!window.IntersectionObserver)return;let t=this.getContainer();if(!t)return;let r=new IntersectionObserver(o=>{o.forEach(c=>{c.isIntersecting&&(e(),r.disconnect())})},{threshold:.1});r.observe(t);let a=()=>r.disconnect(),i=this.cleanup.bind(this);this.cleanup=()=>{a(),i()}}};var R=class extends S{constructor(t){super(t);this.cleanupFns=[]}initialize(t){return this.markerManager=new w({mapInstance:this.map,maplibregl:t.maplibregl,onMarkerClick:t.onMarkerClick}),t.onRefresh&&this.attachEventListeners(t.onRefresh),t.onMapMoveEnd&&this.attachBoundsTracking(t.onMapMoveEnd),this.markerManager}attachBoundsTracking(t){if(!this.map||typeof this.map.on!="function")return;let r=()=>{let i=this.getMapBounds();t(i)},a=()=>{let i=this.getMapBounds();t(i)};this.map.loaded&&this.map.loaded()?a():(this.map.once("load",a),this.cleanupFns.push(()=>{typeof this.map.off=="function"&&this.map.off("load",a)})),this.map.on("moveend",r),this.cleanupFns.push(()=>{typeof this.map.off=="function"&&this.map.off("moveend",r)})}attachEventListeners(t){if(!this.map||typeof this.map.on!="function")return;["move","zoom","dragend","pitch","rotate"].forEach(a=>{this.map.on(a,t),this.cleanupFns.push(()=>{typeof this.map.off=="function"&&this.map.off(a,t)})})}getMarkerManager(){return this.markerManager}getContainer(){var t,r;return((r=(t=this.map)==null?void 0:t.getContainer)==null?void 0:r.call(t))||null}cleanup(){for(let t of this.cleanupFns)try{t()}catch{}this.cleanupFns.length=0}getMap(){return this.map}getCenter(){let t=this.map.getCenter();return{lng:t.lng,lat:t.lat}}getZoom(){return this.map.getZoom()}getBearing(){return this.map.getBearing()}getPitch(){return this.map.getPitch()}getMapBounds(){let t=this.map.getBounds(),r=t.getSouthWest(),a=t.getNorthEast();return{sw:{lat:r.lat,lng:r.lng},ne:{lat:a.lat,lng:a.lng}}}project(t){return this.map.project({lng:t[0],lat:t[1]})}on(t,r){this.map.on(t,r)}off(t,r){this.map.off(t,r)}resize(){this.map.resize()}remove(){this.cleanup(),this.map.remove()}};var F=class extends S{constructor(t){super(t);this.cleanupFns=[];this.initializeOverlayView()}initialize(t){return this.markerManager=new B({mapInstance:this.map,google:t.google,onMarkerClick:t.onMarkerClick}),t.onRefresh&&this.attachEventListeners(t.onRefresh),t.onMapMoveEnd&&this.attachBoundsTracking(t.onMapMoveEnd,t.google),this.markerManager}attachBoundsTracking(t,r){if(!this.map)return;let a=()=>{let o=this.getMapBounds();t(o)};a();let i=r.event.addListener(this.map,"idle",a);this.cleanupFns.push(()=>{r.event.removeListener(i)})}attachEventListeners(t){let r=["center_changed","zoom_changed","drag","heading_changed","tilt_changed"],a=[];r.forEach(i=>{let o=this.map.addListener(i,t);a.push(o)}),this.cleanupFns.push(()=>{a.forEach(i=>{try{i.remove()}catch{}})})}getMarkerManager(){return this.markerManager}getContainer(){var t,r;return((r=(t=this.map)==null?void 0:t.getDiv)==null?void 0:r.call(t))||null}cleanup(){for(let t of this.cleanupFns)try{t()}catch{}this.cleanupFns.length=0}initializeOverlayView(){var a;let t=(a=globalThis.google)==null?void 0:a.maps;if(!t)return;let r=t.OverlayView;r&&(this.overlayView=new r,this.overlayView.draw=function(){},this.overlayView.setMap(this.map))}getMap(){return this.map}getCenter(){let t=this.map.getCenter();return t?{lng:t.lng(),lat:t.lat()}:{lng:0,lat:0}}getZoom(){var t;return(t=this.map.getZoom())!=null?t:0}getBearing(){var t;return(t=this.map.getHeading())!=null?t:0}getPitch(){var t;return(t=this.map.getTilt())!=null?t:0}getMapBounds(){let t=this.map.getBounds();if(!t)return{sw:{lat:0,lng:0},ne:{lat:0,lng:0}};let r=t.getSouthWest(),a=t.getNorthEast();return{sw:{lat:r.lat(),lng:r.lng()},ne:{lat:a.lat(),lng:a.lng()}}}project(t){var c;if(!this.overlayView)return{x:0,y:0};let r=this.overlayView.getProjection();if(!r)return{x:0,y:0};let a=(c=globalThis.google)==null?void 0:c.maps;if(!a)return{x:0,y:0};let i=new a.LatLng(t[1],t[0]),o=r.fromLatLngToContainerPixel(i);return o?{x:o.x,y:o.y}:{x:0,y:0}}on(t,r){this.map.addListener(t,r)}off(t,r){var i;let a=(i=globalThis.google)==null?void 0:i.maps;a!=null&&a.event&&a.event.clearListeners(this.map,t)}resize(){var r;let t=(r=globalThis.google)==null?void 0:r.maps;t!=null&&t.event&&t.event.trigger(this.map,"resize")}remove(){this.cleanup(),this.overlayView&&(this.overlayView.setMap(null),this.overlayView=null)}};var D=class extends S{constructor(t){super(t);this.cleanupFns=[]}initialize(t){return this.markerManager=new E({mapInstance:this.map,mapboxgl:t.mapboxgl,onMarkerClick:t.onMarkerClick}),t.onRefresh&&this.attachEventListeners(t.onRefresh),t.onMapMoveEnd&&this.attachBoundsTracking(t.onMapMoveEnd),this.markerManager}attachBoundsTracking(t){if(!this.map||typeof this.map.on!="function")return;let r=()=>{let i=this.getMapBounds();t(i)},a=()=>{let i=this.getMapBounds();t(i)};this.map.loaded&&this.map.loaded()?a():(this.map.once("load",a),this.cleanupFns.push(()=>{typeof this.map.off=="function"&&this.map.off("load",a)})),this.map.on("moveend",r),this.cleanupFns.push(()=>{typeof this.map.off=="function"&&this.map.off("moveend",r)})}attachEventListeners(t){if(!this.map||typeof this.map.on!="function")return;["move","zoom","dragend","pitch","rotate"].forEach(a=>{this.map.on(a,t),this.cleanupFns.push(()=>{typeof this.map.off=="function"&&this.map.off(a,t)})})}getMarkerManager(){return this.markerManager}getContainer(){var t,r;return((r=(t=this.map)==null?void 0:t.getContainer)==null?void 0:r.call(t))||null}cleanup(){for(let t of this.cleanupFns)try{t()}catch{}this.cleanupFns.length=0}getMap(){return this.map}getCenter(){let t=this.map.getCenter();return{lng:t.lng,lat:t.lat}}getZoom(){return this.map.getZoom()}getBearing(){return this.map.getBearing()}getPitch(){return this.map.getPitch()}getMapBounds(){let t=this.map.getBounds(),r=t.getSouthWest(),a=t.getNorthEast();return{sw:{lat:r.lat,lng:r.lng},ne:{lat:a.lat,lng:a.lng}}}project(t){return this.map.project({lng:t[0],lat:t[1]})}on(t,r){this.map.on(t,r)}off(t,r){this.map.off(t,r)}resize(){this.map.resize()}remove(){this.cleanup(),this.map.remove()}};function X(n){let e=n.getCenter();return{longitude:e.lng,latitude:e.lat,zoom:n.getZoom(),bearing:n.getBearing(),pitch:n.getPitch()}}var ye=[{zoom:6,threshold:120},{zoom:8,threshold:108},{zoom:10,threshold:92},{zoom:12,threshold:80},{zoom:14,threshold:68},{zoom:16,threshold:56}];function J(n){for(let e of ye)if(n<=e.zoom)return e.threshold;return 48}function H({primaryType:n,markers:e,map:t,selectedMarkerId:r,zoom:a,collisionThresholdPx:i,dotCollisionThresholdPx:o}){if(!e.length)return[];if(!t)return e.map(d=>({kind:"primary",marker:d,key:`primary-${d.tripadvisor_id}`}));let c=e.map((d,u)=>{let f=d.location;if(typeof(f==null?void 0:f.lon)!="number"||typeof(f==null?void 0:f.lat)!="number")return null;let{x:l,y:M}=t.project([f.lon,f.lat]);return{marker:d,index:u,x:l,y:M}}).filter(d=>!!d);if(!c.length)return[];let s=J(a),p=be(a),h=c.map((d,u)=>u),g=d=>h[d]===d?d:(h[d]=g(h[d]),h[d]),m=(d,u)=>{let f=g(d),l=g(u);f!==l&&(h[l]=f)};for(let d=0;d<c.length;d+=1)for(let u=d+1;u<c.length;u+=1){let f=c[d].x-c[u].x,l=c[d].y-c[u].y;Math.hypot(f,l)<=s&&m(d,u)}let y=new Map;for(let d of c){let u=g(d.index),f=y.get(u);f?f.push(d):y.set(u,[d])}let b=[];return y.forEach(d=>{var A,C;if(d.length===1){let[{marker:v}]=d,P=v.type===n,T=r===v.tripadvisor_id;b.push({kind:"primary",marker:v,key:`primary-${v.tripadvisor_id}-p${P?1:0}-s${T?1:0}-${(A=v.pricing)==null?void 0:A.availability}`});return}let u=[...d].sort((v,P)=>ke(P.marker,v.marker,n)),[f,...l]=u,M=f.marker.type===n,x=r===f.marker.tripadvisor_id;if(b.push({kind:"primary",marker:f.marker,key:`primary-${f.marker.tripadvisor_id}-p${M?1:0}-s${x?1:0}-${(C=f.marker.pricing)==null?void 0:C.availability}`}),!l.length)return;let L=[],k=[];if(l.forEach(v=>{var P;if(r&&v.marker.tripadvisor_id===r){let T=v.marker.type===n;b.push({kind:"primary",marker:v.marker,key:`primary-${v.marker.tripadvisor_id}-p${T?1:0}-s1-${(P=v.marker.pricing)==null?void 0:P.availability}`});return}ge(f,v)<=p?L.push(v):k.push(v)}),L.forEach(v=>{var T;let P=v.marker.type===n;b.push({kind:"dot",marker:v.marker,key:`dot-${v.marker.tripadvisor_id}-p${P?1:0}-s0-${(T=v.marker.pricing)==null?void 0:T.availability}`,parentId:f.marker.tripadvisor_id})}),k.length){let v=H({markers:k.map(P=>P.marker),map:t,selectedMarkerId:r,zoom:a,primaryType:n,collisionThresholdPx:i,dotCollisionThresholdPx:o});b.push(...v)}}),b}function ge(n,e){return Math.hypot(n.x-e.x,n.y-e.y)}function be(n){let e=J(n);return Math.max(48,e)}function ke(n,e,t){var s,p;let r=n.type===t,a=e.type===t;if(r&&!a)return 1;if(!r&&a)return-1;let i=Z(n)-Z(e);if(i!==0)return i;let o=W(n)-W(e);if(o!==0)return o;let c=((s=n.reviews)!=null?s:0)-((p=e.reviews)!=null?p:0);return c!==0?c:n.tripadvisor_id-e.tripadvisor_id}function Z(n){if(typeof n.rating=="number")return n.rating;if(n.rating===void 0||n.rating===null)return-1/0;let e=Number(n.rating);return Number.isNaN(e)?-1/0:e}function W(n){var t,r,a;if(!((r=(t=n.pricing)==null?void 0:t.offer)!=null&&r.price))return-1/0;let e=Number(((a=n.pricing.offer.displayPrice)!=null?a:"0").replace(/[^0-9.,-]+/g,"").replace(/,/g,""));return Number.isNaN(e)?-1/0:e}function Y(n){let e=[];return n.amenities&&Array.isArray(n.amenities)&&n.amenities.forEach(t=>{e.push({id:`amenity-${t}`,label:t,type:"amenity",value:t})}),n.hotelStyle&&Array.isArray(n.hotelStyle)&&n.hotelStyle.forEach(t=>{e.push({id:`hotelStyle-${t}`,label:t,type:"hotelStyle",value:t})}),n.price&&e.push({id:"priceRange",label:"Price Range",type:"priceRange",value:`${n.price.min}-${n.price.max}`,priceRange:n.price}),typeof n.minRating=="number"&&Number.isFinite(n.minRating)&&e.push({id:"minRating",label:`${n.minRating}+`,type:"minRating",value:String(n.minRating),numericValue:n.minRating}),typeof n.starRating=="number"&&Number.isFinite(n.starRating)&&e.push({id:"starRating",label:`${n.starRating} Stars`,type:"starRating",value:String(n.starRating),numericValue:n.starRating}),n.transformed_query&&e.push({id:"transformed_query",label:n.transformed_query,type:"transformed_query",value:n.transformed_query}),n.selected_restaurant_price_levels&&e.push({id:"selected_restaurant_price_levels",label:n.selected_restaurant_price_levels.join(", "),type:"selected_restaurant_price_levels",value:n.selected_restaurant_price_levels.join(", "),priceLevels:n.selected_restaurant_price_levels}),e}function Q(n){return n.map(e=>{let t={id:e.id,label:typeof e.label=="string"?e.label:String(e.label||""),type:e.type,value:e.value};if(e.numericValue!==void 0&&(t.numericValue=e.numericValue),e.priceRange){let r=e.priceRange.min,a=e.priceRange.max;r!==void 0&&(t.priceRange={min:r,...a!==void 0&&{max:a}})}return e.priceLevels&&(t.priceLevels=e.priceLevels),t})}var Me={prod:"https://api.mapfirst.ai",test:"https://api.mapfirst.ai/test"},_=class extends Error{constructor({message:e,status:t,code:r}){super(e),this.name="PropertiesFetchError",this.status=t,this.code=r}};async function ae(n,e,t,{signal:r}={}){var i,o;let a=await fetch(n,{method:"POST",headers:{"Content-Type":"application/json",...t&&{"X-API-Key":t}},body:JSON.stringify(e),signal:r});if(!a.ok){let c=`Unexpected response: ${a.status}`,s;try{let p=await a.json();c=(o=(i=p.detail)!=null?i:p.error)!=null?o:c,s=p.code}catch{}throw new _({message:c,status:a.status,code:s})}return await a.json()}function ee(n){return typeof n=="string"?n:n.toISOString().slice(0,10)}async function ve(n,e,t){try{await fetch(`${n}/${e}/impressions`,{method:"POST",headers:{"Content-Type":"application/json",...e&&{"X-API-Key":e}},body:JSON.stringify({timestamp:new Date().toISOString(),type:"map_view",...t})})}catch(r){console.debug("Failed to track map impression:",r)}}var te="Accommodation";function Pe(){let e=new Date(Date.now()+864e6),t=(6-e.getDay()+7)%7,r=new Date(e.getTime()+t*864e5),a=r.getDay(),i=a===0?6:6-a,o=new Date(r.getTime()+(i+1)*864e5);return{checkIn:r,checkOut:o}}var z=class{constructor(e){this.options=e;this.adapter=null;this.properties=[];this.selectedMarkerId=null;this.destroyed=!1;this.clusterItems=[];this.isMapAttached=!1;var a,i,o,c,s,p,h,g,m,y,b,d,u,f,l,M,x;if(this.properties=[...(a=e.properties)!=null?a:[]],this.primaryType=e.primaryType,this.selectedMarkerId=(i=e.selectedMarkerId)!=null?i:null,this.useApi=(o=e.useApi)!=null?o:!0,this.environment=(c=e.environment)!=null?c:"prod",this.apiUrl=(s=e.apiUrl)!=null?s:Me[this.environment],this.apiKey=(p=e.apiKey)!=null?p:"default",this.requestBody=e.requestBody,this.currentPlatform=e.platform,!this.useApi&&e.platform&&e.platform!=="maplibre")throw new Error("When useApi is false, only maplibre platform is supported. Google Maps and Mapbox require API usage.");let t=re(e);this.fitBoundsPadding={top:(g=(h=e.fitBoundsPadding)==null?void 0:h.top)!=null?g:t?0:50,bottom:(y=(m=e.fitBoundsPadding)==null?void 0:m.bottom)!=null?y:t?0:160,left:(d=(b=e.fitBoundsPadding)==null?void 0:b.left)!=null?d:t?0:50,right:(f=(u=e.fitBoundsPadding)==null?void 0:u.right)!=null?f:t?0:50};let r=Pe();this.state={center:[0,0],zoom:0,bounds:null,pendingBounds:null,tempBounds:null,properties:this.properties,primary:(l=this.primaryType)!=null?l:te,selectedPropertyId:this.selectedMarkerId,initialLoading:!0,isSearching:!1,firstCallDone:!1,filters:{checkIn:r.checkIn,checkOut:r.checkOut,numAdults:2,numRooms:1,...((M=e.initialLocationData)==null?void 0:M.currency)&&{currency:e.initialLocationData.currency}},activeLocation:{country:"",location_id:null,locationName:"",coordinates:[0,0]},isFlyToAnimating:!1,...e.state},this.callbacks=(x=e.callbacks)!=null?x:{},this.hasMapInstance(e)&&(this.adapter=this.createAdapter(e),this.isMapAttached=!0,this.refresh()),e.initialLocationData?this.initializeFromLocationData(e.initialLocationData):this.requestBody&&this.isMapAttached&&this.autoLoadProperties()}hasMapInstance(e){return!!("adapter"in e&&e.adapter||"mapInstance"in e&&e.mapInstance)}async initializeFromLocationData(e){if(!this.useApi){console.warn("initializeFromLocationData requires API usage. Set useApi to true.");return}try{let{city:t,country:r,query:a,currency:i}=e,o={filters:this.getFilters(),initial:!0};if(t&&r||r){let c=await fetch(`${this.apiUrl}/geo-lookup?country=${encodeURIComponent(r)}${t?`&city=${encodeURIComponent(t)}`:""}`);if(c.ok){let s=await c.json(),p=t;s.location_name&&s.path3_name&&s.location_name===s.path3_name&&(p=void 0),s.location_name&&(p=s.location_name);let h=s.path3_name||r;o={...o,city:p,country:h,location_id:s.location_id,longitude:s.longitude,latitude:s.latitude},this.setActiveLocation({city:p,country:h,location_id:s.location_id,locationName:p&&h?`${p}, ${h}`:h||"",coordinates:[s.latitude,s.longitude]}),this.setState({center:[s.latitude,s.longitude],zoom:12})}else this.handleError(new Error(`Geo mapping fetch failed: ${c.statusText}`),"initializeFromLocationData")}else a&&(o.query=a);this.requestBody=o,this.isMapAttached&&await this.autoLoadProperties()}catch(t){this.handleError(t,"initializeFromLocationData")}}async autoLoadProperties(){if(!this.useApi){console.warn("autoLoadProperties requires API usage. Set useApi to true.");return}if(!this.requestBody)return;let e={filters:this.getFilters(),initial:!0,...this.requestBody};await this.runPropertiesSearch({body:e,onError:t=>{var r,a;this.handleError(t,"autoLoadProperties"),(a=(r=this.callbacks).onPropertiesLoadError)==null||a.call(r,t)}})}attachMap(e,t){if(!this.useApi&&t.platform!=="maplibre")throw new Error("When useApi is false, only maplibre platform is supported. Google Maps and Mapbox require API usage.");if(this.isMapAttached&&(console.warn("Map is already attached. Destroying previous adapter."),this.adapter)){let a=this.adapter.getMarkerManager();a==null||a.destroy(),this.adapter.cleanup()}let r={...this.options,platform:t.platform,mapInstance:e,maplibregl:t.maplibregl,google:t.google,mapboxgl:t.mapboxgl,onMarkerClick:t.onMarkerClick};this.currentPlatform=t.platform,this.adapter=this.createAdapter(r),this.isMapAttached=!0,this.refresh(),this.requestBody&&!this.state.firstCallDone&&this.autoLoadProperties()}createAdapter(e){return xe(e)&&e.mapInstance?this.initializeAdapter(new R(e.mapInstance),{maplibregl:e.maplibregl,onMarkerClick:e.onMarkerClick}):re(e)&&e.mapInstance?this.initializeAdapter(new F(e.mapInstance),{google:e.google,onMarkerClick:e.onMarkerClick}):Le(e)&&e.mapInstance?this.initializeAdapter(new D(e.mapInstance),{mapboxgl:e.mapboxgl,onMarkerClick:e.onMarkerClick}):"adapter"in e&&e.adapter?e.adapter:null}initializeAdapter(e,t){var a;let r=(a=this.options.autoSelectOnClick)!=null?a:!0;return e.initialize({...t,onMarkerClick:i=>{var o;i.location&&this.flyMapTo(i.location.lon,i.location.lat,14),i.type!==this.primaryType&&this.setPrimaryType(i.type),r&&this.setSelectedMarker(i.tripadvisor_id===this.selectedMarkerId?null:i.tripadvisor_id),(o=t.onMarkerClick)==null||o.call(t,i)},onRefresh:()=>this.refresh(),onMapMoveEnd:i=>{this.state.tempBounds===null?(this.setTempBounds(i),this.setPendingBounds(null)):this.handleMapMoveEnd(i)}}),this.useApi&&e.setupImpressionTracking(()=>{ve(this.apiUrl,this.apiKey||"default",{platform:this.currentPlatform,environment:this.environment})}),e}_setProperties(e){var t,r;this.ensureAlive(),this.properties=[...e.filter(a=>{var i;return a.type==="Accommodation"?((i=a.pricing)==null?void 0:i.availability)!=="unavailable":!0})],this.updateState({properties:this.properties}),(r=(t=this.callbacks).onPropertiesChange)==null||r.call(t,e),this.refresh()}addProperty(e){var t,r;this.ensureAlive(),this.properties=[...this.properties,e],this.updateState({properties:this.properties}),(r=(t=this.callbacks).onPropertiesChange)==null||r.call(t,this.properties),this.refresh()}clearProperties(){var e,t;this.ensureAlive(),this.properties=[],this.updateState({properties:[]}),(t=(e=this.callbacks).onPropertiesChange)==null||t.call(e,[]),this.refresh()}setPrimaryType(e){var t,r;this.ensureAlive(),this.primaryType!==e&&(this.primaryType=e,this.updateState({primary:e}),(r=(t=this.callbacks).onPrimaryTypeChange)==null||r.call(t,e),this.refresh())}setSelectedMarker(e){var t,r;if(this.ensureAlive(),this.selectedMarkerId!==e){if(e!==null){let a=this.properties.find(i=>i.tripadvisor_id===e);a&&a.type!==this.primaryType&&this.setPrimaryType(a.type)}this.selectedMarkerId=e,this.updateState({selectedPropertyId:e}),(r=(t=this.callbacks).onSelectedPropertyChange)==null||r.call(t,e),this.refresh()}}getState(){return{...this.state}}handleError(e,t="MapFirstCore"){let r=e instanceof Error?e.message:String(e),a=e instanceof Error?e:new Error(r);console.error(`[${t}]`,r),this.callbacks.onError&&this.callbacks.onError(a,t)}updateState(e){this.state={...this.state,...e}}setState(e){var r,a,i,o,c,s,p,h,g,m,y,b,d,u,f,l;let t={...this.state};this.updateState(e),e.center!==void 0&&e.center!==t.center&&((a=(r=this.callbacks).onCenterChange)==null||a.call(r,e.center,this.state.zoom)),e.zoom!==void 0&&e.zoom!==t.zoom&&((o=(i=this.callbacks).onZoomChange)==null||o.call(i,e.zoom)),e.bounds!==void 0&&e.bounds!==t.bounds&&((s=(c=this.callbacks).onBoundsChange)==null||s.call(c,e.bounds)),e.pendingBounds!==void 0&&e.pendingBounds!==t.pendingBounds&&((h=(p=this.callbacks).onPendingBoundsChange)==null||h.call(p,e.pendingBounds)),e.filters!==void 0&&e.filters!==t.filters&&((m=(g=this.callbacks).onFiltersChange)==null||m.call(g,e.filters)),e.activeLocation!==void 0&&e.activeLocation!==t.activeLocation&&((b=(y=this.callbacks).onActiveLocationChange)==null||b.call(y,e.activeLocation)),e.initialLoading!==void 0&&e.initialLoading!==t.initialLoading&&((u=(d=this.callbacks).onLoadingStateChange)==null||u.call(d,e.initialLoading)),e.isSearching!==void 0&&e.isSearching!==t.isSearching&&((l=(f=this.callbacks).onSearchingStateChange)==null||l.call(f,e.isSearching))}setFilters(e){this.setState({filters:e})}setActiveLocation(e){this.setState({activeLocation:e})}setBounds(e){this.setState({bounds:e})}setPendingBounds(e){this.setState({pendingBounds:e})}setTempBounds(e){this.setState({tempBounds:e})}setLoading(e){this.setState({initialLoading:e})}setSearching(e){this.setState({isSearching:e})}setFlyToAnimating(e){this.setState({isFlyToAnimating:e})}handleMapMoveEnd(e){if(this.state.isFlyToAnimating){this.setState({isFlyToAnimating:!1,tempBounds:e,pendingBounds:null});return}let t=this.state.tempBounds;if(!t){this.setState({tempBounds:e,pendingBounds:e});return}let r=.01;Math.abs(e.sw.lat-t.sw.lat)>r||Math.abs(e.sw.lng-t.sw.lng)>r||Math.abs(e.ne.lat-t.ne.lat)>r||Math.abs(e.ne.lng-t.ne.lng)>r?this.setState({pendingBounds:e}):this.setState({pendingBounds:null})}flyMapTo(e,t,r,a=!0){if(this.ensureAlive(),this.setState({center:[t,e]}),typeof r=="number"&&this.setState({zoom:r}),!this.adapter)return;let i=this.adapter.getMap();if(i){if(this.currentPlatform==="google"){this.setFlyToAnimating(!1),i.setCenter({lat:t,lng:e}),r!==null&&typeof r=="number"&&i.setZoom(r!=null?r:13);return}if(a===!1){this.setFlyToAnimating(!1),i.jumpTo&&i.jumpTo({center:[e,t],...r!==null&&{zoom:r!=null?r:13}});return}this.setFlyToAnimating(!0),i.flyTo&&i.flyTo({center:[e,t],...r!==null&&{zoom:r!=null?r:13}})}}flyToPOIs(e,t,r=!0){var o,c;if(this.ensureAlive(),!this.adapter)return;let a=this.adapter.getMap();if(!a)return;let i=e;if((!i||i.length===0)&&(i=this.properties.filter(s=>s.location!==void 0&&(t!==void 0?s.type===t:!0)).map(s=>({lat:s.location.lat,lng:s.location.lon}))),!(!i||i.length===0)){if(i.length===1){let s=i[0];this.currentPlatform==="google"?(a.setCenter({lat:s.lat,lng:s.lng}),a.setZoom(13)):a.flyTo&&a.flyTo({center:[s.lng,s.lat],zoom:13})}else if(this.currentPlatform==="google"){let s=(c=(o=window.google)==null?void 0:o.maps)==null?void 0:c.LatLngBounds;if(s){let p=new s;i.forEach(h=>{p.extend({lat:h.lat,lng:h.lng})}),r&&this.setFlyToAnimating(!0),a.fitBounds(p,this.fitBoundsPadding)}}else if(a.fitBounds){let s=[[i[0].lng,i[0].lat],[i[0].lng,i[0].lat]];i.forEach(p=>{s[0][0]=Math.min(s[0][0],p.lng),s[0][1]=Math.min(s[0][1],p.lat),s[1][0]=Math.max(s[1][0],p.lng),s[1][1]=Math.max(s[1][1],p.lat)}),r&&this.setFlyToAnimating(!0),a.fitBounds(s,{padding:this.fitBoundsPadding,animate:r})}}}getFilters(){let e={...this.state.filters};return e.checkIn instanceof Date&&(e.checkIn=ee(e.checkIn)),e.checkOut instanceof Date&&(e.checkOut=ee(e.checkOut)),e}async loadProperties({fetchFn:e,onSuccess:t,onError:r}){this.ensureAlive(),this.setLoading(!0),this.setSearching(!0),this.clearProperties();try{let a=await e();if(this._setProperties(a),!this.primaryType&&a.length>0){let i=a.reduce((c,s)=>(c[s.type]=(c[s.type]||0)+1,c),{}),o=Object.entries(i).reduce((c,s)=>i[c[0]]>i[s[0]]?c:s)[0];this.setPrimaryType(o)}this.setState({firstCallDone:!0}),t==null||t(a)}catch(a){this.clearProperties(),r==null||r(a)}finally{this.setSearching(!1),this.setLoading(!1),this.setState({firstCallDone:!0})}}async pollForPricing({pollingLink:e,maxAttempts:t=15,delayMs:r=2e3,isCancelled:a,price:i,limit:o}){var g,m,y,b,d;if(this.ensureAlive(),!this.useApi)return console.warn("pollForPricing requires API usage. Set useApi to true."),{completed:!1};if(!e)return{completed:!1};let c=!1,s,p=this.getFilters();o&&(p.limit=o);let h={filters:p,pollingLink:e};for(let u=0;u<t;u++){if(a!=null&&a())return{completed:c,pollData:s};try{let f=await fetch(`${this.apiUrl}/ta-polling?pollingNumber=${u}`,{method:"POST",body:JSON.stringify(h),headers:{"Content-Type":"application/json",...this.apiKey&&{"X-API-Key":this.apiKey}}});if(!f.ok)throw new _({message:`Poll failed: ${f.status}`,status:f.status});if(s=await f.json(),a!=null&&a())return{completed:c,pollData:s};let l=(m=(g=s==null?void 0:s.success)==null?void 0:g.results)!=null?m:[];if(l.length>0&&this.setProperties(M=>{let x=new Set(l.map(k=>k.tripadvisor_id)),L=M.filter(k=>k.type!=="Accommodation"||x.has(k.tripadvisor_id));return l.forEach(k=>{var C,v,P,T,$,j;if(!k.location)return;(v=(C=k.pricing)==null?void 0:C.offer)!=null&&v.price&&i&&(((T=(P=k.pricing)==null?void 0:P.offer)==null?void 0:T.price)<(i==null?void 0:i.min)||((j=($=k.pricing)==null?void 0:$.offer)==null?void 0:j.price)>(i==null?void 0:i.max))&&(k.pricing.availability="unavailable");let A=L.findIndex(ie=>ie.tripadvisor_id===k.tripadvisor_id);A>=0?L[A]=k:L.push(k)}),L}),(y=s==null?void 0:s.success)!=null&&y.isComplete){c=!0;break}}catch(f){this.handleError(f,"pollForPricing"),(d=(b=this.callbacks).onPropertiesLoadError)==null||d.call(b,f);break}u<t-1&&await new Promise(f=>setTimeout(f,r))}return{completed:c,pollData:s}}setProperties(e){let t=e(this.properties);this._setProperties(t)}mostCommonTypeFromProperties(e){let t=e.reduce((r,a)=>(r[a.type]=(r[a.type]||0)+1,r),{});return Object.entries(t).reduce((r,a)=>t[r[0]]>t[a[0]]?r:a)[0]}async runPropertiesSearch({body:e,beforeApplyProperties:t,smartFiltersClearable:r,onError:a}){var i,o,c,s,p,h,g;if(this.ensureAlive(),!this.useApi)return console.warn("runPropertiesSearch requires API usage. Set useApi to true."),a==null||a(new Error("API usage is disabled")),null;this.setState({firstCallDone:!1}),this.setSearching(!0),this.clearProperties();try{let m=await ae(`${this.apiUrl}/properties`,e,this.apiKey);this.updateActiveLocationFromResponse(m);let y=null,b=30,d=m.filters.primary_type;if(t){let l=t(m);y=(i=l.price)!=null?i:null,b=(o=l.limit)!=null?o:30}let u=m.properties.some(l=>!!l.location),f=y?m.properties.map(l=>{var M;return(M=l.pricing)!=null&&M.offer?{...l,pricing:{...l.pricing,availability:l.pricing.offer.price&&(l.pricing.offer.price<y.min||l.pricing.offer.price>y.max)?"unavailable":l.pricing.availability}}:l}):m.properties;if(this._setProperties(f),u&&this.flyToPOIs(m.properties.filter(l=>!!l.location&&(m.filters.primary_type?l.type===m.filters.primary_type:!0)).map(l=>({lat:l.location.lat,lng:l.location.lon})),void 0,e.initial!==!0),m.filters.primary_type&&m.properties.filter(l=>{var M;return l.type===m.filters.primary_type&&(l.type==="Accommodation"?((M=l.pricing)==null?void 0:M.availability)!=="unavailable":!0)}).length>0)d=m.filters.primary_type,this.setPrimaryType(m.filters.primary_type);else if(m.properties.length>0){let l=this.mostCommonTypeFromProperties(m.properties);this.setPrimaryType(l),d=l}if(this.setState({firstCallDone:!0}),m.isComplete===!1&&m.pollingLink){let{completed:l,pollData:M}=await this.pollForPricing({pollingLink:m.pollingLink,...y&&{price:y},...b&&{limit:b}});if(l&&((c=M==null?void 0:M.success)!=null&&c.results)&&M.success.results.filter(x=>{var L;return x.type===m.filters.primary_type&&(x.type==="Accommodation"?((L=x.pricing)==null?void 0:L.availability)!=="unavailable":!0)}).length===0&&d&&d!==m.filters.primary_type){let x=this.mostCommonTypeFromProperties(m.properties);this.setPrimaryType(x)}}return u||(m.properties.some(l=>!!l.location)?this.flyToPOIs(m.properties.filter(l=>!!l.location&&(m.filters.primary_type?l.type===m.filters.primary_type:!0)).map(l=>({lat:l.location.lat,lng:l.location.lon})),void 0,e.initial!==!0):(s=m.filters.location)!=null&&s.latitude&&((p=m.filters.location)!=null&&p.longitude)&&this.flyMapTo(m.filters.location.longitude,m.filters.location.latitude,12,e.initial!==!0)),m}catch(m){return this.handleError(m,"runPropertiesSearch"),a==null||a(m),(g=(h=this.callbacks).onPropertiesLoadError)==null||g.call(h,m),this.clearProperties(),this.setState({firstCallDone:!0}),null}finally{this.setSearching(!1),this.setState({firstCallDone:!0})}}async performBoundsSearch(){var i;if(this.ensureAlive(),!this.useApi)return console.warn("performBoundsSearch requires API usage. Set useApi to true."),null;if(!this.state.pendingBounds)return null;let e=this.getFilters(),t={bounds:this.state.pendingBounds,filters:e},r=(i=e==null?void 0:e.price)!=null?i:void 0,a=await this.runPropertiesSearch({body:t,beforeApplyProperties:()=>({price:r!=null?r:null})});return a&&(this.setBounds(this.state.pendingBounds),this.setTempBounds(this.state.pendingBounds),this.setPendingBounds(null)),a}updateActiveLocationFromResponse(e){var c,s,p,h;let t=(c=e.location_id)!=null?c:null,r=(p=(s=e.filters.location)==null?void 0:s.city)!=null?p:void 0,a=((h=e.filters.location)==null?void 0:h.country)||"",i=e.filters.location?[e.filters.location.latitude,e.filters.location.longitude]:void 0;if(!i)return;let o=this.state.activeLocation;(t!==(o==null?void 0:o.location_id)||r!==(o==null?void 0:o.city)||a!==(o==null?void 0:o.country))&&this.setActiveLocation({city:r,country:a,location_id:t,locationName:r&&a?`${r}, ${a}`:a||"",coordinates:i})}async runSmartFilterSearch({query:e,filters:t,onProcessFilters:r,onError:a}){if(this.ensureAlive(),!this.useApi)return console.warn("runSmartFilterSearch requires API usage. Set useApi to true."),a==null||a(new Error("API usage is disabled")),null;let i=this.getFilters(),o=this.getState();if(t&&t.length>0){let s=new Set,p=new Set,h,g,m,y,b,d;t.forEach(u=>{var f,l,M;switch(u.type){case"amenity":s.add(u.value);break;case"hotelStyle":p.add(u.value);break;case"priceRange":u.priceRange&&(h={min:u.priceRange.min,max:(f=u.priceRange.max)!=null?f:0});break;case"minRating":g=(l=u.numericValue)!=null?l:Number(u.value);break;case"starRating":m=(M=u.numericValue)!=null?M:Number(u.value);break;case"primary_type":y=u.propertyType;break;case"transformed_query":b=u.value;break;case"selected_restaurant_price_levels":d=u.priceLevels;break}}),i={...i,...s.size>0&&{amenities:Array.from(s)},...p.size>0&&{hotelStyle:Array.from(p)},...h&&{price:h},...g!==void 0&&{minRating:g},...m!==void 0&&{starRating:m},...y&&{primary_type:y},...b&&{transformed_query:b},...d&&{selected_restaurant_price_levels:d}}}else e||(i.minRating=4);let c={filters:i,...e&&{query:e},...o.bounds?{bounds:o.bounds}:o.activeLocation.location_id?{location_id:o.activeLocation.location_id}:o.activeLocation.coordinates?{latitude:o.activeLocation.coordinates[0],longitude:o.activeLocation.coordinates[1]}:{}};return this.runPropertiesSearch({body:c,beforeApplyProperties:r?s=>{var h,g;let p=r(s.filters,s.location_id);return{price:(h=p.price)!=null?h:null,limit:(g=p.limit)!=null?g:30}}:void 0,smartFiltersClearable:!!e,onError:a})}getClusters(){return this.ensureAlive(),[...this.clusterItems]}setUseApi(e,t=!0){this.ensureAlive(),this.useApi=e,!e&&this.currentPlatform&&this.currentPlatform!=="maplibre"&&console.warn("When useApi is false, only maplibre platform is supported. Please switch to maplibre."),e||this.clearProperties(),e&&t&&(this.options.initialLocationData?this.initializeFromLocationData(this.options.initialLocationData):this.requestBody&&this.isMapAttached&&this.autoLoadProperties())}setApiKey(e){this.ensureAlive();let t=this.apiKey;this.apiKey=e||"default",t!==this.apiKey&&this.isMapAttached&&(this.refresh(),this.useApi&&(this.options.initialLocationData?this.initializeFromLocationData(this.options.initialLocationData):this.requestBody&&this.autoLoadProperties()))}getApiKey(){return this.apiKey}refresh(){var a,i,o;if(this.ensureAlive(),!this.adapter)return;let e=this.safeExtractViewState(),t=this.resolvePrimaryType();this.clusterItems=H({primaryType:t,markers:this.properties,map:this.adapter,selectedMarkerId:this.selectedMarkerId,zoom:(a=e==null?void 0:e.zoom)!=null?a:0}),this.adapter.getMarkerManager().render(this.clusterItems,t,this.selectedMarkerId),(o=(i=this.options).onClusterUpdate)==null||o.call(i,this.clusterItems,e)}destroy(){this.destroyed||(this.adapter&&(this.adapter.getMarkerManager().destroy(),this.adapter.cleanup()),this.clusterItems=[],this.properties=[],this.destroyed=!0,this.isMapAttached=!1)}resolvePrimaryType(){var e,t,r;return(r=(t=this.primaryType)!=null?t:(e=this.properties.find(a=>a.type))==null?void 0:e.type)!=null?r:te}safeExtractViewState(){if(!this.adapter)return null;try{return X(this.adapter)}catch{return null}}ensureAlive(){if(this.destroyed)throw new Error("MapFirstCore instance has been destroyed")}};function xe(n){return n.platform==="maplibre"}function re(n){return n.platform==="google"}function Le(n){return n.platform==="mapbox"}0&&(module.exports={MapFirstCore,PropertiesFetchError,convertToApiFilters,fetchProperties,processApiFilters});
|
|
3
3
|
//# sourceMappingURL=index.js.map
|