@mapfirst.ai/core 0.0.29 → 0.0.30

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.mjs CHANGED
@@ -29,5 +29,5 @@ function O(i,{insertAt:e}={}){if(!i||typeof document=="undefined")return;let t=d
29
29
  </span>
30
30
  `:""}
31
31
  </div>
32
- `,t}function de(i,e){let t=i.querySelector(".mapfirst-property-hover-image");if(t&&e.tripadvisor_id&&!t.dataset.imageLoaded){t.dataset.imageLoaded="loading";let a=t.dataset.defaultImage;K(e.tripadvisor_id,1).then(r=>{if(r&&t){let n=document.createElement("img");n.src=r,n.alt=e.name,n.style.width="100%",n.style.height="100%",n.style.objectFit="cover",t.innerHTML="",t.appendChild(n),t.classList.remove("mapfirst-property-hover-image-placeholder"),t.dataset.imageLoaded="true"}else throw new Error("No image URL")}).catch(()=>{if(a&&t){let r=document.createElement("img");r.src=a,r.alt=e.name,r.style.width="100%",r.style.height="100%",r.style.objectFit="cover",t.innerHTML="",t.appendChild(r),t.classList.remove("mapfirst-property-hover-image-placeholder"),t.dataset.imageLoaded="false"}})}}function V(i,e,t){let a=e.getBoundingClientRect(),r=t.getBoundingClientRect(),n=270,s=120,m=12,p=r.right-a.right,f=a.left-r.left,y=r.bottom-a.bottom,M=a.top-r.top,l=a.left-r.left+a.width/2-n/2,o=a.top-r.top+a.height+m;l<0?l=8:l+n>r.width&&(l=r.width-n-8),y<s+m&&M>y&&(o=a.top-r.top-s-m),i.style.left=`${l}px`,i.style.top=`${o}px`}function U(i,e,t,a){var u,b,g,c,h,v,A,T,x;if(typeof document=="undefined")return null;let r=i.marker,n=r.type===e,s=t===r.tripadvisor_id,m=r.type==="Accommodation",p=(b=(u=r.pricing)==null?void 0:u.offer)==null?void 0:b.displayPrice,f=m&&!p,y=(()=>{if(r.rating===void 0||r.rating===null)return null;let L=typeof r.rating=="number"?r.rating:Number(r.rating);return Number.isNaN(L)||L<=0?null:L.toFixed(1)})(),M=document.createElement("div");M.className="mapfirst-marker-root",M.style.zIndex=s?"20":n?"12":"11";let l=(h=(c=(g=r.pricing)==null?void 0:g.offer)==null?void 0:c.clickUrl)!=null?h:r.url,o=document.createElement(l?"a":"div");if(l&&(o.href=l,o.target="_blank",o.style.textDecoration="none"),o.className=f?"mapfirst-marker-pill mapfirst-marker-pill-pending":`mapfirst-marker-pill mapfirst-marker-pill-active${s?" mapfirst-marker-selected":n?"":" mapfirst-marker-non-primary"}`,!f&&((v=r.awards)!=null&&v.length||y)){let L=document.createElement("div");if(L.className="mapfirst-marker-badge",n||(L.style.opacity="0.2"),L.className="mapfirst-marker-badge",(A=r.awards)!=null&&A.length&&r.awards[0].type){let k=document.createElement("div");k.className="mapfirst-marker-award-container";let P=document.createElement("div");P.className="mapfirst-marker-award-back",P.innerHTML=se;let C=document.createElement("div");C.className=`mapfirst-marker-award-dot mapfirst-marker-award-dot-type-${r.awards[0].type}`;let w=document.createElement("div");w.className="mapfirst-marker-award-front",w.innerHTML=ne,k.appendChild(P),k.appendChild(C),k.appendChild(w),L.appendChild(k)}else y&&(L.className="mapfirst-marker-badge mapfirst-marker-rating-badge",L.textContent=y);o.appendChild(L)}let d=document.createElement("span");return d.className="mapfirst-marker-content",m?(x=(T=r.pricing)==null?void 0:T.offer)!=null&&x.displayPrice?(d.innerHTML=r.pricing.offer.displayPrice,d.dataset.price=r.pricing.offer.displayPrice):(d.innerHTML=le,d.dataset.price=""):r.type==="Eat & Drink"?d.innerHTML=oe:r.type==="Attraction"&&(d.innerHTML=pe),o.appendChild(d),o.addEventListener("click",L=>{L.stopPropagation(),f||a==null||a(r)}),f||E(M,o,r,s),M.appendChild(o),M}function Z(i,e,t,a){var M,l,o;if(typeof document=="undefined")return null;let r=i.marker,n=r.type===e,s=t===r.tripadvisor_id,p=r.type==="Accommodation"&&((l=(M=r.pricing)==null?void 0:M.offer)==null?void 0:l.availability)!=="available",f=document.createElement("div");f.className="mapfirst-dot-marker-container",f.style.zIndex=s?"20":n?"3":"1";let y=document.createElement("div");return y.className=p?"mapfirst-dot-marker-button mapfirst-dot-marker-button-pending":`mapfirst-dot-marker-button mapfirst-dot-marker-button-active${s?" mapfirst-dot-marker-selected":n?"":" mapfirst-dot-marker-non-primary"}`,y.title=(o=r.name)!=null?o:String(r.tripadvisor_id),y.addEventListener("click",d=>{d.stopPropagation(),p||a==null||a(r)}),f.appendChild(y),p||E(f,y,r,s),f}var ue='<video class="mapfirst-marker-loading-video" src="https://api.mapfirst.ai/static/images/loading.webm" autoplay loop muted></video>';function z(i,e,t,a,r){var f,y,M,l,o,d,u,b,g,c;let n=(y=(f=i.querySelector(".mapfirst-marker-pill"))==null?void 0:f.classList.contains("mapfirst-marker-pill-pending"))!=null?y:!1,s=i;s.style.zIndex=t?"20":e?"12":"11";let m=s.querySelector(".mapfirst-marker-pill");m&&(a?m.className="mapfirst-marker-pill mapfirst-marker-pill-pending":m.className=`mapfirst-marker-pill mapfirst-marker-pill-active${t?" mapfirst-marker-selected":e?"":" mapfirst-marker-non-primary"}`);let p=s.querySelector(".mapfirst-marker-badge");if(p instanceof HTMLElement&&(p.style.opacity=!e&&!t?"0.2":""),n&&!a&&r){let h=s.querySelector(".mapfirst-marker-pill");h instanceof HTMLElement&&E(s,h,r,t)}if(r&&r.type==="Accommodation"){let h=s.querySelector(".mapfirst-marker-content");if(h instanceof HTMLElement){let v=(l=(M=r.pricing)==null?void 0:M.offer)==null?void 0:l.displayPrice;h.dataset.price!==v&&(v?(h.innerHTML=v,h.dataset.price=v):(h.innerHTML=ue,h.dataset.price=""))}}if(r){let h=document.querySelector(`.mapfirst-property-hover-card[data-marker-id="${r.tripadvisor_id}"]`);if(h){let v=r.rating||0,A=r.reviews||0,T=(u=(d=(o=r.pricing)==null?void 0:o.offer)==null?void 0:d.displayPrice)!=null?u:r.price_level,x=h.querySelector(".rating-value");if(x){let P=v.toFixed(1);x.textContent!==P&&(x.textContent=P)}let L=h.querySelector(".reviews");if(L){let P=`(${A})`;L.textContent!==P&&(L.textContent=P)}if(r.type==="Accommodation"&&T){let P=h.querySelector(".mapfirst-property-hover-price");if(!P){P=document.createElement("div"),P.className="mapfirst-property-hover-price";let C=h.querySelector(".mapfirst-property-hover-details"),w=h.querySelector(".mapfirst-property-hover-learn-more");C&&(w?C.insertBefore(P,w):C.appendChild(P))}if(P){let C=`Starting at <strong>${T}</strong>`;P.innerHTML!==C&&(P.innerHTML=C)}}let k=(c=(g=(b=r.pricing)==null?void 0:b.offer)==null?void 0:g.clickUrl)!=null?c:r.url;k&&h instanceof HTMLAnchorElement&&h.href!==k&&(h.href=k)}}}function $(i,e,t,a){let r=i;r.style.zIndex=t?"20":e?"3":"1";let n=r.querySelector(".mapfirst-dot-marker-button");n&&(a?n.className="mapfirst-dot-marker-button mapfirst-dot-marker-button-pending":n.className=`mapfirst-dot-marker-button mapfirst-dot-marker-button-active${t?" mapfirst-dot-marker-selected":e?"":" mapfirst-dot-marker-non-primary"}`)}function W(i){let e=i.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,a){var n,s,m,p,f,y,M,l;t&&t!==this.primaryType&&(this.primaryType=t),a!==void 0&&(this.selectedMarkerId=a);let r=new Set(e.map(o=>o.key));for(let[o,d]of this.markerCache.entries())r.has(o)||(this.removeMarkerFromMap(d.marker),this.markerCache.delete(o));for(let o of e){let d=fe(o.marker.location);if(!d)continue;let u=this.markerCache.get(o.key);if(u){let b=o.marker.type===this.primaryType,g=this.selectedMarkerId===o.marker.tripadvisor_id,c=o.marker.type==="Accommodation",h=o.kind==="primary"?c&&!((s=(n=o.marker.pricing)==null?void 0:n.offer)!=null&&s.displayPrice):c&&((p=(m=o.marker.pricing)==null?void 0:m.offer)==null?void 0:p.availability)!=="available",v=this.getMarkerElement(u.marker);v&&(o.kind==="primary"?z(v,b,g,h,o.marker):$(v,b,g,h));try{this.updateMarkerPosition(u.marker,d)}catch{this.removeMarkerFromMap(u.marker),this.markerCache.delete(o.key),this.createAndAddMarker(o,d)}}else{let b=o.marker.tripadvisor_id,g,c;for(let[h,v]of this.markerCache.entries())if(W(h)===b&&v.kind===o.kind){g=v,c=h;break}if(g&&c){let h=o.marker.type===this.primaryType,v=this.selectedMarkerId===o.marker.tripadvisor_id,A=o.marker.type==="Accommodation",T=o.kind==="primary"?A&&!((y=(f=o.marker.pricing)==null?void 0:f.offer)!=null&&y.displayPrice):A&&((l=(M=o.marker.pricing)==null?void 0:M.offer)==null?void 0:l.availability)!=="available",x=this.getMarkerElement(g.marker);x&&(o.kind==="primary"?z(x,h,v,T,o.marker):$(x,h,v,T)),this.updateMarkerZIndex(g.marker,o,h,v),this.markerCache.delete(c),this.markerCache.set(o.key,g);try{this.updateMarkerPosition(g.marker,d)}catch{}}else this.createAndAddMarker(o,d)}}}destroy(){for(let e of this.markerCache.values())this.removeMarkerFromMap(e.marker);this.markerCache.clear()}createAndAddMarker(e,t){let a=e.kind==="primary"?U(e,this.primaryType,this.selectedMarkerId,this.onMarkerClick):Z(e,this.primaryType,this.selectedMarkerId,this.onMarkerClick);if(!a)return;let r=e.marker.type===this.primaryType,n=this.selectedMarkerId===e.marker.tripadvisor_id;try{let s=this.createMarker(a,t,e,r,n);s&&this.markerCache.set(e.key,{key:e.key,marker:s,kind:e.kind,parentId:e.kind==="dot"?e.parentId:void 0})}catch(s){console.error("Error creating marker",s)}}updateMarkerZIndex(e,t,a,r){}};function fe(i){return typeof(i==null?void 0:i.lon)!="number"||typeof(i==null?void 0:i.lat)!="number"||Number.isNaN(i.lon)||Number.isNaN(i.lat)?null:{lon:i.lon,lat:i.lat}}var B=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,a){this.MarkerCtor&&super.render(e,t,a)}createMarker(e,t,a){return this.MarkerCtor?new this.MarkerCtor({element:e,anchor:a.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 _=class extends I{constructor(e){super(e.mapInstance,e.onMarkerClick),this.google=e.google}render(e,t,a){var r,n;if(!((n=(r=this.google)==null?void 0:r.marker)!=null&&n.AdvancedMarkerElement)){console.warn("AdvancedMarkerElement not available");return}super.render(e,t,a)}createMarker(e,t,a,r,n){var m,p;if(!((p=(m=this.google)==null?void 0:m.marker)!=null&&p.AdvancedMarkerElement))return null;let s=a.kind==="primary"?n?20:r?12:11:n?20:r?3:1;return new this.google.marker.AdvancedMarkerElement({map:this.mapInstance,position:{lat:t.lat,lng:t.lon},content:e,zIndex:s})}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,a,r){let n=t.kind==="primary"?r?20:a?12:11:r?20:a?3:1;e.zIndex=n}};var R=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,a){this.MarkerCtor&&super.render(e,t,a)}createMarker(e,t,a){return this.MarkerCtor?new this.MarkerCtor({element:e,anchor:a.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 a=new IntersectionObserver(s=>{s.forEach(m=>{m.isIntersecting&&(e(),a.disconnect())})},{threshold:.1});a.observe(t);let r=()=>a.disconnect(),n=this.cleanup.bind(this);this.cleanup=()=>{r(),n()}}};var F=class extends S{constructor(t){super(t);this.cleanupFns=[]}initialize(t){return this.markerManager=new B({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 a=()=>{let n=this.getMapBounds();t(n)},r=()=>{let n=this.getMapBounds();t(n)};this.map.loaded&&this.map.loaded()?r():(this.map.once("load",r),this.cleanupFns.push(()=>{typeof this.map.off=="function"&&this.map.off("load",r)})),this.map.on("moveend",a),this.cleanupFns.push(()=>{typeof this.map.off=="function"&&this.map.off("moveend",a)})}attachEventListeners(t){if(!this.map||typeof this.map.on!="function")return;["move","zoom","dragend","pitch","rotate"].forEach(r=>{this.map.on(r,t),this.cleanupFns.push(()=>{typeof this.map.off=="function"&&this.map.off(r,t)})})}getMarkerManager(){return this.markerManager}getContainer(){var t,a;return((a=(t=this.map)==null?void 0:t.getContainer)==null?void 0:a.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(),a=t.getSouthWest(),r=t.getNorthEast();return{sw:{lat:a.lat,lng:a.lng},ne:{lat:r.lat,lng:r.lng}}}project(t){return this.map.project({lng:t[0],lat:t[1]})}on(t,a){this.map.on(t,a)}off(t,a){this.map.off(t,a)}resize(){this.map.resize()}remove(){this.cleanup(),this.map.remove()}};var H=class extends S{constructor(t){super(t);this.cleanupFns=[];this.initializeOverlayView()}initialize(t){return this.markerManager=new _({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,a){if(!this.map)return;let r=()=>{let s=this.getMapBounds();t(s)};r();let n=a.event.addListener(this.map,"idle",r);this.cleanupFns.push(()=>{a.event.removeListener(n)})}attachEventListeners(t){let a=["center_changed","zoom_changed","drag","heading_changed","tilt_changed"],r=[];a.forEach(n=>{let s=this.map.addListener(n,t);r.push(s)}),this.cleanupFns.push(()=>{r.forEach(n=>{try{n.remove()}catch{}})})}getMarkerManager(){return this.markerManager}getContainer(){var t,a;return((a=(t=this.map)==null?void 0:t.getDiv)==null?void 0:a.call(t))||null}cleanup(){for(let t of this.cleanupFns)try{t()}catch{}this.cleanupFns.length=0}initializeOverlayView(){var r;let t=(r=globalThis.google)==null?void 0:r.maps;if(!t)return;let a=t.OverlayView;a&&(this.overlayView=new a,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 a=t.getSouthWest(),r=t.getNorthEast();return{sw:{lat:a.lat(),lng:a.lng()},ne:{lat:r.lat(),lng:r.lng()}}}project(t){var m;if(!this.overlayView)return{x:0,y:0};let a=this.overlayView.getProjection();if(!a)return{x:0,y:0};let r=(m=globalThis.google)==null?void 0:m.maps;if(!r)return{x:0,y:0};let n=new r.LatLng(t[1],t[0]),s=a.fromLatLngToContainerPixel(n);return s?{x:s.x,y:s.y}:{x:0,y:0}}on(t,a){this.map.addListener(t,a)}off(t,a){var n;let r=(n=globalThis.google)==null?void 0:n.maps;r!=null&&r.event&&r.event.clearListeners(this.map,t)}resize(){var a;let t=(a=globalThis.google)==null?void 0:a.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 R({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 a=()=>{let n=this.getMapBounds();t(n)},r=()=>{let n=this.getMapBounds();t(n)};this.map.loaded&&this.map.loaded()?r():(this.map.once("load",r),this.cleanupFns.push(()=>{typeof this.map.off=="function"&&this.map.off("load",r)})),this.map.on("moveend",a),this.cleanupFns.push(()=>{typeof this.map.off=="function"&&this.map.off("moveend",a)})}attachEventListeners(t){if(!this.map||typeof this.map.on!="function")return;["move","zoom","dragend","pitch","rotate"].forEach(r=>{this.map.on(r,t),this.cleanupFns.push(()=>{typeof this.map.off=="function"&&this.map.off(r,t)})})}getMarkerManager(){return this.markerManager}getContainer(){var t,a;return((a=(t=this.map)==null?void 0:t.getContainer)==null?void 0:a.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(),a=t.getSouthWest(),r=t.getNorthEast();return{sw:{lat:a.lat,lng:a.lng},ne:{lat:r.lat,lng:r.lng}}}project(t){return this.map.project({lng:t[0],lat:t[1]})}on(t,a){this.map.on(t,a)}off(t,a){this.map.off(t,a)}resize(){this.map.resize()}remove(){this.cleanup(),this.map.remove()}};function Y(i){let e=i.getCenter();return{longitude:e.lng,latitude:e.lat,zoom:i.getZoom(),bearing:i.getBearing(),pitch:i.getPitch()}}var he=[{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 Q(i){for(let e of he)if(i<=e.zoom)return e.threshold;return 48}function q({primaryType:i,markers:e,map:t,selectedMarkerId:a,zoom:r,collisionThresholdPx:n,dotCollisionThresholdPx:s}){if(!e.length)return[];if(!t)return e.map(u=>({kind:"primary",marker:u,key:`primary-${u.tripadvisor_id}`}));let m=e.map((u,b)=>{let g=u.location;if(typeof(g==null?void 0:g.lon)!="number"||typeof(g==null?void 0:g.lat)!="number")return null;let{x:c,y:h}=t.project([g.lon,g.lat]);return{marker:u,index:b,x:c,y:h}}).filter(u=>!!u);if(!m.length)return[];let p=Q(r),f=ye(r),y=m.map((u,b)=>b),M=u=>y[u]===u?u:(y[u]=M(y[u]),y[u]),l=(u,b)=>{let g=M(u),c=M(b);g!==c&&(y[c]=g)};for(let u=0;u<m.length;u+=1)for(let b=u+1;b<m.length;b+=1){let g=m[u].x-m[b].x,c=m[u].y-m[b].y;Math.hypot(g,c)<=p&&l(u,b)}let o=new Map;for(let u of m){let b=M(u.index),g=o.get(b);g?g.push(u):o.set(b,[u])}let d=[];return o.forEach(u=>{var x,L;if(u.length===1){let[{marker:k}]=u,P=k.type===i,C=a===k.tripadvisor_id;d.push({kind:"primary",marker:k,key:`primary-${k.tripadvisor_id}-p${P?1:0}-s${C?1:0}-${(x=k.pricing)==null?void 0:x.availability}`});return}let b=[...u].sort((k,P)=>be(P.marker,k.marker,i)),[g,...c]=b,h=g.marker.type===i,v=a===g.marker.tripadvisor_id;if(d.push({kind:"primary",marker:g.marker,key:`primary-${g.marker.tripadvisor_id}-p${h?1:0}-s${v?1:0}-${(L=g.marker.pricing)==null?void 0:L.availability}`}),!c.length)return;let A=[],T=[];if(c.forEach(k=>{var P;if(a&&k.marker.tripadvisor_id===a){let C=k.marker.type===i;d.push({kind:"primary",marker:k.marker,key:`primary-${k.marker.tripadvisor_id}-p${C?1:0}-s1-${(P=k.marker.pricing)==null?void 0:P.availability}`});return}ge(g,k)<=f?A.push(k):T.push(k)}),A.forEach(k=>{var C;let P=k.marker.type===i;d.push({kind:"dot",marker:k.marker,key:`dot-${k.marker.tripadvisor_id}-p${P?1:0}-s0-${(C=k.marker.pricing)==null?void 0:C.availability}`,parentId:g.marker.tripadvisor_id})}),T.length){let k=q({markers:T.map(P=>P.marker),map:t,selectedMarkerId:a,zoom:r,primaryType:i,collisionThresholdPx:n,dotCollisionThresholdPx:s});d.push(...k)}}),d}function ge(i,e){return Math.hypot(i.x-e.x,i.y-e.y)}function ye(i){let e=Q(i);return Math.max(48,e)}function be(i,e,t){var p,f;let a=i.type===t,r=e.type===t;if(a&&!r)return 1;if(!a&&r)return-1;let n=X(i)-X(e);if(n!==0)return n;let s=J(i)-J(e);if(s!==0)return s;let m=((p=i.reviews)!=null?p:0)-((f=e.reviews)!=null?f:0);return m!==0?m:i.tripadvisor_id-e.tripadvisor_id}function X(i){if(typeof i.rating=="number")return i.rating;if(i.rating===void 0||i.rating===null)return-1/0;let e=Number(i.rating);return Number.isNaN(e)?-1/0:e}function J(i){var t,a,r;if(!((a=(t=i.pricing)==null?void 0:t.offer)!=null&&a.price))return-1/0;let e=Number(((r=i.pricing.offer.displayPrice)!=null?r:"0").replace(/[^0-9.,-]+/g,"").replace(/,/g,""));return Number.isNaN(e)?-1/0:e}function Me(i){let e=[];return i.amenities&&Array.isArray(i.amenities)&&i.amenities.forEach(t=>{e.push({id:`amenity-${t}`,label:t,type:"amenity",value:t})}),i.hotelStyle&&Array.isArray(i.hotelStyle)&&i.hotelStyle.forEach(t=>{e.push({id:`hotelStyle-${t}`,label:t,type:"hotelStyle",value:t})}),i.price&&e.push({id:"priceRange",label:"Price Range",type:"priceRange",value:`${i.price.min}-${i.price.max}`,priceRange:i.price}),typeof i.minRating=="number"&&Number.isFinite(i.minRating)&&e.push({id:"minRating",label:`${i.minRating}+`,type:"minRating",value:String(i.minRating),numericValue:i.minRating}),typeof i.starRating=="number"&&Number.isFinite(i.starRating)&&e.push({id:"starRating",label:`${i.starRating} Stars`,type:"starRating",value:String(i.starRating),numericValue:i.starRating}),i.transformed_query&&e.push({id:"transformed_query",label:i.transformed_query,type:"transformed_query",value:i.transformed_query}),i.selected_restaurant_price_levels&&e.push({id:"selected_restaurant_price_levels",label:i.selected_restaurant_price_levels.join(", "),type:"selected_restaurant_price_levels",value:i.selected_restaurant_price_levels.join(", "),priceLevels:i.selected_restaurant_price_levels}),e}function ke(i){return i.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 a=e.priceRange.min,r=e.priceRange.max;a!==void 0&&(t.priceRange={min:a,...r!==void 0&&{max:r}})}return e.priceLevels&&(t.priceLevels=e.priceLevels),t})}var ve={prod:"https://api.mapfirst.ai",test:"https://api.mapfirst.ai/test"},N=class extends Error{constructor({message:e,status:t,code:a}){super(e),this.name="PropertiesFetchError",this.status=t,this.code=a}};async function K(i,e=1){try{let t=await fetch(`https://l4detuz832.execute-api.us-east-1.amazonaws.com/dev/photo?id=${i}&limit=${e}`);if(!t.ok)return null;let a=await t.json();if(a.photos&&a.photos.length>0){let r=a.photos[0].FullSizeURL.url;if((await fetch(r)).ok)return r}return null}catch(t){return console.debug("Failed to fetch images:",t),null}}async function Pe(i,e,t,{signal:a}={}){var s,m;let r;try{document.referrer&&(r=document.referrer)}catch(p){console.error(p)}let n=await fetch(i,{method:"POST",headers:{"Content-Type":"application/json","X-Source":"SDK",...t&&{"X-API-Key":t},...r&&{"X-Referer":r}},body:JSON.stringify(e),signal:a});if(!n.ok){let p=`Unexpected response: ${n.status}`,f;try{let y=await n.json();p=(m=(s=y.detail)!=null?s:y.error)!=null?m:p,f=y.code}catch{}throw new N({message:p,status:n.status,code:f})}return await n.json()}function ee(i){return typeof i=="string"?i:i.toISOString().slice(0,10)}var te="Accommodation";function xe(){let e=new Date(Date.now()+864e6),t=(6-e.getDay()+7)%7,a=new Date(e.getTime()+t*864e5),r=a.getDay(),n=r===0?6:6-r,s=new Date(a.getTime()+(n+1)*864e5);return{checkIn:a,checkOut:s}}var re=class{constructor(e){this.options=e;this.adapter=null;this.properties=[];this.selectedMarkerId=null;this.destroyed=!1;this.clusterItems=[];this.isMapAttached=!1;var r,n,s,m,p,f,y,M,l,o,d,u,b,g,c,h,v,A,T,x,L;if(this.properties=[...(r=e.properties)!=null?r:[]],this.primaryType=e.primaryType,this.selectedMarkerId=(n=e.selectedMarkerId)!=null?n:null,this.useApi=(s=e.useApi)!=null?s:!0,this.environment=(m=e.environment)!=null?m:"prod",this.apiUrl=(p=e.apiUrl)!=null?p:ve[this.environment],this.apiKey=e.apiKey,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=ae(e);this.fitBoundsPadding={top:(y=(f=e.fitBoundsPadding)==null?void 0:f.top)!=null?y:t?0:50,bottom:(l=(M=e.fitBoundsPadding)==null?void 0:M.bottom)!=null?l:t?0:160,left:(d=(o=e.fitBoundsPadding)==null?void 0:o.left)!=null?d:t?0:50,right:(b=(u=e.fitBoundsPadding)==null?void 0:u.right)!=null?b:t?0:50};let a=xe();this.state={center:(g=e.initialLocationData)!=null&&g.latitude&&e.initialLocationData.longitude?[e.initialLocationData.latitude,e.initialLocationData.longitude]:[0,0],zoom:(h=(c=e.initialLocationData)==null?void 0:c.zoom)!=null?h:0,bounds:(A=(v=e.initialLocationData)==null?void 0:v.bounds)!=null?A:null,pendingBounds:null,tempBounds:null,properties:this.properties,primary:(T=this.primaryType)!=null?T:te,selectedPropertyId:this.selectedMarkerId,initialLoading:!0,isSearching:!1,firstCallDone:!1,filters:{checkIn:a.checkIn,checkOut:a.checkOut,numAdults:2,numRooms:1,...((x=e.initialLocationData)==null?void 0:x.currency)&&{currency:e.initialLocationData.currency}},activeLocation:{country:"",location_id:null,locationName:"",coordinates:[0,0]},isFlyToAnimating:!1,...e.state},this.callbacks=(L=e.callbacks)!=null?L:{},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){var t;if(!this.useApi){console.warn("initializeFromLocationData requires API usage. Set useApi to true.");return}try{let{city:a,state:r,country:n,query:s,latitude:m,longitude:p,radius:f,bounds:y}=e,M={filters:this.getFilters(),initial:!0,query:s,latitude:m,longitude:p,radius:f,bounds:y},l=[a,r].filter(Boolean).join(", ");if(n||l){let o=await fetch(`${this.apiUrl}/geo-lookup2?${new URLSearchParams({...n&&{country_code:n},...l&&{query:l}}).toString()}`,{headers:{...this.apiKey&&{"X-API-Key":this.apiKey}}});if(o.ok){let d=await o.json();M.city=["country","island","state"].includes(d.type)?void 0:d.name,M.state=d.type==="state"?d.name:["country","island","county"].includes(d.type)?void 0:d.state,M.country=["country","island"].includes(d.type)?d.name:d.country,M.location_id=d.id,M.latitude=d.lat,M.longitude=d.lon,this.setActiveLocation({city:a,state:r,country:n,location_id:(t=d.id)!=null?t:null,locationName:[a,r,n].filter(Boolean).join(", "),...d.lon&&d.lat&&{coordinates:[d.lat,d.lon]}}),d.lon&&d.lat&&this.setState({center:[d.lat,d.lon],zoom:a?12:r?8:5})}else this.handleError(new Error(`Geo mapping fetch failed: ${o.statusText}`),"initializeFromLocationData")}this.requestBody=M,this.isMapAttached&&await this.autoLoadProperties()}catch(a){this.handleError(a,"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 a,r;this.handleError(t,"autoLoadProperties"),(r=(a=this.callbacks).onPropertiesLoadError)==null||r.call(a,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 r=this.adapter.getMarkerManager();r==null||r.destroy(),this.adapter.cleanup()}let a={...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(a),this.isMapAttached=!0,this.refresh(),this.requestBody&&!this.state.firstCallDone&&this.autoLoadProperties()}createAdapter(e){return Le(e)&&e.mapInstance?this.initializeAdapter(new F(e.mapInstance),{maplibregl:e.maplibregl,onMarkerClick:e.onMarkerClick}):ae(e)&&e.mapInstance?this.initializeAdapter(new H(e.mapInstance),{google:e.google,onMarkerClick:e.onMarkerClick}):Te(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){return e.initialize({...t,onMarkerClick:a=>{var r;a.location&&this.flyMapTo(a.location.lon,a.location.lat,14),a.type!==this.primaryType&&this.setPrimaryType(a.type),this.setSelectedMarker(a.tripadvisor_id===this.selectedMarkerId?null:a.tripadvisor_id),(r=t.onMarkerClick)==null||r.call(t,a)},onRefresh:()=>this.refresh(),onMapMoveEnd:a=>{this.state.tempBounds===null?(this.setTempBounds(a),this.setPendingBounds(null)):this.handleMapMoveEnd(a)}}),this.useApi&&e.setupImpressionTracking(()=>{}),e}_setProperties(e){var t,a;this.ensureAlive(),this.properties=[...e.filter(r=>{var n;return r.type==="Accommodation"?((n=r.pricing)==null?void 0:n.availability)!=="unavailable":!0})],this.updateState({properties:this.properties}),(a=(t=this.callbacks).onPropertiesChange)==null||a.call(t,e),this.refresh()}addProperty(e){var t,a;this.ensureAlive(),this.properties=[...this.properties,e],this.updateState({properties:this.properties}),(a=(t=this.callbacks).onPropertiesChange)==null||a.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,a;this.ensureAlive(),this.primaryType!==e&&(this.primaryType=e,this.updateState({primary:e}),(a=(t=this.callbacks).onPrimaryTypeChange)==null||a.call(t,e),this.refresh())}setSelectedMarker(e){var t,a;if(this.ensureAlive(),this.selectedMarkerId!==e){if(e!==null){let r=this.properties.find(n=>n.tripadvisor_id===e);r&&r.type!==this.primaryType&&this.setPrimaryType(r.type)}this.selectedMarkerId=e,this.updateState({selectedPropertyId:e}),(a=(t=this.callbacks).onSelectedPropertyChange)==null||a.call(t,e),this.refresh()}}getState(){return{...this.state}}handleError(e,t="MapFirstCore"){let a=e instanceof Error?e.message:String(e),r=e instanceof Error?e:new Error(a);console.error(`[${t}]`,a),this.callbacks.onError&&this.callbacks.onError(r,t)}updateState(e){this.state={...this.state,...e}}setState(e){var a,r,n,s,m,p,f,y,M,l,o,d,u,b,g,c;let t={...this.state};this.updateState(e),e.center!==void 0&&e.center!==t.center&&((r=(a=this.callbacks).onCenterChange)==null||r.call(a,e.center,this.state.zoom)),e.zoom!==void 0&&e.zoom!==t.zoom&&((s=(n=this.callbacks).onZoomChange)==null||s.call(n,e.zoom)),e.bounds!==void 0&&e.bounds!==t.bounds&&((p=(m=this.callbacks).onBoundsChange)==null||p.call(m,e.bounds)),e.pendingBounds!==void 0&&e.pendingBounds!==t.pendingBounds&&((y=(f=this.callbacks).onPendingBoundsChange)==null||y.call(f,e.pendingBounds)),e.filters!==void 0&&e.filters!==t.filters&&((l=(M=this.callbacks).onFiltersChange)==null||l.call(M,e.filters)),e.activeLocation!==void 0&&e.activeLocation!==t.activeLocation&&((d=(o=this.callbacks).onActiveLocationChange)==null||d.call(o,e.activeLocation)),e.initialLoading!==void 0&&e.initialLoading!==t.initialLoading&&((b=(u=this.callbacks).onLoadingStateChange)==null||b.call(u,e.initialLoading)),e.isSearching!==void 0&&e.isSearching!==t.isSearching&&((c=(g=this.callbacks).onSearchingStateChange)==null||c.call(g,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 a=.01;Math.abs(e.sw.lat-t.sw.lat)>a||Math.abs(e.sw.lng-t.sw.lng)>a||Math.abs(e.ne.lat-t.ne.lat)>a||Math.abs(e.ne.lng-t.ne.lng)>a?this.setState({pendingBounds:e}):this.setState({pendingBounds:null})}flyMapTo(e,t,a,r=!0){if(this.ensureAlive(),this.setState({center:[t,e]}),typeof a=="number"&&this.setState({zoom:a}),!this.adapter)return;let n=this.adapter.getMap();if(n){if(this.currentPlatform==="google"){this.setFlyToAnimating(!1),n.setCenter({lat:t,lng:e}),a!==null&&typeof a=="number"&&n.setZoom(a!=null?a:13);return}if(r===!1){this.setFlyToAnimating(!1),n.jumpTo&&n.jumpTo({center:[e,t],...a!==null&&{zoom:a!=null?a:13}});return}this.setFlyToAnimating(!0),n.flyTo&&n.flyTo({center:[e,t],...a!==null&&{zoom:a!=null?a:13}})}}flyToPOIs(e,t,a=!0){var s,m;if(this.ensureAlive(),!this.adapter)return;let r=this.adapter.getMap();if(!r)return;let n=e;if((!n||n.length===0)&&(n=this.properties.filter(p=>p.location!==void 0&&(t!==void 0?p.type===t:!0)).map(p=>({lat:p.location.lat,lng:p.location.lon}))),!(!n||n.length===0)){if(n.length===1){let p=n[0];this.currentPlatform==="google"?(r.setCenter({lat:p.lat,lng:p.lng}),r.setZoom(13)):r.flyTo&&r.flyTo({center:[p.lng,p.lat],zoom:13})}else if(this.currentPlatform==="google"){let p=(m=(s=window.google)==null?void 0:s.maps)==null?void 0:m.LatLngBounds;if(p){let f=new p;n.forEach(y=>{f.extend({lat:y.lat,lng:y.lng})}),a&&this.setFlyToAnimating(!0),r.fitBounds(f,this.fitBoundsPadding)}}else if(r.fitBounds){let p=[[n[0].lng,n[0].lat],[n[0].lng,n[0].lat]];n.forEach(f=>{p[0][0]=Math.min(p[0][0],f.lng),p[0][1]=Math.min(p[0][1],f.lat),p[1][0]=Math.max(p[1][0],f.lng),p[1][1]=Math.max(p[1][1],f.lat)}),a&&this.setFlyToAnimating(!0),r.fitBounds(p,{padding:this.fitBoundsPadding,animate:a})}}}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 pollForPricing({pollingLink:e,maxAttempts:t=15,delayMs:a=2e3,isCancelled:r,price:n,limit:s}){var l,o,d,u,b;if(this.ensureAlive(),!this.useApi)return console.warn("pollForPricing requires API usage. Set useApi to true."),{completed:!1};if(!e)return{completed:!1};let m=!1,p,f=this.getFilters();s&&(f.limit=s);let y={filters:f,pollingLink:e},M;try{document.referrer&&(M=document.referrer)}catch(g){console.error(g)}for(let g=0;g<t;g++){if(r!=null&&r())return{completed:m,pollData:p};try{let c=await fetch(`${this.apiUrl}/ta-polling?pollingNumber=${g}`,{method:"POST",body:JSON.stringify(y),headers:{"Content-Type":"application/json","X-Source":"SDK",...this.apiKey&&{"X-API-Key":this.apiKey},...M&&{"X-Referer":M}}});if(!c.ok)throw new N({message:`Poll failed: ${c.status}`,status:c.status});if(p=await c.json(),r!=null&&r())return{completed:m,pollData:p};let h=(o=(l=p==null?void 0:p.success)==null?void 0:l.results)!=null?o:[];if(h.length>0&&this.setProperties(v=>{let A=new Set(h.map(x=>x.tripadvisor_id)),T=v.filter(x=>x.type!=="Accommodation"||A.has(x.tripadvisor_id));return h.forEach(x=>{var k,P,C,w,j,G;if(!x.location)return;(P=(k=x.pricing)==null?void 0:k.offer)!=null&&P.price&&n&&(((w=(C=x.pricing)==null?void 0:C.offer)==null?void 0:w.price)<(n==null?void 0:n.min)||((G=(j=x.pricing)==null?void 0:j.offer)==null?void 0:G.price)>(n==null?void 0:n.max))&&(x.pricing.availability="unavailable");let L=T.findIndex(ie=>ie.tripadvisor_id===x.tripadvisor_id);L>=0?T[L]=x:T.push(x)}),T}),(d=p==null?void 0:p.success)!=null&&d.isComplete){m=!0,this.setSearching(!1);break}}catch(c){this.handleError(c,"pollForPricing"),(b=(u=this.callbacks).onPropertiesLoadError)==null||b.call(u,c);break}g<t-1&&await new Promise(c=>setTimeout(c,a))}return{completed:m,pollData:p}}setProperties(e){let t=e(this.properties);this._setProperties(t)}mostCommonTypeFromProperties(e){let t=e.reduce((a,r)=>(a[r.type]=(a[r.type]||0)+1,a),{});return Object.entries(t).reduce((a,r)=>t[a[0]]>t[r[0]]?a:r)[0]}async runPropertiesSearch({body:e,beforeApplyProperties:t,smartFiltersClearable:a,onError:r}){var n,s,m,p,f,y,M;if(this.ensureAlive(),!this.useApi)return console.warn("runPropertiesSearch requires API usage. Set useApi to true."),r==null||r(new Error("API usage is disabled")),null;this.setState({firstCallDone:!1}),this.setSearching(!0),this.clearProperties();try{let l=await Pe(`${this.apiUrl}/properties`,e,this.apiKey);this.updateActiveLocationFromResponse(l);let o=null,d=30,u=l.filters.primary_type;if(t){let c=t(l);o=(n=c.price)!=null?n:null,d=(s=c.limit)!=null?s:30}let b=l.properties.some(c=>!!c.location),g=o?l.properties.map(c=>{var h;return(h=c.pricing)!=null&&h.offer?{...c,pricing:{...c.pricing,availability:c.pricing.offer.price&&(c.pricing.offer.price<o.min||c.pricing.offer.price>o.max)?"unavailable":c.pricing.availability}}:c}):l.properties;if(this._setProperties(g),b&&this.flyToPOIs(l.properties.filter(c=>!!c.location&&(l.filters.primary_type?c.type===l.filters.primary_type:!0)).map(c=>({lat:c.location.lat,lng:c.location.lon})),void 0,e.initial!==!0),l.filters.primary_type&&l.properties.filter(c=>{var h;return c.type===l.filters.primary_type&&(c.type==="Accommodation"?((h=c.pricing)==null?void 0:h.availability)!=="unavailable":!0)}).length>0)u=l.filters.primary_type,this.setPrimaryType(l.filters.primary_type);else if(l.properties.length>0){let c=this.mostCommonTypeFromProperties(l.properties);this.setPrimaryType(c),u=c}if(this.setState({firstCallDone:!0}),l.isComplete===!1&&l.pollingLink){let{completed:c,pollData:h}=await this.pollForPricing({pollingLink:l.pollingLink,...o&&{price:o},...d&&{limit:d}});if(c&&((m=h==null?void 0:h.success)!=null&&m.results)&&h.success.results.filter(v=>{var A;return v.type===l.filters.primary_type&&(v.type==="Accommodation"?((A=v.pricing)==null?void 0:A.availability)!=="unavailable":!0)}).length===0&&u&&u!==l.filters.primary_type){let v=this.mostCommonTypeFromProperties(l.properties);this.setPrimaryType(v)}c&&this.refresh()}else l.isComplete===!0&&this.setSearching(!1);return b||(l.properties.some(c=>!!c.location)?this.flyToPOIs(l.properties.filter(c=>!!c.location&&(l.filters.primary_type?c.type===l.filters.primary_type:!0)).map(c=>({lat:c.location.lat,lng:c.location.lon})),void 0,e.initial!==!0):(p=l.filters.location)!=null&&p.latitude&&((f=l.filters.location)!=null&&f.longitude)&&this.flyMapTo(l.filters.location.longitude,l.filters.location.latitude,12,e.initial!==!0)),l}catch(l){return this.handleError(l,"runPropertiesSearch"),r==null||r(l),(M=(y=this.callbacks).onPropertiesLoadError)==null||M.call(y,l),this.clearProperties(),this.setState({firstCallDone:!0}),this.setSearching(!1),null}}async performBoundsSearch(){var n;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},a=(n=e==null?void 0:e.price)!=null?n:void 0,r=await this.runPropertiesSearch({body:t,beforeApplyProperties:()=>({price:a!=null?a:null})});return r&&(this.setBounds(this.state.pendingBounds),this.setTempBounds(this.state.pendingBounds),this.setPendingBounds(null)),r}updateActiveLocationFromResponse(e){var m,p,f,y;let t=(m=e.location_id)!=null?m:null,a=(f=(p=e.filters.location)==null?void 0:p.city)!=null?f:void 0,r=((y=e.filters.location)==null?void 0:y.country)||"",n=e.filters.location?[e.filters.location.latitude,e.filters.location.longitude]:void 0;if(!n)return;let s=this.state.activeLocation;(t!==(s==null?void 0:s.location_id)||a!==(s==null?void 0:s.city)||r!==(s==null?void 0:s.country))&&this.setActiveLocation({city:a,country:r,location_id:t,locationName:a&&r?`${a}, ${r}`:r||"",coordinates:n})}async runSmartFilterSearch({query:e,filters:t,onProcessFilters:a,onError:r}){if(this.ensureAlive(),!this.useApi)return console.warn("runSmartFilterSearch requires API usage. Set useApi to true."),r==null||r(new Error("API usage is disabled")),null;let n=this.getFilters(),s=this.getState();if(t&&t.length>0){let p=new Set,f=new Set,y,M,l,o,d,u;t.forEach(b=>{var g,c,h;switch(b.type){case"amenity":p.add(b.value);break;case"hotelStyle":f.add(b.value);break;case"priceRange":b.priceRange&&(y={min:b.priceRange.min,max:(g=b.priceRange.max)!=null?g:0});break;case"minRating":M=(c=b.numericValue)!=null?c:Number(b.value);break;case"starRating":l=(h=b.numericValue)!=null?h:Number(b.value);break;case"primary_type":o=b.propertyType;break;case"transformed_query":d=b.value;break;case"selected_restaurant_price_levels":u=b.priceLevels;break}}),n={...n,...p.size>0&&{amenities:Array.from(p)},...f.size>0&&{hotelStyle:Array.from(f)},...y&&{price:y},...M!==void 0&&{minRating:M},...l!==void 0&&{starRating:l},...o&&{primary_type:o},...d&&{transformed_query:d},...u&&{selected_restaurant_price_levels:u}}}else e||(n.minRating=4);let m={filters:n,...e&&{query:e},...s.bounds?{bounds:s.bounds}:s.activeLocation.location_id?{location_id:s.activeLocation.location_id}:s.activeLocation.coordinates?{latitude:s.activeLocation.coordinates[0],longitude:s.activeLocation.coordinates[1]}:{}};return this.runPropertiesSearch({body:m,beforeApplyProperties:a?p=>{var y,M;let f=a(p.filters,p.location_id);return{price:(y=f.price)!=null?y:null,limit:(M=f.limit)!=null?M:30}}:void 0,smartFiltersClearable:!!e,onError:r})}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,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 r,n,s;if(this.ensureAlive(),!this.adapter)return;let e=this.safeExtractViewState(),t=this.resolvePrimaryType();this.clusterItems=q({primaryType:t,markers:this.properties,map:this.adapter,selectedMarkerId:this.selectedMarkerId,zoom:(r=e==null?void 0:e.zoom)!=null?r:0}),this.adapter.getMarkerManager().render(this.clusterItems,t,this.selectedMarkerId),(s=(n=this.options).onClusterUpdate)==null||s.call(n,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,a;return(a=(t=this.primaryType)!=null?t:(e=this.properties.find(r=>r.type))==null?void 0:e.type)!=null?a:te}safeExtractViewState(){if(!this.adapter)return null;try{return Y(this.adapter)}catch{return null}}ensureAlive(){if(this.destroyed)throw new Error("MapFirstCore instance has been destroyed")}};function Le(i){return i.platform==="maplibre"}function ae(i){return i.platform==="google"}function Te(i){return i.platform==="mapbox"}export{re as MapFirstCore,N as PropertiesFetchError,ke as convertToApiFilters,K as fetchImages,Pe as fetchProperties,Me as processApiFilters};
32
+ `,t}function de(i,e){let t=i.querySelector(".mapfirst-property-hover-image");if(t&&e.tripadvisor_id&&!t.dataset.imageLoaded){t.dataset.imageLoaded="loading";let a=t.dataset.defaultImage;K(e.tripadvisor_id,1).then(r=>{if(r&&t){let n=document.createElement("img");n.src=r,n.alt=e.name,n.style.width="100%",n.style.height="100%",n.style.objectFit="cover",t.innerHTML="",t.appendChild(n),t.classList.remove("mapfirst-property-hover-image-placeholder"),t.dataset.imageLoaded="true"}else throw new Error("No image URL")}).catch(()=>{if(a&&t){let r=document.createElement("img");r.src=a,r.alt=e.name,r.style.width="100%",r.style.height="100%",r.style.objectFit="cover",t.innerHTML="",t.appendChild(r),t.classList.remove("mapfirst-property-hover-image-placeholder"),t.dataset.imageLoaded="false"}})}}function V(i,e,t){let a=e.getBoundingClientRect(),r=t.getBoundingClientRect(),n=270,s=120,m=12,p=r.right-a.right,f=a.left-r.left,y=r.bottom-a.bottom,M=a.top-r.top,l=a.left-r.left+a.width/2-n/2,o=a.top-r.top+a.height+m;l<0?l=8:l+n>r.width&&(l=r.width-n-8),y<s+m&&M>y&&(o=a.top-r.top-s-m),i.style.left=`${l}px`,i.style.top=`${o}px`}function U(i,e,t,a){var u,b,g,c,h,v,A,T,x;if(typeof document=="undefined")return null;let r=i.marker,n=r.type===e,s=t===r.tripadvisor_id,m=r.type==="Accommodation",p=(b=(u=r.pricing)==null?void 0:u.offer)==null?void 0:b.displayPrice,f=m&&!p,y=(()=>{if(r.rating===void 0||r.rating===null)return null;let L=typeof r.rating=="number"?r.rating:Number(r.rating);return Number.isNaN(L)||L<=0?null:L.toFixed(1)})(),M=document.createElement("div");M.className="mapfirst-marker-root",M.style.zIndex=s?"20":n?"12":"11";let l=(h=(c=(g=r.pricing)==null?void 0:g.offer)==null?void 0:c.clickUrl)!=null?h:r.url,o=document.createElement(l?"a":"div");if(l&&(o.href=l,o.target="_blank",o.style.textDecoration="none"),o.className=f?"mapfirst-marker-pill mapfirst-marker-pill-pending":`mapfirst-marker-pill mapfirst-marker-pill-active${s?" mapfirst-marker-selected":n?"":" mapfirst-marker-non-primary"}`,!f&&((v=r.awards)!=null&&v.length||y)){let L=document.createElement("div");if(L.className="mapfirst-marker-badge",n||(L.style.opacity="0.2"),L.className="mapfirst-marker-badge",(A=r.awards)!=null&&A.length&&r.awards[0].type){let k=document.createElement("div");k.className="mapfirst-marker-award-container";let P=document.createElement("div");P.className="mapfirst-marker-award-back",P.innerHTML=se;let C=document.createElement("div");C.className=`mapfirst-marker-award-dot mapfirst-marker-award-dot-type-${r.awards[0].type}`;let w=document.createElement("div");w.className="mapfirst-marker-award-front",w.innerHTML=ne,k.appendChild(P),k.appendChild(C),k.appendChild(w),L.appendChild(k)}else y&&(L.className="mapfirst-marker-badge mapfirst-marker-rating-badge",L.textContent=y);o.appendChild(L)}let d=document.createElement("span");return d.className="mapfirst-marker-content",m?(x=(T=r.pricing)==null?void 0:T.offer)!=null&&x.displayPrice?(d.innerHTML=r.pricing.offer.displayPrice,d.dataset.price=r.pricing.offer.displayPrice):(d.innerHTML=le,d.dataset.price=""):r.type==="Eat & Drink"?d.innerHTML=oe:r.type==="Attraction"&&(d.innerHTML=pe),o.appendChild(d),o.addEventListener("click",L=>{L.stopPropagation(),f||a==null||a(r)}),f||E(M,o,r,s),M.appendChild(o),M}function Z(i,e,t,a){var M,l,o;if(typeof document=="undefined")return null;let r=i.marker,n=r.type===e,s=t===r.tripadvisor_id,p=r.type==="Accommodation"&&((l=(M=r.pricing)==null?void 0:M.offer)==null?void 0:l.availability)!=="available",f=document.createElement("div");f.className="mapfirst-dot-marker-container",f.style.zIndex=s?"20":n?"3":"1";let y=document.createElement("div");return y.className=p?"mapfirst-dot-marker-button mapfirst-dot-marker-button-pending":`mapfirst-dot-marker-button mapfirst-dot-marker-button-active${s?" mapfirst-dot-marker-selected":n?"":" mapfirst-dot-marker-non-primary"}`,y.title=(o=r.name)!=null?o:String(r.tripadvisor_id),y.addEventListener("click",d=>{d.stopPropagation(),p||a==null||a(r)}),f.appendChild(y),p||E(f,y,r,s),f}var ue='<video class="mapfirst-marker-loading-video" src="https://api.mapfirst.ai/static/images/loading.webm" autoplay loop muted></video>';function z(i,e,t,a,r){var f,y,M,l,o,d,u,b,g,c;let n=(y=(f=i.querySelector(".mapfirst-marker-pill"))==null?void 0:f.classList.contains("mapfirst-marker-pill-pending"))!=null?y:!1,s=i;s.style.zIndex=t?"20":e?"12":"11";let m=s.querySelector(".mapfirst-marker-pill");m&&(a?m.className="mapfirst-marker-pill mapfirst-marker-pill-pending":m.className=`mapfirst-marker-pill mapfirst-marker-pill-active${t?" mapfirst-marker-selected":e?"":" mapfirst-marker-non-primary"}`);let p=s.querySelector(".mapfirst-marker-badge");if(p instanceof HTMLElement&&(p.style.opacity=!e&&!t?"0.2":""),n&&!a&&r){let h=s.querySelector(".mapfirst-marker-pill");h instanceof HTMLElement&&E(s,h,r,t)}if(r&&r.type==="Accommodation"){let h=s.querySelector(".mapfirst-marker-content");if(h instanceof HTMLElement){let v=(l=(M=r.pricing)==null?void 0:M.offer)==null?void 0:l.displayPrice;h.dataset.price!==v&&(v?(h.innerHTML=v,h.dataset.price=v):(h.innerHTML=ue,h.dataset.price=""))}}if(r){let h=document.querySelector(`.mapfirst-property-hover-card[data-marker-id="${r.tripadvisor_id}"]`);if(h){let v=r.rating||0,A=r.reviews||0,T=(u=(d=(o=r.pricing)==null?void 0:o.offer)==null?void 0:d.displayPrice)!=null?u:r.price_level,x=h.querySelector(".rating-value");if(x){let P=v.toFixed(1);x.textContent!==P&&(x.textContent=P)}let L=h.querySelector(".reviews");if(L){let P=`(${A})`;L.textContent!==P&&(L.textContent=P)}if(r.type==="Accommodation"&&T){let P=h.querySelector(".mapfirst-property-hover-price");if(!P){P=document.createElement("div"),P.className="mapfirst-property-hover-price";let C=h.querySelector(".mapfirst-property-hover-details"),w=h.querySelector(".mapfirst-property-hover-learn-more");C&&(w?C.insertBefore(P,w):C.appendChild(P))}if(P){let C=`Starting at <strong>${T}</strong>`;P.innerHTML!==C&&(P.innerHTML=C)}}let k=(c=(g=(b=r.pricing)==null?void 0:b.offer)==null?void 0:g.clickUrl)!=null?c:r.url;k&&h instanceof HTMLAnchorElement&&h.href!==k&&(h.href=k)}}}function $(i,e,t,a){let r=i;r.style.zIndex=t?"20":e?"3":"1";let n=r.querySelector(".mapfirst-dot-marker-button");n&&(a?n.className="mapfirst-dot-marker-button mapfirst-dot-marker-button-pending":n.className=`mapfirst-dot-marker-button mapfirst-dot-marker-button-active${t?" mapfirst-dot-marker-selected":e?"":" mapfirst-dot-marker-non-primary"}`)}function W(i){let e=i.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,a){var n,s,m,p,f,y,M,l;t&&t!==this.primaryType&&(this.primaryType=t),a!==void 0&&(this.selectedMarkerId=a);let r=new Set(e.map(o=>o.key));for(let[o,d]of this.markerCache.entries())r.has(o)||(this.removeMarkerFromMap(d.marker),this.markerCache.delete(o));for(let o of e){let d=fe(o.marker.location);if(!d)continue;let u=this.markerCache.get(o.key);if(u){let b=o.marker.type===this.primaryType,g=this.selectedMarkerId===o.marker.tripadvisor_id,c=o.marker.type==="Accommodation",h=o.kind==="primary"?c&&!((s=(n=o.marker.pricing)==null?void 0:n.offer)!=null&&s.displayPrice):c&&((p=(m=o.marker.pricing)==null?void 0:m.offer)==null?void 0:p.availability)!=="available",v=this.getMarkerElement(u.marker);v&&(o.kind==="primary"?z(v,b,g,h,o.marker):$(v,b,g,h));try{this.updateMarkerPosition(u.marker,d)}catch{this.removeMarkerFromMap(u.marker),this.markerCache.delete(o.key),this.createAndAddMarker(o,d)}}else{let b=o.marker.tripadvisor_id,g,c;for(let[h,v]of this.markerCache.entries())if(W(h)===b&&v.kind===o.kind){g=v,c=h;break}if(g&&c){let h=o.marker.type===this.primaryType,v=this.selectedMarkerId===o.marker.tripadvisor_id,A=o.marker.type==="Accommodation",T=o.kind==="primary"?A&&!((y=(f=o.marker.pricing)==null?void 0:f.offer)!=null&&y.displayPrice):A&&((l=(M=o.marker.pricing)==null?void 0:M.offer)==null?void 0:l.availability)!=="available",x=this.getMarkerElement(g.marker);x&&(o.kind==="primary"?z(x,h,v,T,o.marker):$(x,h,v,T)),this.updateMarkerZIndex(g.marker,o,h,v),this.markerCache.delete(c),this.markerCache.set(o.key,g);try{this.updateMarkerPosition(g.marker,d)}catch{}}else this.createAndAddMarker(o,d)}}}destroy(){for(let e of this.markerCache.values())this.removeMarkerFromMap(e.marker);this.markerCache.clear()}createAndAddMarker(e,t){let a=e.kind==="primary"?U(e,this.primaryType,this.selectedMarkerId,this.onMarkerClick):Z(e,this.primaryType,this.selectedMarkerId,this.onMarkerClick);if(!a)return;let r=e.marker.type===this.primaryType,n=this.selectedMarkerId===e.marker.tripadvisor_id;try{let s=this.createMarker(a,t,e,r,n);s&&this.markerCache.set(e.key,{key:e.key,marker:s,kind:e.kind,parentId:e.kind==="dot"?e.parentId:void 0})}catch(s){console.error("Error creating marker",s)}}updateMarkerZIndex(e,t,a,r){}};function fe(i){return typeof(i==null?void 0:i.lon)!="number"||typeof(i==null?void 0:i.lat)!="number"||Number.isNaN(i.lon)||Number.isNaN(i.lat)?null:{lon:i.lon,lat:i.lat}}var B=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,a){this.MarkerCtor&&super.render(e,t,a)}createMarker(e,t,a){return this.MarkerCtor?new this.MarkerCtor({element:e,anchor:a.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 _=class extends I{constructor(e){super(e.mapInstance,e.onMarkerClick),this.google=e.google}render(e,t,a){var r,n;if(!((n=(r=this.google)==null?void 0:r.marker)!=null&&n.AdvancedMarkerElement)){console.warn("AdvancedMarkerElement not available");return}super.render(e,t,a)}createMarker(e,t,a,r,n){var m,p;if(!((p=(m=this.google)==null?void 0:m.marker)!=null&&p.AdvancedMarkerElement))return null;let s=a.kind==="primary"?n?20:r?12:11:n?20:r?3:1;return new this.google.marker.AdvancedMarkerElement({map:this.mapInstance,position:{lat:t.lat,lng:t.lon},content:e,zIndex:s})}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,a,r){let n=t.kind==="primary"?r?20:a?12:11:r?20:a?3:1;e.zIndex=n}};var R=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,a){this.MarkerCtor&&super.render(e,t,a)}createMarker(e,t,a){return this.MarkerCtor?new this.MarkerCtor({element:e,anchor:a.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 a=new IntersectionObserver(s=>{s.forEach(m=>{m.isIntersecting&&(e(),a.disconnect())})},{threshold:.1});a.observe(t);let r=()=>a.disconnect(),n=this.cleanup.bind(this);this.cleanup=()=>{r(),n()}}};var F=class extends S{constructor(t){super(t);this.cleanupFns=[]}initialize(t){return this.markerManager=new B({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 a=()=>{let n=this.getMapBounds();t(n)},r=()=>{let n=this.getMapBounds();t(n)};this.map.loaded&&this.map.loaded()?r():(this.map.once("load",r),this.cleanupFns.push(()=>{typeof this.map.off=="function"&&this.map.off("load",r)})),this.map.on("moveend",a),this.cleanupFns.push(()=>{typeof this.map.off=="function"&&this.map.off("moveend",a)})}attachEventListeners(t){if(!this.map||typeof this.map.on!="function")return;["move","zoom","dragend","pitch","rotate"].forEach(r=>{this.map.on(r,t),this.cleanupFns.push(()=>{typeof this.map.off=="function"&&this.map.off(r,t)})})}getMarkerManager(){return this.markerManager}getContainer(){var t,a;return((a=(t=this.map)==null?void 0:t.getContainer)==null?void 0:a.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(),a=t.getSouthWest(),r=t.getNorthEast();return{sw:{lat:a.lat,lng:a.lng},ne:{lat:r.lat,lng:r.lng}}}project(t){return this.map.project({lng:t[0],lat:t[1]})}on(t,a){this.map.on(t,a)}off(t,a){this.map.off(t,a)}resize(){this.map.resize()}remove(){this.cleanup(),this.map.remove()}};var H=class extends S{constructor(t){super(t);this.cleanupFns=[];this.initializeOverlayView()}initialize(t){return this.markerManager=new _({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,a){if(!this.map)return;let r=()=>{let s=this.getMapBounds();t(s)};r();let n=a.event.addListener(this.map,"idle",r);this.cleanupFns.push(()=>{a.event.removeListener(n)})}attachEventListeners(t){let a=["center_changed","zoom_changed","drag","heading_changed","tilt_changed"],r=[];a.forEach(n=>{let s=this.map.addListener(n,t);r.push(s)}),this.cleanupFns.push(()=>{r.forEach(n=>{try{n.remove()}catch{}})})}getMarkerManager(){return this.markerManager}getContainer(){var t,a;return((a=(t=this.map)==null?void 0:t.getDiv)==null?void 0:a.call(t))||null}cleanup(){for(let t of this.cleanupFns)try{t()}catch{}this.cleanupFns.length=0}initializeOverlayView(){var r;let t=(r=globalThis.google)==null?void 0:r.maps;if(!t)return;let a=t.OverlayView;a&&(this.overlayView=new a,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 a=t.getSouthWest(),r=t.getNorthEast();return{sw:{lat:a.lat(),lng:a.lng()},ne:{lat:r.lat(),lng:r.lng()}}}project(t){var m;if(!this.overlayView)return{x:0,y:0};let a=this.overlayView.getProjection();if(!a)return{x:0,y:0};let r=(m=globalThis.google)==null?void 0:m.maps;if(!r)return{x:0,y:0};let n=new r.LatLng(t[1],t[0]),s=a.fromLatLngToContainerPixel(n);return s?{x:s.x,y:s.y}:{x:0,y:0}}on(t,a){this.map.addListener(t,a)}off(t,a){var n;let r=(n=globalThis.google)==null?void 0:n.maps;r!=null&&r.event&&r.event.clearListeners(this.map,t)}resize(){var a;let t=(a=globalThis.google)==null?void 0:a.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 R({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 a=()=>{let n=this.getMapBounds();t(n)},r=()=>{let n=this.getMapBounds();t(n)};this.map.loaded&&this.map.loaded()?r():(this.map.once("load",r),this.cleanupFns.push(()=>{typeof this.map.off=="function"&&this.map.off("load",r)})),this.map.on("moveend",a),this.cleanupFns.push(()=>{typeof this.map.off=="function"&&this.map.off("moveend",a)})}attachEventListeners(t){if(!this.map||typeof this.map.on!="function")return;["move","zoom","dragend","pitch","rotate"].forEach(r=>{this.map.on(r,t),this.cleanupFns.push(()=>{typeof this.map.off=="function"&&this.map.off(r,t)})})}getMarkerManager(){return this.markerManager}getContainer(){var t,a;return((a=(t=this.map)==null?void 0:t.getContainer)==null?void 0:a.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(),a=t.getSouthWest(),r=t.getNorthEast();return{sw:{lat:a.lat,lng:a.lng},ne:{lat:r.lat,lng:r.lng}}}project(t){return this.map.project({lng:t[0],lat:t[1]})}on(t,a){this.map.on(t,a)}off(t,a){this.map.off(t,a)}resize(){this.map.resize()}remove(){this.cleanup(),this.map.remove()}};function Y(i){let e=i.getCenter();return{longitude:e.lng,latitude:e.lat,zoom:i.getZoom(),bearing:i.getBearing(),pitch:i.getPitch()}}var he=[{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 Q(i){for(let e of he)if(i<=e.zoom)return e.threshold;return 48}function q({primaryType:i,markers:e,map:t,selectedMarkerId:a,zoom:r,collisionThresholdPx:n,dotCollisionThresholdPx:s}){if(!e.length)return[];if(!t)return e.map(u=>({kind:"primary",marker:u,key:`primary-${u.tripadvisor_id}`}));let m=e.map((u,b)=>{let g=u.location;if(typeof(g==null?void 0:g.lon)!="number"||typeof(g==null?void 0:g.lat)!="number")return null;let{x:c,y:h}=t.project([g.lon,g.lat]);return{marker:u,index:b,x:c,y:h}}).filter(u=>!!u);if(!m.length)return[];let p=Q(r),f=ye(r),y=m.map((u,b)=>b),M=u=>y[u]===u?u:(y[u]=M(y[u]),y[u]),l=(u,b)=>{let g=M(u),c=M(b);g!==c&&(y[c]=g)};for(let u=0;u<m.length;u+=1)for(let b=u+1;b<m.length;b+=1){let g=m[u].x-m[b].x,c=m[u].y-m[b].y;Math.hypot(g,c)<=p&&l(u,b)}let o=new Map;for(let u of m){let b=M(u.index),g=o.get(b);g?g.push(u):o.set(b,[u])}let d=[];return o.forEach(u=>{var x,L;if(u.length===1){let[{marker:k}]=u,P=k.type===i,C=a===k.tripadvisor_id;d.push({kind:"primary",marker:k,key:`primary-${k.tripadvisor_id}-p${P?1:0}-s${C?1:0}-${(x=k.pricing)==null?void 0:x.availability}`});return}let b=[...u].sort((k,P)=>be(P.marker,k.marker,i)),[g,...c]=b,h=g.marker.type===i,v=a===g.marker.tripadvisor_id;if(d.push({kind:"primary",marker:g.marker,key:`primary-${g.marker.tripadvisor_id}-p${h?1:0}-s${v?1:0}-${(L=g.marker.pricing)==null?void 0:L.availability}`}),!c.length)return;let A=[],T=[];if(c.forEach(k=>{var P;if(a&&k.marker.tripadvisor_id===a){let C=k.marker.type===i;d.push({kind:"primary",marker:k.marker,key:`primary-${k.marker.tripadvisor_id}-p${C?1:0}-s1-${(P=k.marker.pricing)==null?void 0:P.availability}`});return}ge(g,k)<=f?A.push(k):T.push(k)}),A.forEach(k=>{var C;let P=k.marker.type===i;d.push({kind:"dot",marker:k.marker,key:`dot-${k.marker.tripadvisor_id}-p${P?1:0}-s0-${(C=k.marker.pricing)==null?void 0:C.availability}`,parentId:g.marker.tripadvisor_id})}),T.length){let k=q({markers:T.map(P=>P.marker),map:t,selectedMarkerId:a,zoom:r,primaryType:i,collisionThresholdPx:n,dotCollisionThresholdPx:s});d.push(...k)}}),d}function ge(i,e){return Math.hypot(i.x-e.x,i.y-e.y)}function ye(i){let e=Q(i);return Math.max(48,e)}function be(i,e,t){var p,f;let a=i.type===t,r=e.type===t;if(a&&!r)return 1;if(!a&&r)return-1;let n=X(i)-X(e);if(n!==0)return n;let s=J(i)-J(e);if(s!==0)return s;let m=((p=i.reviews)!=null?p:0)-((f=e.reviews)!=null?f:0);return m!==0?m:i.tripadvisor_id-e.tripadvisor_id}function X(i){if(typeof i.rating=="number")return i.rating;if(i.rating===void 0||i.rating===null)return-1/0;let e=Number(i.rating);return Number.isNaN(e)?-1/0:e}function J(i){var t,a,r;if(!((a=(t=i.pricing)==null?void 0:t.offer)!=null&&a.price))return-1/0;let e=Number(((r=i.pricing.offer.displayPrice)!=null?r:"0").replace(/[^0-9.,-]+/g,"").replace(/,/g,""));return Number.isNaN(e)?-1/0:e}function Me(i){let e=[];return i.amenities&&Array.isArray(i.amenities)&&i.amenities.forEach(t=>{e.push({id:`amenity-${t}`,label:t,type:"amenity",value:t})}),i.hotelStyle&&Array.isArray(i.hotelStyle)&&i.hotelStyle.forEach(t=>{e.push({id:`hotelStyle-${t}`,label:t,type:"hotelStyle",value:t})}),i.price&&e.push({id:"priceRange",label:"Price Range",type:"priceRange",value:`${i.price.min}-${i.price.max}`,priceRange:i.price}),typeof i.minRating=="number"&&Number.isFinite(i.minRating)&&e.push({id:"minRating",label:`${i.minRating}+`,type:"minRating",value:String(i.minRating),numericValue:i.minRating}),typeof i.starRating=="number"&&Number.isFinite(i.starRating)&&e.push({id:"starRating",label:`${i.starRating} Stars`,type:"starRating",value:String(i.starRating),numericValue:i.starRating}),i.transformed_query&&e.push({id:"transformed_query",label:i.transformed_query,type:"transformed_query",value:i.transformed_query}),i.selected_restaurant_price_levels&&e.push({id:"selected_restaurant_price_levels",label:i.selected_restaurant_price_levels.join(", "),type:"selected_restaurant_price_levels",value:i.selected_restaurant_price_levels.join(", "),priceLevels:i.selected_restaurant_price_levels}),e}function ke(i){return i.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 a=e.priceRange.min,r=e.priceRange.max;a!==void 0&&(t.priceRange={min:a,...r!==void 0&&{max:r}})}return e.priceLevels&&(t.priceLevels=e.priceLevels),t})}var ve={prod:"https://api.mapfirst.ai",test:"https://api.mapfirst.ai/test"},N=class extends Error{constructor({message:e,status:t,code:a}){super(e),this.name="PropertiesFetchError",this.status=t,this.code=a}};async function K(i,e=1){try{let t=await fetch(`https://l4detuz832.execute-api.us-east-1.amazonaws.com/dev/photo?id=${i}&limit=${e}`);if(!t.ok)return null;let a=await t.json();if(a.photos&&a.photos.length>0){let r=a.photos[0].FullSizeURL.url;if((await fetch(r)).ok)return r}return null}catch(t){return console.debug("Failed to fetch images:",t),null}}async function Pe(i,e,t,{signal:a}={}){var s,m;let r;try{document.referrer&&(r=document.referrer)}catch(p){console.error(p)}let n=await fetch(i,{method:"POST",headers:{"Content-Type":"application/json","X-Source":"SDK",...t&&{"X-API-Key":t},...r&&{"X-Referer":r}},body:JSON.stringify(e),signal:a});if(!n.ok){let p=`Unexpected response: ${n.status}`,f;try{let y=await n.json();p=(m=(s=y.detail)!=null?s:y.error)!=null?m:p,f=y.code}catch{}throw new N({message:p,status:n.status,code:f})}return await n.json()}function ee(i){return typeof i=="string"?i:i.toISOString().slice(0,10)}var te="Accommodation";function xe(){let e=new Date(Date.now()+864e6),t=(6-e.getDay()+7)%7,a=new Date(e.getTime()+t*864e5),r=a.getDay(),n=r===0?6:6-r,s=new Date(a.getTime()+(n+1)*864e5);return{checkIn:a,checkOut:s}}var re=class{constructor(e){this.options=e;this.adapter=null;this.properties=[];this.selectedMarkerId=null;this.destroyed=!1;this.clusterItems=[];this.isMapAttached=!1;var r,n,s,m,p,f,y,M,l,o,d,u,b,g,c,h,v,A,T,x,L;if(this.properties=[...(r=e.properties)!=null?r:[]],this.primaryType=e.primaryType,this.selectedMarkerId=(n=e.selectedMarkerId)!=null?n:null,this.useApi=(s=e.useApi)!=null?s:!0,this.environment=(m=e.environment)!=null?m:"prod",this.apiUrl=(p=e.apiUrl)!=null?p:ve[this.environment],this.apiKey=e.apiKey,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=ae(e);this.fitBoundsPadding={top:(y=(f=e.fitBoundsPadding)==null?void 0:f.top)!=null?y:t?0:50,bottom:(l=(M=e.fitBoundsPadding)==null?void 0:M.bottom)!=null?l:t?0:160,left:(d=(o=e.fitBoundsPadding)==null?void 0:o.left)!=null?d:t?0:50,right:(b=(u=e.fitBoundsPadding)==null?void 0:u.right)!=null?b:t?0:50};let a=xe();this.state={center:(g=e.initialLocationData)!=null&&g.latitude&&e.initialLocationData.longitude?[e.initialLocationData.latitude,e.initialLocationData.longitude]:[0,0],zoom:(h=(c=e.initialLocationData)==null?void 0:c.zoom)!=null?h:0,bounds:(A=(v=e.initialLocationData)==null?void 0:v.bounds)!=null?A:null,pendingBounds:null,tempBounds:null,properties:this.properties,primary:(T=this.primaryType)!=null?T:te,selectedPropertyId:this.selectedMarkerId,initialLoading:!0,isSearching:!1,firstCallDone:!1,filters:{checkIn:a.checkIn,checkOut:a.checkOut,numAdults:2,numRooms:1,...((x=e.initialLocationData)==null?void 0:x.currency)&&{currency:e.initialLocationData.currency}},activeLocation:{country:"",location_id:null,locationName:"",coordinates:[0,0]},isFlyToAnimating:!1,...e.state},this.callbacks=(L=e.callbacks)!=null?L:{},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){var t;if(!this.useApi){console.warn("initializeFromLocationData requires API usage. Set useApi to true.");return}try{let{city:a,state:r,country:n,query:s,latitude:m,longitude:p,radius:f,bounds:y}=e,M={filters:this.getFilters(),initial:!0,query:s,latitude:m,longitude:p,radius:f,bounds:y},l=[a,r].filter(Boolean).join(", ");if(n||l){let o=await fetch(`${this.apiUrl}/geo-lookup2?${new URLSearchParams({...n&&{country_code:n},...l&&{q:l}}).toString()}`,{headers:{...this.apiKey&&{"X-API-Key":this.apiKey}}});if(o.ok){let d=await o.json();M.city=["country","island","state"].includes(d.type)?void 0:d.name,M.state=d.type==="state"?d.name:["country","island","county"].includes(d.type)?void 0:d.state,M.country=["country","island"].includes(d.type)?d.name:d.country,M.location_id=d.id,M.latitude=d.lat,M.longitude=d.lon,this.setActiveLocation({city:a,state:r,country:n,location_id:(t=d.id)!=null?t:null,locationName:[a,r,n].filter(Boolean).join(", "),...d.lon&&d.lat&&{coordinates:[d.lat,d.lon]}}),d.lon&&d.lat&&this.setState({center:[d.lat,d.lon],zoom:a?12:r?8:5})}else this.handleError(new Error(`Geo mapping fetch failed: ${o.statusText}`),"initializeFromLocationData")}this.requestBody=M,this.isMapAttached&&await this.autoLoadProperties()}catch(a){this.handleError(a,"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 a,r;this.handleError(t,"autoLoadProperties"),(r=(a=this.callbacks).onPropertiesLoadError)==null||r.call(a,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 r=this.adapter.getMarkerManager();r==null||r.destroy(),this.adapter.cleanup()}let a={...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(a),this.isMapAttached=!0,this.refresh(),this.requestBody&&!this.state.firstCallDone&&this.autoLoadProperties()}createAdapter(e){return Le(e)&&e.mapInstance?this.initializeAdapter(new F(e.mapInstance),{maplibregl:e.maplibregl,onMarkerClick:e.onMarkerClick}):ae(e)&&e.mapInstance?this.initializeAdapter(new H(e.mapInstance),{google:e.google,onMarkerClick:e.onMarkerClick}):Te(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){return e.initialize({...t,onMarkerClick:a=>{var r;a.location&&this.flyMapTo(a.location.lon,a.location.lat,14),a.type!==this.primaryType&&this.setPrimaryType(a.type),this.setSelectedMarker(a.tripadvisor_id===this.selectedMarkerId?null:a.tripadvisor_id),(r=t.onMarkerClick)==null||r.call(t,a)},onRefresh:()=>this.refresh(),onMapMoveEnd:a=>{this.state.tempBounds===null?(this.setTempBounds(a),this.setPendingBounds(null)):this.handleMapMoveEnd(a)}}),this.useApi&&e.setupImpressionTracking(()=>{}),e}_setProperties(e){var t,a;this.ensureAlive(),this.properties=[...e.filter(r=>{var n;return r.type==="Accommodation"?((n=r.pricing)==null?void 0:n.availability)!=="unavailable":!0})],this.updateState({properties:this.properties}),(a=(t=this.callbacks).onPropertiesChange)==null||a.call(t,e),this.refresh()}addProperty(e){var t,a;this.ensureAlive(),this.properties=[...this.properties,e],this.updateState({properties:this.properties}),(a=(t=this.callbacks).onPropertiesChange)==null||a.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,a;this.ensureAlive(),this.primaryType!==e&&(this.primaryType=e,this.updateState({primary:e}),(a=(t=this.callbacks).onPrimaryTypeChange)==null||a.call(t,e),this.refresh())}setSelectedMarker(e){var t,a;if(this.ensureAlive(),this.selectedMarkerId!==e){if(e!==null){let r=this.properties.find(n=>n.tripadvisor_id===e);r&&r.type!==this.primaryType&&this.setPrimaryType(r.type)}this.selectedMarkerId=e,this.updateState({selectedPropertyId:e}),(a=(t=this.callbacks).onSelectedPropertyChange)==null||a.call(t,e),this.refresh()}}getState(){return{...this.state}}handleError(e,t="MapFirstCore"){let a=e instanceof Error?e.message:String(e),r=e instanceof Error?e:new Error(a);console.error(`[${t}]`,a),this.callbacks.onError&&this.callbacks.onError(r,t)}updateState(e){this.state={...this.state,...e}}setState(e){var a,r,n,s,m,p,f,y,M,l,o,d,u,b,g,c;let t={...this.state};this.updateState(e),e.center!==void 0&&e.center!==t.center&&((r=(a=this.callbacks).onCenterChange)==null||r.call(a,e.center,this.state.zoom)),e.zoom!==void 0&&e.zoom!==t.zoom&&((s=(n=this.callbacks).onZoomChange)==null||s.call(n,e.zoom)),e.bounds!==void 0&&e.bounds!==t.bounds&&((p=(m=this.callbacks).onBoundsChange)==null||p.call(m,e.bounds)),e.pendingBounds!==void 0&&e.pendingBounds!==t.pendingBounds&&((y=(f=this.callbacks).onPendingBoundsChange)==null||y.call(f,e.pendingBounds)),e.filters!==void 0&&e.filters!==t.filters&&((l=(M=this.callbacks).onFiltersChange)==null||l.call(M,e.filters)),e.activeLocation!==void 0&&e.activeLocation!==t.activeLocation&&((d=(o=this.callbacks).onActiveLocationChange)==null||d.call(o,e.activeLocation)),e.initialLoading!==void 0&&e.initialLoading!==t.initialLoading&&((b=(u=this.callbacks).onLoadingStateChange)==null||b.call(u,e.initialLoading)),e.isSearching!==void 0&&e.isSearching!==t.isSearching&&((c=(g=this.callbacks).onSearchingStateChange)==null||c.call(g,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 a=.01;Math.abs(e.sw.lat-t.sw.lat)>a||Math.abs(e.sw.lng-t.sw.lng)>a||Math.abs(e.ne.lat-t.ne.lat)>a||Math.abs(e.ne.lng-t.ne.lng)>a?this.setState({pendingBounds:e}):this.setState({pendingBounds:null})}flyMapTo(e,t,a,r=!0){if(this.ensureAlive(),this.setState({center:[t,e]}),typeof a=="number"&&this.setState({zoom:a}),!this.adapter)return;let n=this.adapter.getMap();if(n){if(this.currentPlatform==="google"){this.setFlyToAnimating(!1),n.setCenter({lat:t,lng:e}),a!==null&&typeof a=="number"&&n.setZoom(a!=null?a:13);return}if(r===!1){this.setFlyToAnimating(!1),n.jumpTo&&n.jumpTo({center:[e,t],...a!==null&&{zoom:a!=null?a:13}});return}this.setFlyToAnimating(!0),n.flyTo&&n.flyTo({center:[e,t],...a!==null&&{zoom:a!=null?a:13}})}}flyToPOIs(e,t,a=!0){var s,m;if(this.ensureAlive(),!this.adapter)return;let r=this.adapter.getMap();if(!r)return;let n=e;if((!n||n.length===0)&&(n=this.properties.filter(p=>p.location!==void 0&&(t!==void 0?p.type===t:!0)).map(p=>({lat:p.location.lat,lng:p.location.lon}))),!(!n||n.length===0)){if(n.length===1){let p=n[0];this.currentPlatform==="google"?(r.setCenter({lat:p.lat,lng:p.lng}),r.setZoom(13)):r.flyTo&&r.flyTo({center:[p.lng,p.lat],zoom:13})}else if(this.currentPlatform==="google"){let p=(m=(s=window.google)==null?void 0:s.maps)==null?void 0:m.LatLngBounds;if(p){let f=new p;n.forEach(y=>{f.extend({lat:y.lat,lng:y.lng})}),a&&this.setFlyToAnimating(!0),r.fitBounds(f,this.fitBoundsPadding)}}else if(r.fitBounds){let p=[[n[0].lng,n[0].lat],[n[0].lng,n[0].lat]];n.forEach(f=>{p[0][0]=Math.min(p[0][0],f.lng),p[0][1]=Math.min(p[0][1],f.lat),p[1][0]=Math.max(p[1][0],f.lng),p[1][1]=Math.max(p[1][1],f.lat)}),a&&this.setFlyToAnimating(!0),r.fitBounds(p,{padding:this.fitBoundsPadding,animate:a})}}}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 pollForPricing({pollingLink:e,maxAttempts:t=15,delayMs:a=2e3,isCancelled:r,price:n,limit:s}){var l,o,d,u,b;if(this.ensureAlive(),!this.useApi)return console.warn("pollForPricing requires API usage. Set useApi to true."),{completed:!1};if(!e)return{completed:!1};let m=!1,p,f=this.getFilters();s&&(f.limit=s);let y={filters:f,pollingLink:e},M;try{document.referrer&&(M=document.referrer)}catch(g){console.error(g)}for(let g=0;g<t;g++){if(r!=null&&r())return{completed:m,pollData:p};try{let c=await fetch(`${this.apiUrl}/ta-polling?pollingNumber=${g}`,{method:"POST",body:JSON.stringify(y),headers:{"Content-Type":"application/json","X-Source":"SDK",...this.apiKey&&{"X-API-Key":this.apiKey},...M&&{"X-Referer":M}}});if(!c.ok)throw new N({message:`Poll failed: ${c.status}`,status:c.status});if(p=await c.json(),r!=null&&r())return{completed:m,pollData:p};let h=(o=(l=p==null?void 0:p.success)==null?void 0:l.results)!=null?o:[];if(h.length>0&&this.setProperties(v=>{let A=new Set(h.map(x=>x.tripadvisor_id)),T=v.filter(x=>x.type!=="Accommodation"||A.has(x.tripadvisor_id));return h.forEach(x=>{var k,P,C,w,j,G;if(!x.location)return;(P=(k=x.pricing)==null?void 0:k.offer)!=null&&P.price&&n&&(((w=(C=x.pricing)==null?void 0:C.offer)==null?void 0:w.price)<(n==null?void 0:n.min)||((G=(j=x.pricing)==null?void 0:j.offer)==null?void 0:G.price)>(n==null?void 0:n.max))&&(x.pricing.availability="unavailable");let L=T.findIndex(ie=>ie.tripadvisor_id===x.tripadvisor_id);L>=0?T[L]=x:T.push(x)}),T}),(d=p==null?void 0:p.success)!=null&&d.isComplete){m=!0,this.setSearching(!1);break}}catch(c){this.handleError(c,"pollForPricing"),(b=(u=this.callbacks).onPropertiesLoadError)==null||b.call(u,c);break}g<t-1&&await new Promise(c=>setTimeout(c,a))}return{completed:m,pollData:p}}setProperties(e){let t=e(this.properties);this._setProperties(t)}mostCommonTypeFromProperties(e){let t=e.reduce((a,r)=>(a[r.type]=(a[r.type]||0)+1,a),{});return Object.entries(t).reduce((a,r)=>t[a[0]]>t[r[0]]?a:r)[0]}async runPropertiesSearch({body:e,beforeApplyProperties:t,smartFiltersClearable:a,onError:r}){var n,s,m,p,f,y,M;if(this.ensureAlive(),!this.useApi)return console.warn("runPropertiesSearch requires API usage. Set useApi to true."),r==null||r(new Error("API usage is disabled")),null;this.setState({firstCallDone:!1}),this.setSearching(!0),this.clearProperties();try{let l=await Pe(`${this.apiUrl}/properties`,e,this.apiKey);this.updateActiveLocationFromResponse(l);let o=null,d=30,u=l.filters.primary_type;if(t){let c=t(l);o=(n=c.price)!=null?n:null,d=(s=c.limit)!=null?s:30}let b=l.properties.some(c=>!!c.location),g=o?l.properties.map(c=>{var h;return(h=c.pricing)!=null&&h.offer?{...c,pricing:{...c.pricing,availability:c.pricing.offer.price&&(c.pricing.offer.price<o.min||c.pricing.offer.price>o.max)?"unavailable":c.pricing.availability}}:c}):l.properties;if(this._setProperties(g),b&&this.flyToPOIs(l.properties.filter(c=>!!c.location&&(l.filters.primary_type?c.type===l.filters.primary_type:!0)).map(c=>({lat:c.location.lat,lng:c.location.lon})),void 0,e.initial!==!0),l.filters.primary_type&&l.properties.filter(c=>{var h;return c.type===l.filters.primary_type&&(c.type==="Accommodation"?((h=c.pricing)==null?void 0:h.availability)!=="unavailable":!0)}).length>0)u=l.filters.primary_type,this.setPrimaryType(l.filters.primary_type);else if(l.properties.length>0){let c=this.mostCommonTypeFromProperties(l.properties);this.setPrimaryType(c),u=c}if(this.setState({firstCallDone:!0}),l.isComplete===!1&&l.pollingLink){let{completed:c,pollData:h}=await this.pollForPricing({pollingLink:l.pollingLink,...o&&{price:o},...d&&{limit:d}});if(c&&((m=h==null?void 0:h.success)!=null&&m.results)&&h.success.results.filter(v=>{var A;return v.type===l.filters.primary_type&&(v.type==="Accommodation"?((A=v.pricing)==null?void 0:A.availability)!=="unavailable":!0)}).length===0&&u&&u!==l.filters.primary_type){let v=this.mostCommonTypeFromProperties(l.properties);this.setPrimaryType(v)}c&&this.refresh()}else l.isComplete===!0&&this.setSearching(!1);return b||(l.properties.some(c=>!!c.location)?this.flyToPOIs(l.properties.filter(c=>!!c.location&&(l.filters.primary_type?c.type===l.filters.primary_type:!0)).map(c=>({lat:c.location.lat,lng:c.location.lon})),void 0,e.initial!==!0):(p=l.filters.location)!=null&&p.latitude&&((f=l.filters.location)!=null&&f.longitude)&&this.flyMapTo(l.filters.location.longitude,l.filters.location.latitude,12,e.initial!==!0)),l}catch(l){return this.handleError(l,"runPropertiesSearch"),r==null||r(l),(M=(y=this.callbacks).onPropertiesLoadError)==null||M.call(y,l),this.clearProperties(),this.setState({firstCallDone:!0}),this.setSearching(!1),null}}async performBoundsSearch(){var n;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},a=(n=e==null?void 0:e.price)!=null?n:void 0,r=await this.runPropertiesSearch({body:t,beforeApplyProperties:()=>({price:a!=null?a:null})});return r&&(this.setBounds(this.state.pendingBounds),this.setTempBounds(this.state.pendingBounds),this.setPendingBounds(null)),r}updateActiveLocationFromResponse(e){var m,p,f,y;let t=(m=e.location_id)!=null?m:null,a=(f=(p=e.filters.location)==null?void 0:p.city)!=null?f:void 0,r=((y=e.filters.location)==null?void 0:y.country)||"",n=e.filters.location?[e.filters.location.latitude,e.filters.location.longitude]:void 0;if(!n)return;let s=this.state.activeLocation;(t!==(s==null?void 0:s.location_id)||a!==(s==null?void 0:s.city)||r!==(s==null?void 0:s.country))&&this.setActiveLocation({city:a,country:r,location_id:t,locationName:a&&r?`${a}, ${r}`:r||"",coordinates:n})}async runSmartFilterSearch({query:e,filters:t,onProcessFilters:a,onError:r}){if(this.ensureAlive(),!this.useApi)return console.warn("runSmartFilterSearch requires API usage. Set useApi to true."),r==null||r(new Error("API usage is disabled")),null;let n=this.getFilters(),s=this.getState();if(t&&t.length>0){let p=new Set,f=new Set,y,M,l,o,d,u;t.forEach(b=>{var g,c,h;switch(b.type){case"amenity":p.add(b.value);break;case"hotelStyle":f.add(b.value);break;case"priceRange":b.priceRange&&(y={min:b.priceRange.min,max:(g=b.priceRange.max)!=null?g:0});break;case"minRating":M=(c=b.numericValue)!=null?c:Number(b.value);break;case"starRating":l=(h=b.numericValue)!=null?h:Number(b.value);break;case"primary_type":o=b.propertyType;break;case"transformed_query":d=b.value;break;case"selected_restaurant_price_levels":u=b.priceLevels;break}}),n={...n,...p.size>0&&{amenities:Array.from(p)},...f.size>0&&{hotelStyle:Array.from(f)},...y&&{price:y},...M!==void 0&&{minRating:M},...l!==void 0&&{starRating:l},...o&&{primary_type:o},...d&&{transformed_query:d},...u&&{selected_restaurant_price_levels:u}}}else e||(n.minRating=4);let m={filters:n,...e&&{query:e},...s.bounds?{bounds:s.bounds}:s.activeLocation.location_id?{location_id:s.activeLocation.location_id}:s.activeLocation.coordinates?{latitude:s.activeLocation.coordinates[0],longitude:s.activeLocation.coordinates[1]}:{}};return this.runPropertiesSearch({body:m,beforeApplyProperties:a?p=>{var y,M;let f=a(p.filters,p.location_id);return{price:(y=f.price)!=null?y:null,limit:(M=f.limit)!=null?M:30}}:void 0,smartFiltersClearable:!!e,onError:r})}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,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 r,n,s;if(this.ensureAlive(),!this.adapter)return;let e=this.safeExtractViewState(),t=this.resolvePrimaryType();this.clusterItems=q({primaryType:t,markers:this.properties,map:this.adapter,selectedMarkerId:this.selectedMarkerId,zoom:(r=e==null?void 0:e.zoom)!=null?r:0}),this.adapter.getMarkerManager().render(this.clusterItems,t,this.selectedMarkerId),(s=(n=this.options).onClusterUpdate)==null||s.call(n,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,a;return(a=(t=this.primaryType)!=null?t:(e=this.properties.find(r=>r.type))==null?void 0:e.type)!=null?a:te}safeExtractViewState(){if(!this.adapter)return null;try{return Y(this.adapter)}catch{return null}}ensureAlive(){if(this.destroyed)throw new Error("MapFirstCore instance has been destroyed")}};function Le(i){return i.platform==="maplibre"}function ae(i){return i.platform==="google"}function Te(i){return i.platform==="mapbox"}export{re as MapFirstCore,N as PropertiesFetchError,ke as convertToApiFilters,K as fetchImages,Pe as fetchProperties,Me as processApiFilters};
33
33
  //# sourceMappingURL=index.mjs.map