@mapfirst.ai/core 0.0.3 → 0.0.5

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
@@ -1,3 +1,3 @@
1
1
  function H(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))}H(`.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 A(n,e,t,r){var h,l,y;if(typeof document=="undefined")return null;let a=n.marker,i=a.type===e,c=t===a.tripadvisor_id,s=a.type==="Accommodation"&&((l=(h=a.pricing)==null?void 0:h.offer)==null?void 0:l.availability)!=="available",o=document.createElement("div");o.className="mapfirst-dot-marker-container",o.style.zIndex=c?"20":i?"3":"1";let u=document.createElement("button");return u.type="button",u.className=s?"mapfirst-dot-marker-button mapfirst-dot-marker-button-pending":`mapfirst-dot-marker-button mapfirst-dot-marker-button-active${c?" mapfirst-dot-marker-selected":i?"":" mapfirst-dot-marker-non-primary"}`,u.title=(y=a.name)!=null?y:String(a.tripadvisor_id),u.addEventListener("click",k=>{k.stopPropagation(),s||r==null||r(a)}),o.appendChild(u),o}var ee='<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>',te='<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>',re='<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>',ae='<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 w(n,e,t,r){var k,m,f,p,g,v,C,x;if(typeof document=="undefined")return null;let a=n.marker,i=a.type===e,c=t===a.tripadvisor_id,d=a.type==="Accommodation",s=(m=(k=a.pricing)==null?void 0:k.offer)==null?void 0:m.displayPrice,o=d&&!s,u=(()=>{if(a.rating===void 0||a.rating===null)return null;let b=typeof a.rating=="number"?a.rating:Number(a.rating);return Number.isNaN(b)||b<=0?null:b.toFixed(1)})(),h=document.createElement("div");h.className="mapfirst-marker-root",h.style.zIndex=c?"20":i?"12":"11";let l=document.createElement("button");if(l.type="button",l.className=o?"mapfirst-marker-pill mapfirst-marker-pill-pending":`mapfirst-marker-pill mapfirst-marker-pill-active${c?" mapfirst-marker-selected":i?"":" mapfirst-marker-non-primary"}`,l.title=(f=a.name)!=null?f:String(a.tripadvisor_id),!o&&((p=a.awards)!=null&&p.length||u)){let b=document.createElement("div");if(b.className="mapfirst-marker-badge",i||(b.style.opacity="0.2"),b.className="mapfirst-marker-badge",(g=a.awards)!=null&&g.length&&a.awards[0].type){let M=document.createElement("div");M.className="mapfirst-marker-award-container";let P=document.createElement("div");P.className="mapfirst-marker-award-back",P.innerHTML=te;let I=document.createElement("div");I.className=`mapfirst-marker-award-dot mapfirst-marker-award-dot-type-${a.awards[0].type}`;let T=document.createElement("div");T.className="mapfirst-marker-award-front",T.innerHTML=ee,M.appendChild(P),M.appendChild(I),M.appendChild(T),b.appendChild(M)}else u&&(b.className="mapfirst-marker-badge mapfirst-marker-rating-badge",b.textContent=u);l.appendChild(b)}let y=document.createElement("span");return y.className="mapfirst-marker-content",d?y.textContent=(x=(C=(v=a.pricing)==null?void 0:v.offer)==null?void 0:C.displayPrice)!=null?x:"\u2014":a.type==="Eat & Drink"?y.innerHTML=re:a.type==="Attraction"&&(y.innerHTML=ae),l.appendChild(y),l.addEventListener("click",b=>{b.stopPropagation(),o||r==null||r(a)}),h.appendChild(l),h}function E(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 c=a.querySelector(".mapfirst-marker-badge");c instanceof HTMLElement&&(c.style.opacity=!e&&!t?"0.2":"")}function S(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 N(n){let e=n.match(/^(?:primary|dot)-(\d+)-/);return e?parseInt(e[1],10):null}var B=class{constructor(e){this.markerCache=new Map;this.primaryType="Accommodation";this.selectedMarkerId=null;var t;this.mapInstance=e.mapInstance,this.MarkerCtor=(t=e.maplibregl)==null?void 0:t.Marker,this.onMarkerClick=e.onMarkerClick}render(e,t,r){var i,c,d,s;if(t&&t!==this.primaryType&&(this.primaryType=t),r!==void 0&&(this.selectedMarkerId=r),!this.MarkerCtor)return;let a=new Set(e.map(o=>o.key));for(let[o,u]of this.markerCache.entries())if(!a.has(o)){try{u.marker.remove()}catch{}this.markerCache.delete(o)}for(let o of e){let u=ie(o.marker.location);if(!u)continue;let h=this.markerCache.get(o.key);if(h)try{h.marker.setLngLat([u.lon,u.lat])}catch{try{h.marker.remove()}catch{}this.markerCache.delete(o.key),this.createAndAddMarker(o,u)}else{let l=o.marker.tripadvisor_id,y,k;for(let[m,f]of this.markerCache.entries())if(N(m)===l&&f.kind===o.kind){y=f,k=m;break}if(y&&k){let m=o.marker.type===this.primaryType,f=this.selectedMarkerId===o.marker.tripadvisor_id,p=o.marker.type==="Accommodation",g=o.kind==="primary"?p&&!((c=(i=o.marker.pricing)==null?void 0:i.offer)!=null&&c.displayPrice):p&&((s=(d=o.marker.pricing)==null?void 0:d.offer)==null?void 0:s.availability)!=="available",v=y.marker.getElement();v&&(o.kind==="primary"?E(v,m,f,g):S(v,m,f,g)),this.markerCache.delete(k),this.markerCache.set(o.key,y);try{y.marker.setLngLat([u.lon,u.lat])}catch{}}else this.createAndAddMarker(o,u)}}}destroy(){for(let e of this.markerCache.values())try{e.marker.remove()}catch{}this.markerCache.clear()}createAndAddMarker(e,t){if(!this.MarkerCtor)return;let r=e.kind==="primary"?w(e,this.primaryType,this.selectedMarkerId,this.onMarkerClick):A(e,this.primaryType,this.selectedMarkerId,this.onMarkerClick);if(r)try{let a=new this.MarkerCtor({element:r,anchor:e.kind==="primary"?"bottom":"center"}).setLngLat([t.lon,t.lat]).addTo(this.mapInstance);this.markerCache.set(e.key,{key:e.key,marker:a,kind:e.kind,parentId:e.kind==="dot"?e.parentId:void 0})}catch{}}};function ie(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 _=class{constructor(e){this.markerCache=new Map;this.primaryType="Accommodation";this.selectedMarkerId=null;this.mapInstance=e.mapInstance,this.google=e.google,this.onMarkerClick=e.onMarkerClick}render(e,t,r){var i,c,d,s,o,u;if(t&&t!==this.primaryType&&(this.primaryType=t),r!==void 0&&(this.selectedMarkerId=r),!((c=(i=this.google)==null?void 0:i.marker)!=null&&c.AdvancedMarkerElement)){console.warn("AdvancedMarkerElement not available");return}let a=new Set(e.map(h=>h.key));for(let[h,l]of this.markerCache.entries())if(!a.has(h)){try{l.marker.map=null}catch(y){console.error("Error removing marker",y)}this.markerCache.delete(h)}for(let h of e){let l=ne(h.marker.location);if(!l)continue;let y=this.markerCache.get(h.key);if(y)try{y.marker.position={lat:l.lat,lng:l.lon}}catch{try{y.marker.map=null}catch(k){console.error("Error removing marker",k)}this.markerCache.delete(h.key),this.createAndAddMarker(h,l)}else{let k=h.marker.tripadvisor_id,m,f;for(let[p,g]of this.markerCache.entries())if(N(p)===k&&g.kind===h.kind){m=g,f=p;break}if(m&&f){let p=h.marker.type===this.primaryType,g=this.selectedMarkerId===h.marker.tripadvisor_id,v=h.marker.type==="Accommodation",C=h.kind==="primary"?v&&!((s=(d=h.marker.pricing)==null?void 0:d.offer)!=null&&s.displayPrice):v&&((u=(o=h.marker.pricing)==null?void 0:o.offer)==null?void 0:u.availability)!=="available",x=m.marker.content;x instanceof HTMLElement&&(h.kind==="primary"?E(x,p,g,C):S(x,p,g,C));let b=h.kind==="primary"?g?20:p?12:11:g?20:p?3:1;m.marker.zIndex=b,this.markerCache.delete(f),this.markerCache.set(h.key,m);try{m.marker.position={lat:l.lat,lng:l.lon}}catch{}}else this.createAndAddMarker(h,l)}}}destroy(){for(let e of this.markerCache.values())try{e.marker.map=null}catch(t){console.error("Error removing marker",t)}this.markerCache.clear()}createAndAddMarker(e,t){var d,s;if(!((s=(d=this.google)==null?void 0:d.marker)!=null&&s.AdvancedMarkerElement))return;let r=e.kind==="primary"?w(e,this.primaryType,this.selectedMarkerId,this.onMarkerClick):A(e,this.primaryType,this.selectedMarkerId,this.onMarkerClick);if(!r)return;let a=e.marker.type===this.primaryType,i=this.selectedMarkerId===e.marker.tripadvisor_id,c=e.kind==="primary"?i?20:a?12:11:i?20:a?3:1;try{let o=new this.google.marker.AdvancedMarkerElement({map:this.mapInstance,position:{lat:t.lat,lng:t.lon},content:r,zIndex:c});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)}}};function ne(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 D=class{constructor(e){this.markerCache=new Map;this.primaryType="Accommodation";this.selectedMarkerId=null;var t;this.mapInstance=e.mapInstance,this.MarkerCtor=(t=e.mapboxgl)==null?void 0:t.Marker,this.onMarkerClick=e.onMarkerClick}render(e,t,r){var i,c,d,s;if(t&&t!==this.primaryType&&(this.primaryType=t),r!==void 0&&(this.selectedMarkerId=r),!this.MarkerCtor)return;let a=new Set(e.map(o=>o.key));for(let[o,u]of this.markerCache.entries())if(!a.has(o)){try{u.marker.remove()}catch{}this.markerCache.delete(o)}for(let o of e){let u=se(o.marker.location);if(!u)continue;let h=this.markerCache.get(o.key);if(h)try{h.marker.setLngLat([u.lon,u.lat])}catch{try{h.marker.remove()}catch{}this.markerCache.delete(o.key),this.createAndAddMarker(o,u)}else{let l=o.marker.tripadvisor_id,y,k;for(let[m,f]of this.markerCache.entries())if(N(m)===l&&f.kind===o.kind){y=f,k=m;break}if(y&&k){let m=o.marker.type===this.primaryType,f=this.selectedMarkerId===o.marker.tripadvisor_id,p=o.marker.type==="Accommodation",g=o.kind==="primary"?p&&!((c=(i=o.marker.pricing)==null?void 0:i.offer)!=null&&c.displayPrice):p&&((s=(d=o.marker.pricing)==null?void 0:d.offer)==null?void 0:s.availability)!=="available",v=y.marker.getElement();v&&(o.kind==="primary"?E(v,m,f,g):S(v,m,f,g)),this.markerCache.delete(k),this.markerCache.set(o.key,y);try{y.marker.setLngLat([u.lon,u.lat])}catch{}}else this.createAndAddMarker(o,u)}}}destroy(){for(let e of this.markerCache.values())try{e.marker.remove()}catch{}this.markerCache.clear()}createAndAddMarker(e,t){if(!this.MarkerCtor)return;let r=e.kind==="primary"?w(e,this.primaryType,this.selectedMarkerId,this.onMarkerClick):A(e,this.primaryType,this.selectedMarkerId,this.onMarkerClick);if(r)try{let a=new this.MarkerCtor({element:r,anchor:e.kind==="primary"?"bottom":"center"}).setLngLat([t.lon,t.lat]).addTo(this.mapInstance);this.markerCache.set(e.key,{key:e.key,marker:a,kind:e.kind,parentId:e.kind==="dot"?e.parentId:void 0})}catch{}}};function se(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 L=class{constructor(e){this.map=e}getMap(){return this.map}};var O=class extends L{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),this.markerManager}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}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 L{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),this.markerManager}attachEventListeners(t){let r=["center_changed","zoom_changed","drag","heading_changed","tilt_changed"],a=[];r.forEach(i=>{let c=this.map.addListener(i,t);a.push(c)}),this.cleanupFns.push(()=>{a.forEach(i=>{try{i.remove()}catch{}})})}getMarkerManager(){return this.markerManager}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 d;if(!this.overlayView)return{x:0,y:0};let r=this.overlayView.getProjection();if(!r)return{x:0,y:0};let a=(d=globalThis.google)==null?void 0:d.maps;if(!a)return{x:0,y:0};let i=new a.LatLng(t[1],t[0]),c=r.fromLatLngToContainerPixel(i);return c?{x:c.x,y:c.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 R=class extends L{constructor(t){super(t);this.cleanupFns=[]}initialize(t){return this.markerManager=new D({mapInstance:this.map,mapboxgl:t.mapboxgl,onMarkerClick:t.onMarkerClick}),t.onRefresh&&this.attachEventListeners(t.onRefresh),this.markerManager}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}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 K(n){let e=n.getCenter();return{longitude:e.lng,latitude:e.lat,zoom:n.getZoom(),bearing:n.getBearing(),pitch:n.getPitch()}}var oe=[{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 Z(n){for(let e of oe)if(n<=e.zoom)return e.threshold;return 48}function j({primaryType:n,markers:e,map:t,selectedMarkerId:r,zoom:a,collisionThresholdPx:i,dotCollisionThresholdPx:c}){if(!e.length)return[];if(!t)return e.map(m=>({kind:"primary",marker:m,key:`primary-${m.tripadvisor_id}`}));let d=e.map((m,f)=>{let p=m.location;if(typeof(p==null?void 0:p.lon)!="number"||typeof(p==null?void 0:p.lat)!="number")return null;let{x:g,y:v}=t.project([p.lon,p.lat]);return{marker:m,index:f,x:g,y:v}}).filter(m=>!!m);if(!d.length)return[];let s=Z(a),o=le(a),u=d.map((m,f)=>f),h=m=>u[m]===m?m:(u[m]=h(u[m]),u[m]),l=(m,f)=>{let p=h(m),g=h(f);p!==g&&(u[g]=p)};for(let m=0;m<d.length;m+=1)for(let f=m+1;f<d.length;f+=1){let p=d[m].x-d[f].x,g=d[m].y-d[f].y;Math.hypot(p,g)<=s&&l(m,f)}let y=new Map;for(let m of d){let f=h(m.index),p=y.get(f);p?p.push(m):y.set(f,[m])}let k=[];return y.forEach(m=>{if(m.length===1){let[{marker:M}]=m,P=M.type===n,I=r===M.tripadvisor_id;k.push({kind:"primary",marker:M,key:`primary-${M.tripadvisor_id}-p${P?1:0}-s${I?1:0}`});return}let f=[...m].sort((M,P)=>me(P.marker,M.marker,n)),[p,...g]=f,v=p.marker.type===n,C=r===p.marker.tripadvisor_id;if(k.push({kind:"primary",marker:p.marker,key:`primary-${p.marker.tripadvisor_id}-p${v?1:0}-s${C?1:0}`}),!g.length)return;let x=[],b=[];if(g.forEach(M=>{if(r&&M.marker.tripadvisor_id===r){let P=M.marker.type===n;k.push({kind:"primary",marker:M.marker,key:`primary-${M.marker.tripadvisor_id}-p${P?1:0}-s1`});return}pe(p,M)<=o?x.push(M):b.push(M)}),x.forEach(M=>{let P=M.marker.type===n;k.push({kind:"dot",marker:M.marker,key:`dot-${M.marker.tripadvisor_id}-p${P?1:0}-s0`,parentId:p.marker.tripadvisor_id})}),b.length){let M=j({markers:b.map(P=>P.marker),map:t,selectedMarkerId:r,zoom:a,primaryType:n,collisionThresholdPx:i,dotCollisionThresholdPx:c});k.push(...M)}}),k}function pe(n,e){return Math.hypot(n.x-e.x,n.y-e.y)}function le(n){let e=Z(n);return Math.max(48,e)}function me(n,e,t){var s,o;let r=n.type===t,a=e.type===t;if(r&&!a)return 1;if(!r&&a)return-1;let i=q(n)-q(e);if(i!==0)return i;let c=U(n)-U(e);if(c!==0)return c;let d=((s=n.reviews)!=null?s:0)-((o=e.reviews)!=null?o:0);return d!==0?d:n.tripadvisor_id-e.tripadvisor_id}function q(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 U(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}var ce={prod:"https://api.mapfirst.ai",test:"https://ta-backend-test-290791666935.us-central1.run.app"},z=class extends Error{constructor({message:e,status:t,code:r}){super(e),this.name="PropertiesFetchError",this.status=t,this.code=r}};async function de(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 c=`Unexpected response: ${r.status}`,d;try{let s=await r.json();c=(i=(a=s.detail)!=null?a:s.error)!=null?i:c,d=s.code}catch{}throw new z({message:c,status:r.status,code:d})}return await r.json()}function W(n){return typeof n=="string"?n:n.toISOString().slice(0,10)}var J="Accommodation";function ue(){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,c=new Date(r.getTime()+(i+1)*864e5);return{checkIn:r,checkOut:c}}var Y=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,c,d,s,o,u,h,l,y,k,m,f,p,g;this.properties=[...(a=e.properties)!=null?a:[]],this.primaryType=e.primaryType,this.selectedMarkerId=(i=e.selectedMarkerId)!=null?i:null,this.environment=(c=e.environment)!=null?c:"prod",this.apiUrl=ce[this.environment],this.mfid=(d=e.mfid)!=null?d:"default",this.requestBody=e.requestBody;let t=X(e);this.fitBoundsPadding={top:(o=(s=e.fitBoundsPadding)==null?void 0:s.top)!=null?o:t?0:50,bottom:(h=(u=e.fitBoundsPadding)==null?void 0:u.bottom)!=null?h:t?0:160,left:(y=(l=e.fitBoundsPadding)==null?void 0:l.left)!=null?y:t?0:50,right:(m=(k=e.fitBoundsPadding)==null?void 0:k.right)!=null?m:t?0:50};let r=ue();this.state={center:[0,0],zoom:0,bounds:null,pendingBounds:null,tempBounds:null,properties:this.properties,primary:(f=this.primaryType)!=null?f:J,selectedPropertyId:this.selectedMarkerId,initialLoading:!0,isSearching:!1,firstCallDone:!1,filters:{checkIn:r.checkIn,checkOut:r.checkOut,numAdults:2,numRooms:1,...((p=e.initialLocationData)==null?void 0:p.currency)&&{currency:e.initialLocationData.currency}},activeLocation:{country:"",location_id:null,locationName:"",coordinates:[0,0]},isFlyToAnimating:!1,...e.state},this.callbacks=(g=e.callbacks)!=null?g:{},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){try{let{city:t,country:r,query:a,currency:i}=e,c={filters:this.getFilters(),initial:!0};if(t&&r||r){let d=await fetch(`${this.apiUrl}/geo-lookup?country=${encodeURIComponent(r)}${t?`&city=${encodeURIComponent(t)}`:""}`);if(d.ok){let s=await d.json(),o=t;s.location_name&&s.path3_name&&s.location_name===s.path3_name&&(o=void 0),s.location_name&&(o=s.location_name);let u=s.path3_name||r;c={...c,city:o,country:u,location_id:s.location_id,longitude:s.longitude,latitude:s.latitude},this.setActiveLocation({city:o,country:u,location_id:s.location_id,locationName:o&&u?`${o}, ${u}`:u||"",coordinates:[s.latitude,s.longitude]}),this.setState({center:[s.latitude,s.longitude],zoom:12})}else this.handleError(new Error(`Geo mapping fetch failed: ${d.statusText}`),"initializeFromLocationData")}else a&&(c.query=a);this.requestBody=c,this.isMapAttached&&await this.autoLoadProperties()}catch(t){this.handleError(t,"initializeFromLocationData")}}async autoLoadProperties(){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.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.adapter=this.createAdapter(r),this.isMapAttached=!0,this.refresh(),this.requestBody&&!this.state.firstCallDone&&this.autoLoadProperties()}createAdapter(e){return he(e)&&e.mapInstance?this.initializeAdapter(new O(e.mapInstance),{maplibregl:e.maplibregl,onMarkerClick:e.onMarkerClick}):X(e)&&e.mapInstance?this.initializeAdapter(new F(e.mapInstance),{google:e.google,onMarkerClick:e.onMarkerClick}):fe(e)&&e.mapInstance?this.initializeAdapter(new R(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 c;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),(c=t.onMarkerClick)==null||c.call(t,i)},onRefresh:()=>this.refresh()}),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,c,d,s,o,u,h,l,y,k,m,f;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&&((c=(i=this.callbacks).onZoomChange)==null||c.call(i,e.zoom)),e.bounds!==void 0&&e.bounds!==t.bounds&&((s=(d=this.callbacks).onBoundsChange)==null||s.call(d,e.bounds)),e.filters!==void 0&&e.filters!==t.filters&&((u=(o=this.callbacks).onFiltersChange)==null||u.call(o,e.filters)),e.activeLocation!==void 0&&e.activeLocation!==t.activeLocation&&((l=(h=this.callbacks).onActiveLocationChange)==null||l.call(h,e.activeLocation)),e.initialLoading!==void 0&&e.initialLoading!==t.initialLoading&&((k=(y=this.callbacks).onLoadingStateChange)==null||k.call(y,e.initialLoading)),e.isSearching!==void 0&&e.isSearching!==t.isSearching&&((f=(m=this.callbacks).onSearchingStateChange)==null||f.call(m,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})}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.options.platform==="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 c,d;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.options.platform==="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.options.platform==="google"){let s=(d=(c=window.google)==null?void 0:c.maps)==null?void 0:d.LatLngBounds;if(s){let o=new s;i.forEach(u=>{o.extend({lat:u.lat,lng:u.lng})}),this.setFlyToAnimating(!0),a.fitBounds(o,this.fitBoundsPadding)}}else if(a.fitBounds){let s=[[i[0].lng,i[0].lat],[i[0].lng,i[0].lat]];i.forEach(o=>{s[0][0]=Math.min(s[0][0],o.lng),s[0][1]=Math.min(s[0][1],o.lat),s[1][0]=Math.max(s[1][0],o.lng),s[1][1]=Math.max(s[1][1],o.lat)}),this.setFlyToAnimating(!0),a.fitBounds(s,{padding:this.fitBoundsPadding,animate:r})}}}getFilters(){let e={...this.state.filters};return e.checkIn instanceof Date&&(e.checkIn=W(e.checkIn)),e.checkOut instanceof Date&&(e.checkOut=W(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((d,s)=>(d[s.type]=(d[s.type]||0)+1,d),{}),c=Object.entries(i).reduce((d,s)=>i[d[0]]>i[s[0]]?d:s)[0];this.setPrimaryType(c)}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:c}){var h,l,y,k,m;if(this.ensureAlive(),!e)return{completed:!1};let d=!1,s,o=this.getFilters();c&&(o.limit=c);let u={filters:o,pollingLink:e};for(let f=0;f<t;f++){if(a!=null&&a())return{completed:d,pollData:s};try{let p=await fetch(`${this.apiUrl}/${this.mfid}/ta-polling`,{method:"POST",body:JSON.stringify(u),headers:{"Content-Type":"application/json"}});if(!p.ok)throw new z({message:`Poll failed: ${p.status}`,status:p.status});if(s=await p.json(),a!=null&&a())return{completed:d,pollData:s};let g=(l=(h=s==null?void 0:s.success)==null?void 0:h.results)!=null?l:[];if(g.length>0&&(this.setProperties(v=>{let C=new Set(g.map(b=>b.tripadvisor_id)),x=v.filter(b=>b.type!=="Accommodation"||C.has(b.tripadvisor_id));return g.forEach(b=>{var P,I,T,$,G,V;if(!b.location)return;(I=(P=b.pricing)==null?void 0:P.offer)!=null&&I.price&&i&&((($=(T=b.pricing)==null?void 0:T.offer)==null?void 0:$.price)<(i==null?void 0:i.min)||((V=(G=b.pricing)==null?void 0:G.offer)==null?void 0:V.price)>(i==null?void 0:i.max))&&(b.pricing.availability="unavailable");let M=x.findIndex(Q=>Q.tripadvisor_id===b.tripadvisor_id);M>=0?x[M]=b:x.push(b)}),x}),this.refresh()),(y=s==null?void 0:s.success)!=null&&y.isComplete){d=!0;break}}catch(p){this.handleError(p,"pollForPricing"),(m=(k=this.callbacks).onPropertiesLoadError)==null||m.call(k,p);break}f<t-1&&await new Promise(p=>setTimeout(p,r))}return{completed:d,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,c,d,s,o,u,h;this.ensureAlive(),this.setState({firstCallDone:!1}),this.setSearching(!0),this.clearProperties();try{let l=await de(`${this.apiUrl}/${this.mfid}/hotels`,e),y=null,k=30,m=l.filters.primary_type;if(t){let p=t(l);y=(i=p.price)!=null?i:null,k=(c=p.limit)!=null?c:30}let f=l.properties.some(p=>!!p.location);if(this._setProperties(l.properties),f&&this.flyToPOIs(l.properties.filter(p=>!!p.location&&(l.filters.primary_type?p.type===l.filters.primary_type:!0)).map(p=>({lat:p.location.lat,lng:p.location.lon})),void 0,e.initial!==!0),l.filters.primary_type&&l.properties.filter(p=>{var g;return p.type===l.filters.primary_type&&(p.type==="Accommodation"?((g=p.pricing)==null?void 0:g.availability)!=="unavailable":!0)}).length>0)m=l.filters.primary_type,this.setPrimaryType(l.filters.primary_type);else if(l.properties.length>0){let p=this.mostCommonTypeFromProperties(l.properties);this.setPrimaryType(p),m=p}if(this.setState({firstCallDone:!0}),l.isComplete===!1&&l.pollingLink){let{completed:p,pollData:g}=await this.pollForPricing({pollingLink:l.pollingLink,...y&&{price:y},...k&&{limit:k}});if(p&&((d=g==null?void 0:g.success)!=null&&d.results)&&g.success.results.filter(v=>{var C;return v.type===l.filters.primary_type&&(v.type==="Accommodation"?((C=v.pricing)==null?void 0:C.availability)!=="unavailable":!0)}).length===0&&m&&m!==l.filters.primary_type){let v=this.mostCommonTypeFromProperties(l.properties);this.setPrimaryType(v)}}return f||(l.properties.some(p=>!!p.location)?this.flyToPOIs(l.properties.filter(p=>!!p.location&&(l.filters.primary_type?p.type===l.filters.primary_type:!0)).map(p=>({lat:p.location.lat,lng:p.location.lon})),void 0,e.initial!==!0):(s=l.filters.location)!=null&&s.latitude&&((o=l.filters.location)!=null&&o.longitude)&&this.flyMapTo(l.filters.location.longitude,l.filters.location.latitude,12,e.initial!==!0)),l}catch(l){return this.handleError(l,"runPropertiesSearch"),a==null||a(l),(h=(u=this.callbacks).onPropertiesLoadError)==null||h.call(u,l),this.clearProperties(),this.setState({firstCallDone:!0}),null}finally{this.setSearching(!1),this.setState({firstCallDone:!0})}}getClusters(){return this.ensureAlive(),[...this.clusterItems]}refresh(){var a,i,c;if(this.ensureAlive(),!this.adapter)return;let e=this.safeExtractViewState(),t=this.resolvePrimaryType();this.clusterItems=j({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),(c=(i=this.options).onClusterUpdate)==null||c.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:J}safeExtractViewState(){if(!this.adapter)return null;try{return K(this.adapter)}catch{return null}}ensureAlive(){if(this.destroyed)throw new Error("MapFirstCore instance has been destroyed")}};function he(n){return n.platform==="maplibre"}function X(n){return n.platform==="google"}function fe(n){return n.platform==="mapbox"}export{Y as MapFirstCore,z as PropertiesFetchError,de as fetchProperties};
2
+ `);function T(n,e,t,r){var f,c,y;if(typeof document=="undefined")return null;let a=n.marker,i=a.type===e,l=t===a.tripadvisor_id,s=a.type==="Accommodation"&&((c=(f=a.pricing)==null?void 0:f.offer)==null?void 0:c.availability)!=="available",o=document.createElement("div");o.className="mapfirst-dot-marker-container",o.style.zIndex=l?"20":i?"3":"1";let u=document.createElement("div");return u.className=s?"mapfirst-dot-marker-button mapfirst-dot-marker-button-pending":`mapfirst-dot-marker-button mapfirst-dot-marker-button-active${l?" mapfirst-dot-marker-selected":i?"":" mapfirst-dot-marker-non-primary"}`,u.title=(y=a.name)!=null?y:String(a.tripadvisor_id),u.addEventListener("click",k=>{k.stopPropagation(),s||r==null||r(a)}),o.appendChild(u),o}var ee='<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>',te='<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>',re='<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>',ae='<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 w(n,e,t,r){var k,m,h,p,g,M,C,x;if(typeof document=="undefined")return null;let a=n.marker,i=a.type===e,l=t===a.tripadvisor_id,d=a.type==="Accommodation",s=(m=(k=a.pricing)==null?void 0:k.offer)==null?void 0:m.displayPrice,o=d&&!s,u=(()=>{if(a.rating===void 0||a.rating===null)return null;let b=typeof a.rating=="number"?a.rating:Number(a.rating);return Number.isNaN(b)||b<=0?null:b.toFixed(1)})(),f=document.createElement("div");f.className="mapfirst-marker-root",f.style.zIndex=l?"20":i?"12":"11";let c=document.createElement("div");if(c.className=o?"mapfirst-marker-pill mapfirst-marker-pill-pending":`mapfirst-marker-pill mapfirst-marker-pill-active${l?" mapfirst-marker-selected":i?"":" mapfirst-marker-non-primary"}`,c.title=(h=a.name)!=null?h:String(a.tripadvisor_id),!o&&((p=a.awards)!=null&&p.length||u)){let b=document.createElement("div");if(b.className="mapfirst-marker-badge",i||(b.style.opacity="0.2"),b.className="mapfirst-marker-badge",(g=a.awards)!=null&&g.length&&a.awards[0].type){let v=document.createElement("div");v.className="mapfirst-marker-award-container";let P=document.createElement("div");P.className="mapfirst-marker-award-back",P.innerHTML=te;let I=document.createElement("div");I.className=`mapfirst-marker-award-dot mapfirst-marker-award-dot-type-${a.awards[0].type}`;let A=document.createElement("div");A.className="mapfirst-marker-award-front",A.innerHTML=ee,v.appendChild(P),v.appendChild(I),v.appendChild(A),b.appendChild(v)}else u&&(b.className="mapfirst-marker-badge mapfirst-marker-rating-badge",b.textContent=u);c.appendChild(b)}let y=document.createElement("span");return y.className="mapfirst-marker-content",d?y.textContent=(x=(C=(M=a.pricing)==null?void 0:M.offer)==null?void 0:C.displayPrice)!=null?x:"\u2014":a.type==="Eat & Drink"?y.innerHTML=re:a.type==="Attraction"&&(y.innerHTML=ae),c.appendChild(y),c.addEventListener("click",b=>{b.stopPropagation(),o||r==null||r(a)}),f.appendChild(c),f}function S(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 l=a.querySelector(".mapfirst-marker-badge");l instanceof HTMLElement&&(l.style.opacity=!e&&!t?"0.2":"")}function E(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 _(n){let e=n.match(/^(?:primary|dot)-(\d+)-/);return e?parseInt(e[1],10):null}var N=class{constructor(e){this.markerCache=new Map;this.primaryType="Accommodation";this.selectedMarkerId=null;var t;this.mapInstance=e.mapInstance,this.MarkerCtor=(t=e.maplibregl)==null?void 0:t.Marker,this.onMarkerClick=e.onMarkerClick}render(e,t,r){var i,l,d,s;if(t&&t!==this.primaryType&&(this.primaryType=t),r!==void 0&&(this.selectedMarkerId=r),!this.MarkerCtor)return;let a=new Set(e.map(o=>o.key));for(let[o,u]of this.markerCache.entries())if(!a.has(o)){try{u.marker.remove()}catch{}this.markerCache.delete(o)}for(let o of e){let u=ie(o.marker.location);if(!u)continue;let f=this.markerCache.get(o.key);if(f)try{f.marker.setLngLat([u.lon,u.lat])}catch{try{f.marker.remove()}catch{}this.markerCache.delete(o.key),this.createAndAddMarker(o,u)}else{let c=o.marker.tripadvisor_id,y,k;for(let[m,h]of this.markerCache.entries())if(_(m)===c&&h.kind===o.kind){y=h,k=m;break}if(y&&k){let m=o.marker.type===this.primaryType,h=this.selectedMarkerId===o.marker.tripadvisor_id,p=o.marker.type==="Accommodation",g=o.kind==="primary"?p&&!((l=(i=o.marker.pricing)==null?void 0:i.offer)!=null&&l.displayPrice):p&&((s=(d=o.marker.pricing)==null?void 0:d.offer)==null?void 0:s.availability)!=="available",M=y.marker.getElement();M&&(o.kind==="primary"?S(M,m,h,g):E(M,m,h,g)),this.markerCache.delete(k),this.markerCache.set(o.key,y);try{y.marker.setLngLat([u.lon,u.lat])}catch{}}else this.createAndAddMarker(o,u)}}}destroy(){for(let e of this.markerCache.values())try{e.marker.remove()}catch{}this.markerCache.clear()}createAndAddMarker(e,t){if(!this.MarkerCtor)return;let r=e.kind==="primary"?w(e,this.primaryType,this.selectedMarkerId,this.onMarkerClick):T(e,this.primaryType,this.selectedMarkerId,this.onMarkerClick);if(r)try{let a=new this.MarkerCtor({element:r,anchor:e.kind==="primary"?"bottom":"center"}).setLngLat([t.lon,t.lat]).addTo(this.mapInstance);this.markerCache.set(e.key,{key:e.key,marker:a,kind:e.kind,parentId:e.kind==="dot"?e.parentId:void 0})}catch{}}};function ie(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 B=class{constructor(e){this.markerCache=new Map;this.primaryType="Accommodation";this.selectedMarkerId=null;this.mapInstance=e.mapInstance,this.google=e.google,this.onMarkerClick=e.onMarkerClick}render(e,t,r){var i,l,d,s,o,u;if(t&&t!==this.primaryType&&(this.primaryType=t),r!==void 0&&(this.selectedMarkerId=r),!((l=(i=this.google)==null?void 0:i.marker)!=null&&l.AdvancedMarkerElement)){console.warn("AdvancedMarkerElement not available");return}let a=new Set(e.map(f=>f.key));for(let[f,c]of this.markerCache.entries())if(!a.has(f)){try{c.marker.map=null}catch(y){console.error("Error removing marker",y)}this.markerCache.delete(f)}for(let f of e){let c=ne(f.marker.location);if(!c)continue;let y=this.markerCache.get(f.key);if(y)try{y.marker.position={lat:c.lat,lng:c.lon}}catch{try{y.marker.map=null}catch(k){console.error("Error removing marker",k)}this.markerCache.delete(f.key),this.createAndAddMarker(f,c)}else{let k=f.marker.tripadvisor_id,m,h;for(let[p,g]of this.markerCache.entries())if(_(p)===k&&g.kind===f.kind){m=g,h=p;break}if(m&&h){let p=f.marker.type===this.primaryType,g=this.selectedMarkerId===f.marker.tripadvisor_id,M=f.marker.type==="Accommodation",C=f.kind==="primary"?M&&!((s=(d=f.marker.pricing)==null?void 0:d.offer)!=null&&s.displayPrice):M&&((u=(o=f.marker.pricing)==null?void 0:o.offer)==null?void 0:u.availability)!=="available",x=m.marker.content;x instanceof HTMLElement&&(f.kind==="primary"?S(x,p,g,C):E(x,p,g,C));let b=f.kind==="primary"?g?20:p?12:11:g?20:p?3:1;m.marker.zIndex=b,this.markerCache.delete(h),this.markerCache.set(f.key,m);try{m.marker.position={lat:c.lat,lng:c.lon}}catch{}}else this.createAndAddMarker(f,c)}}}destroy(){for(let e of this.markerCache.values())try{e.marker.map=null}catch(t){console.error("Error removing marker",t)}this.markerCache.clear()}createAndAddMarker(e,t){var d,s;if(!((s=(d=this.google)==null?void 0:d.marker)!=null&&s.AdvancedMarkerElement))return;let r=e.kind==="primary"?w(e,this.primaryType,this.selectedMarkerId,this.onMarkerClick):T(e,this.primaryType,this.selectedMarkerId,this.onMarkerClick);if(!r)return;let a=e.marker.type===this.primaryType,i=this.selectedMarkerId===e.marker.tripadvisor_id,l=e.kind==="primary"?i?20:a?12:11:i?20:a?3:1;try{let o=new this.google.marker.AdvancedMarkerElement({map:this.mapInstance,position:{lat:t.lat,lng:t.lon},content:r,zIndex:l});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)}}};function ne(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 F=class{constructor(e){this.markerCache=new Map;this.primaryType="Accommodation";this.selectedMarkerId=null;var t;this.mapInstance=e.mapInstance,this.MarkerCtor=(t=e.mapboxgl)==null?void 0:t.Marker,this.onMarkerClick=e.onMarkerClick}render(e,t,r){var i,l,d,s;if(t&&t!==this.primaryType&&(this.primaryType=t),r!==void 0&&(this.selectedMarkerId=r),!this.MarkerCtor)return;let a=new Set(e.map(o=>o.key));for(let[o,u]of this.markerCache.entries())if(!a.has(o)){try{u.marker.remove()}catch{}this.markerCache.delete(o)}for(let o of e){let u=se(o.marker.location);if(!u)continue;let f=this.markerCache.get(o.key);if(f)try{f.marker.setLngLat([u.lon,u.lat])}catch{try{f.marker.remove()}catch{}this.markerCache.delete(o.key),this.createAndAddMarker(o,u)}else{let c=o.marker.tripadvisor_id,y,k;for(let[m,h]of this.markerCache.entries())if(_(m)===c&&h.kind===o.kind){y=h,k=m;break}if(y&&k){let m=o.marker.type===this.primaryType,h=this.selectedMarkerId===o.marker.tripadvisor_id,p=o.marker.type==="Accommodation",g=o.kind==="primary"?p&&!((l=(i=o.marker.pricing)==null?void 0:i.offer)!=null&&l.displayPrice):p&&((s=(d=o.marker.pricing)==null?void 0:d.offer)==null?void 0:s.availability)!=="available",M=y.marker.getElement();M&&(o.kind==="primary"?S(M,m,h,g):E(M,m,h,g)),this.markerCache.delete(k),this.markerCache.set(o.key,y);try{y.marker.setLngLat([u.lon,u.lat])}catch{}}else this.createAndAddMarker(o,u)}}}destroy(){for(let e of this.markerCache.values())try{e.marker.remove()}catch{}this.markerCache.clear()}createAndAddMarker(e,t){if(!this.MarkerCtor)return;let r=e.kind==="primary"?w(e,this.primaryType,this.selectedMarkerId,this.onMarkerClick):T(e,this.primaryType,this.selectedMarkerId,this.onMarkerClick);if(r)try{let a=new this.MarkerCtor({element:r,anchor:e.kind==="primary"?"bottom":"center"}).setLngLat([t.lon,t.lat]).addTo(this.mapInstance);this.markerCache.set(e.key,{key:e.key,marker:a,kind:e.kind,parentId:e.kind==="dot"?e.parentId:void 0})}catch{}}};function se(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 L=class{constructor(e){this.map=e}getMap(){return this.map}};var D=class extends L{constructor(t){super(t);this.cleanupFns=[]}initialize(t){return this.markerManager=new N({mapInstance:this.map,maplibregl:t.maplibregl,onMarkerClick:t.onMarkerClick}),t.onRefresh&&this.attachEventListeners(t.onRefresh),this.markerManager}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}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 O=class extends L{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),this.markerManager}attachEventListeners(t){let r=["center_changed","zoom_changed","drag","heading_changed","tilt_changed"],a=[];r.forEach(i=>{let l=this.map.addListener(i,t);a.push(l)}),this.cleanupFns.push(()=>{a.forEach(i=>{try{i.remove()}catch{}})})}getMarkerManager(){return this.markerManager}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 d;if(!this.overlayView)return{x:0,y:0};let r=this.overlayView.getProjection();if(!r)return{x:0,y:0};let a=(d=globalThis.google)==null?void 0:d.maps;if(!a)return{x:0,y:0};let i=new a.LatLng(t[1],t[0]),l=r.fromLatLngToContainerPixel(i);return l?{x:l.x,y:l.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 R=class extends L{constructor(t){super(t);this.cleanupFns=[]}initialize(t){return this.markerManager=new F({mapInstance:this.map,mapboxgl:t.mapboxgl,onMarkerClick:t.onMarkerClick}),t.onRefresh&&this.attachEventListeners(t.onRefresh),this.markerManager}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}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 K(n){let e=n.getCenter();return{longitude:e.lng,latitude:e.lat,zoom:n.getZoom(),bearing:n.getBearing(),pitch:n.getPitch()}}var oe=[{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 Z(n){for(let e of oe)if(n<=e.zoom)return e.threshold;return 48}function j({primaryType:n,markers:e,map:t,selectedMarkerId:r,zoom:a,collisionThresholdPx:i,dotCollisionThresholdPx:l}){if(!e.length)return[];if(!t)return e.map(m=>({kind:"primary",marker:m,key:`primary-${m.tripadvisor_id}`}));let d=e.map((m,h)=>{let p=m.location;if(typeof(p==null?void 0:p.lon)!="number"||typeof(p==null?void 0:p.lat)!="number")return null;let{x:g,y:M}=t.project([p.lon,p.lat]);return{marker:m,index:h,x:g,y:M}}).filter(m=>!!m);if(!d.length)return[];let s=Z(a),o=le(a),u=d.map((m,h)=>h),f=m=>u[m]===m?m:(u[m]=f(u[m]),u[m]),c=(m,h)=>{let p=f(m),g=f(h);p!==g&&(u[g]=p)};for(let m=0;m<d.length;m+=1)for(let h=m+1;h<d.length;h+=1){let p=d[m].x-d[h].x,g=d[m].y-d[h].y;Math.hypot(p,g)<=s&&c(m,h)}let y=new Map;for(let m of d){let h=f(m.index),p=y.get(h);p?p.push(m):y.set(h,[m])}let k=[];return y.forEach(m=>{if(m.length===1){let[{marker:v}]=m,P=v.type===n,I=r===v.tripadvisor_id;k.push({kind:"primary",marker:v,key:`primary-${v.tripadvisor_id}-p${P?1:0}-s${I?1:0}`});return}let h=[...m].sort((v,P)=>ce(P.marker,v.marker,n)),[p,...g]=h,M=p.marker.type===n,C=r===p.marker.tripadvisor_id;if(k.push({kind:"primary",marker:p.marker,key:`primary-${p.marker.tripadvisor_id}-p${M?1:0}-s${C?1:0}`}),!g.length)return;let x=[],b=[];if(g.forEach(v=>{if(r&&v.marker.tripadvisor_id===r){let P=v.marker.type===n;k.push({kind:"primary",marker:v.marker,key:`primary-${v.marker.tripadvisor_id}-p${P?1:0}-s1`});return}pe(p,v)<=o?x.push(v):b.push(v)}),x.forEach(v=>{let P=v.marker.type===n;k.push({kind:"dot",marker:v.marker,key:`dot-${v.marker.tripadvisor_id}-p${P?1:0}-s0`,parentId:p.marker.tripadvisor_id})}),b.length){let v=j({markers:b.map(P=>P.marker),map:t,selectedMarkerId:r,zoom:a,primaryType:n,collisionThresholdPx:i,dotCollisionThresholdPx:l});k.push(...v)}}),k}function pe(n,e){return Math.hypot(n.x-e.x,n.y-e.y)}function le(n){let e=Z(n);return Math.max(48,e)}function ce(n,e,t){var s,o;let r=n.type===t,a=e.type===t;if(r&&!a)return 1;if(!r&&a)return-1;let i=q(n)-q(e);if(i!==0)return i;let l=U(n)-U(e);if(l!==0)return l;let d=((s=n.reviews)!=null?s:0)-((o=e.reviews)!=null?o:0);return d!==0?d:n.tripadvisor_id-e.tripadvisor_id}function q(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 U(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}var me={prod:"https://api.mapfirst.ai",test:"https://ta-backend-test-290791666935.us-central1.run.app"},z=class extends Error{constructor({message:e,status:t,code:r}){super(e),this.name="PropertiesFetchError",this.status=t,this.code=r}};async function de(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 l=`Unexpected response: ${r.status}`,d;try{let s=await r.json();l=(i=(a=s.detail)!=null?a:s.error)!=null?i:l,d=s.code}catch{}throw new z({message:l,status:r.status,code:d})}return await r.json()}function W(n){return typeof n=="string"?n:n.toISOString().slice(0,10)}var J="Accommodation";function ue(){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,l=new Date(r.getTime()+(i+1)*864e5);return{checkIn:r,checkOut:l}}var Y=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,l,d,s,o,u,f,c,y,k,m,h,p,g,M;this.properties=[...(a=e.properties)!=null?a:[]],this.primaryType=e.primaryType,this.selectedMarkerId=(i=e.selectedMarkerId)!=null?i:null,this.environment=(l=e.environment)!=null?l:"prod",this.apiUrl=(d=e.apiUrl)!=null?d:me[this.environment],this.mfid=(s=e.mfid)!=null?s:"default",this.requestBody=e.requestBody,this.currentPlatform=e.platform;let t=X(e);this.fitBoundsPadding={top:(u=(o=e.fitBoundsPadding)==null?void 0:o.top)!=null?u:t?0:50,bottom:(c=(f=e.fitBoundsPadding)==null?void 0:f.bottom)!=null?c:t?0:160,left:(k=(y=e.fitBoundsPadding)==null?void 0:y.left)!=null?k:t?0:50,right:(h=(m=e.fitBoundsPadding)==null?void 0:m.right)!=null?h:t?0:50};let r=ue();this.state={center:[0,0],zoom:0,bounds:null,pendingBounds:null,tempBounds:null,properties:this.properties,primary:(p=this.primaryType)!=null?p:J,selectedPropertyId:this.selectedMarkerId,initialLoading:!0,isSearching:!1,firstCallDone:!1,filters:{checkIn:r.checkIn,checkOut:r.checkOut,numAdults:2,numRooms:1,...((g=e.initialLocationData)==null?void 0:g.currency)&&{currency:e.initialLocationData.currency}},activeLocation:{country:"",location_id:null,locationName:"",coordinates:[0,0]},isFlyToAnimating:!1,...e.state},this.callbacks=(M=e.callbacks)!=null?M:{},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){try{let{city:t,country:r,query:a,currency:i}=e,l={filters:this.getFilters(),initial:!0};if(t&&r||r){let d=await fetch(`${this.apiUrl}/geo-lookup?country=${encodeURIComponent(r)}${t?`&city=${encodeURIComponent(t)}`:""}`);if(d.ok){let s=await d.json(),o=t;s.location_name&&s.path3_name&&s.location_name===s.path3_name&&(o=void 0),s.location_name&&(o=s.location_name);let u=s.path3_name||r;l={...l,city:o,country:u,location_id:s.location_id,longitude:s.longitude,latitude:s.latitude},this.setActiveLocation({city:o,country:u,location_id:s.location_id,locationName:o&&u?`${o}, ${u}`:u||"",coordinates:[s.latitude,s.longitude]}),this.setState({center:[s.latitude,s.longitude],zoom:12})}else this.handleError(new Error(`Geo mapping fetch failed: ${d.statusText}`),"initializeFromLocationData")}else a&&(l.query=a);this.requestBody=l,this.isMapAttached&&await this.autoLoadProperties()}catch(t){this.handleError(t,"initializeFromLocationData")}}async autoLoadProperties(){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.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 he(e)&&e.mapInstance?this.initializeAdapter(new D(e.mapInstance),{maplibregl:e.maplibregl,onMarkerClick:e.onMarkerClick}):X(e)&&e.mapInstance?this.initializeAdapter(new O(e.mapInstance),{google:e.google,onMarkerClick:e.onMarkerClick}):fe(e)&&e.mapInstance?this.initializeAdapter(new R(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 l;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),(l=t.onMarkerClick)==null||l.call(t,i)},onRefresh:()=>this.refresh()}),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,l,d,s,o,u,f,c,y,k,m,h;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&&((l=(i=this.callbacks).onZoomChange)==null||l.call(i,e.zoom)),e.bounds!==void 0&&e.bounds!==t.bounds&&((s=(d=this.callbacks).onBoundsChange)==null||s.call(d,e.bounds)),e.filters!==void 0&&e.filters!==t.filters&&((u=(o=this.callbacks).onFiltersChange)==null||u.call(o,e.filters)),e.activeLocation!==void 0&&e.activeLocation!==t.activeLocation&&((c=(f=this.callbacks).onActiveLocationChange)==null||c.call(f,e.activeLocation)),e.initialLoading!==void 0&&e.initialLoading!==t.initialLoading&&((k=(y=this.callbacks).onLoadingStateChange)==null||k.call(y,e.initialLoading)),e.isSearching!==void 0&&e.isSearching!==t.isSearching&&((h=(m=this.callbacks).onSearchingStateChange)==null||h.call(m,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})}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 l,d;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=(d=(l=window.google)==null?void 0:l.maps)==null?void 0:d.LatLngBounds;if(s){let o=new s;i.forEach(u=>{o.extend({lat:u.lat,lng:u.lng})}),r&&this.setFlyToAnimating(!0),a.fitBounds(o,this.fitBoundsPadding)}}else if(a.fitBounds){let s=[[i[0].lng,i[0].lat],[i[0].lng,i[0].lat]];i.forEach(o=>{s[0][0]=Math.min(s[0][0],o.lng),s[0][1]=Math.min(s[0][1],o.lat),s[1][0]=Math.max(s[1][0],o.lng),s[1][1]=Math.max(s[1][1],o.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=W(e.checkIn)),e.checkOut instanceof Date&&(e.checkOut=W(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((d,s)=>(d[s.type]=(d[s.type]||0)+1,d),{}),l=Object.entries(i).reduce((d,s)=>i[d[0]]>i[s[0]]?d:s)[0];this.setPrimaryType(l)}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:l}){var f,c,y,k,m;if(this.ensureAlive(),!e)return{completed:!1};let d=!1,s,o=this.getFilters();l&&(o.limit=l);let u={filters:o,pollingLink:e};for(let h=0;h<t;h++){if(a!=null&&a())return{completed:d,pollData:s};try{let p=await fetch(`${this.apiUrl}/${this.mfid}/ta-polling`,{method:"POST",body:JSON.stringify(u),headers:{"Content-Type":"application/json"}});if(!p.ok)throw new z({message:`Poll failed: ${p.status}`,status:p.status});if(s=await p.json(),a!=null&&a())return{completed:d,pollData:s};let g=(c=(f=s==null?void 0:s.success)==null?void 0:f.results)!=null?c:[];if(g.length>0&&(this.setProperties(M=>{let C=new Set(g.map(b=>b.tripadvisor_id)),x=M.filter(b=>b.type!=="Accommodation"||C.has(b.tripadvisor_id));return g.forEach(b=>{var P,I,A,$,V,G;if(!b.location)return;(I=(P=b.pricing)==null?void 0:P.offer)!=null&&I.price&&i&&((($=(A=b.pricing)==null?void 0:A.offer)==null?void 0:$.price)<(i==null?void 0:i.min)||((G=(V=b.pricing)==null?void 0:V.offer)==null?void 0:G.price)>(i==null?void 0:i.max))&&(b.pricing.availability="unavailable");let v=x.findIndex(Q=>Q.tripadvisor_id===b.tripadvisor_id);v>=0?x[v]=b:x.push(b)}),x}),this.refresh()),(y=s==null?void 0:s.success)!=null&&y.isComplete){d=!0;break}}catch(p){this.handleError(p,"pollForPricing"),(m=(k=this.callbacks).onPropertiesLoadError)==null||m.call(k,p);break}h<t-1&&await new Promise(p=>setTimeout(p,r))}return{completed:d,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,l,d,s,o,u,f;this.ensureAlive(),this.setState({firstCallDone:!1}),this.setSearching(!0),this.clearProperties();try{let c=await de(`${this.apiUrl}/${this.mfid}/hotels`,e);this.updateActiveLocationFromResponse(c);let y=null,k=30,m=c.filters.primary_type;if(t){let p=t(c);y=(i=p.price)!=null?i:null,k=(l=p.limit)!=null?l:30}let h=c.properties.some(p=>!!p.location);if(this._setProperties(c.properties),h&&this.flyToPOIs(c.properties.filter(p=>!!p.location&&(c.filters.primary_type?p.type===c.filters.primary_type:!0)).map(p=>({lat:p.location.lat,lng:p.location.lon})),void 0,e.initial!==!0),c.filters.primary_type&&c.properties.filter(p=>{var g;return p.type===c.filters.primary_type&&(p.type==="Accommodation"?((g=p.pricing)==null?void 0:g.availability)!=="unavailable":!0)}).length>0)m=c.filters.primary_type,this.setPrimaryType(c.filters.primary_type);else if(c.properties.length>0){let p=this.mostCommonTypeFromProperties(c.properties);this.setPrimaryType(p),m=p}if(this.setState({firstCallDone:!0}),c.isComplete===!1&&c.pollingLink){let{completed:p,pollData:g}=await this.pollForPricing({pollingLink:c.pollingLink,...y&&{price:y},...k&&{limit:k}});if(p&&((d=g==null?void 0:g.success)!=null&&d.results)&&g.success.results.filter(M=>{var C;return M.type===c.filters.primary_type&&(M.type==="Accommodation"?((C=M.pricing)==null?void 0:C.availability)!=="unavailable":!0)}).length===0&&m&&m!==c.filters.primary_type){let M=this.mostCommonTypeFromProperties(c.properties);this.setPrimaryType(M)}}return h||(c.properties.some(p=>!!p.location)?this.flyToPOIs(c.properties.filter(p=>!!p.location&&(c.filters.primary_type?p.type===c.filters.primary_type:!0)).map(p=>({lat:p.location.lat,lng:p.location.lon})),void 0,e.initial!==!0):(s=c.filters.location)!=null&&s.latitude&&((o=c.filters.location)!=null&&o.longitude)&&this.flyMapTo(c.filters.location.longitude,c.filters.location.latitude,12,e.initial!==!0)),c}catch(c){return this.handleError(c,"runPropertiesSearch"),a==null||a(c),(f=(u=this.callbacks).onPropertiesLoadError)==null||f.call(u,c),this.clearProperties(),this.setState({firstCallDone:!0}),null}finally{this.setSearching(!1),this.setState({firstCallDone:!0})}}updateActiveLocationFromResponse(e){var d,s,o,u;let t=(d=e.location_id)!=null?d:null,r=(o=(s=e.filters.location)==null?void 0:s.city)!=null?o:void 0,a=((u=e.filters.location)==null?void 0:u.country)||"",i=e.filters.location?[e.filters.location.latitude,e.filters.location.longitude]:void 0;if(!i)return;let l=this.state.activeLocation;(t!==(l==null?void 0:l.location_id)||r!==(l==null?void 0:l.city)||a!==(l==null?void 0:l.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}){this.ensureAlive();let i=this.getFilters(),l=this.getState();if(t&&t.length>0){let s=new Set,o=new Set,u,f,c,y,k,m;t.forEach(h=>{var p,g,M;switch(h.type){case"amenity":s.add(h.value);break;case"hotelStyle":o.add(h.value);break;case"priceRange":h.priceRange&&(u={min:h.priceRange.min,max:(p=h.priceRange.max)!=null?p:0});break;case"minRating":f=(g=h.numericValue)!=null?g:Number(h.value);break;case"starRating":c=(M=h.numericValue)!=null?M:Number(h.value);break;case"primary_type":y=h.propertyType;break;case"transformed_query":k=h.value;break;case"selected_restaurant_price_levels":m=h.priceLevels;break}}),i={...i,...s.size>0&&{amenities:Array.from(s)},...o.size>0&&{hotelStyle:Array.from(o)},...u&&{price:u},...f!==void 0&&{minRating:f},...c!==void 0&&{starRating:c},...y&&{primary_type:y},...k&&{transformed_query:k},...m&&{selected_restaurant_price_levels:m}}}else e||(i.minRating=4);let d={filters:i,...e&&{query:e},...l.bounds?{bounds:l.bounds}:l.activeLocation.location_id?{location_id:l.activeLocation.location_id}:l.activeLocation.coordinates?{latitude:l.activeLocation.coordinates[0],longitude:l.activeLocation.coordinates[1]}:{}};return this.runPropertiesSearch({body:d,beforeApplyProperties:r?s=>{var u,f;let o=r(s.filters,s.location_id);return{price:(u=o.price)!=null?u:null,limit:(f=o.limit)!=null?f:30}}:void 0,smartFiltersClearable:!!e,onError:a})}getClusters(){return this.ensureAlive(),[...this.clusterItems]}refresh(){var a,i,l;if(this.ensureAlive(),!this.adapter)return;let e=this.safeExtractViewState(),t=this.resolvePrimaryType();this.clusterItems=j({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),(l=(i=this.options).onClusterUpdate)==null||l.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:J}safeExtractViewState(){if(!this.adapter)return null;try{return K(this.adapter)}catch{return null}}ensureAlive(){if(this.destroyed)throw new Error("MapFirstCore instance has been destroyed")}};function he(n){return n.platform==="maplibre"}function X(n){return n.platform==="google"}function fe(n){return n.platform==="mapbox"}export{Y as MapFirstCore,z as PropertiesFetchError,de as fetchProperties};
3
3
  //# sourceMappingURL=index.mjs.map