@mapfirst.ai/core 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.global.js +1 -1
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -5
package/dist/index.d.mts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.global.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
"use strict";var MapFirstCore=(()=>{var H=Object.defineProperty;var re=Object.getOwnPropertyDescriptor;var ae=Object.getOwnPropertyNames;var ie=Object.prototype.hasOwnProperty;var ne=(i,e)=>{for(var t in e)H(i,t,{get:e[t],enumerable:!0})},se=(i,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of ae(e))!ie.call(i,a)&&a!==t&&H(i,a,{get:()=>e[a],enumerable:!(r=re(e,a))||r.enumerable});return i};var oe=i=>se(H({},"__esModule",{value:!0}),i);var xe={};ne(xe,{MapFirstCore:()=>G,PropertiesFetchError:()=>O,fetchProperties:()=>ee});function j(i,{insertAt:e}={}){if(!i||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=i:r.appendChild(document.createTextNode(i))}j(`.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(i,e,t,r){var h,l,y;if(typeof document=="undefined")return null;let a=i.marker,n=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":n?"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":n?"":" 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 pe='<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>',le='<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>',me='<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>',ce='<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(i,e,t,r){var k,m,f,p,g,v,C,x;if(typeof document=="undefined")return null;let a=i.marker,n=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":n?"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":n?"":" 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",n||(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=le;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=pe,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=me:a.type==="Attraction"&&(y.innerHTML=ce),l.appendChild(y),l.addEventListener("click",b=>{b.stopPropagation(),o||r==null||r(a)}),h.appendChild(l),h}function E(i,e,t,r){let a=i;a.style.zIndex=t?"20":e?"12":"11";let n=a.querySelector(".mapfirst-marker-pill");n&&(r?n.className="mapfirst-marker-pill mapfirst-marker-pill-pending":n.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(i,e,t,r){let a=i;a.style.zIndex=t?"20":e?"3":"1";let n=a.querySelector(".mapfirst-dot-marker-button");n&&(r?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 N(i){let e=i.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 n,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=de(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=(n=o.marker.pricing)==null?void 0:n.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 de(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 _=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 n,c,d,s,o,u;if(t&&t!==this.primaryType&&(this.primaryType=t),r!==void 0&&(this.selectedMarkerId=r),!((c=(n=this.google)==null?void 0:n.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=ue(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,n=this.selectedMarkerId===e.marker.tripadvisor_id,c=e.kind==="primary"?n?20:a?12:11:n?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 ue(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 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 n,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=he(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=(n=o.marker.pricing)==null?void 0:n.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 he(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 L=class{constructor(e){this.map=e}getMap(){return this.map}};var F=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 R=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(n=>{let c=this.map.addListener(n,t);a.push(c)}),this.cleanupFns.push(()=>{a.forEach(n=>{try{n.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 n=new a.LatLng(t[1],t[0]),c=r.fromLatLngToContainerPixel(n);return c?{x:c.x,y:c.y}:{x:0,y:0}}on(t,r){this.map.addListener(t,r)}off(t,r){var n;let a=(n=globalThis.google)==null?void 0:n.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 z=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 W(i){let e=i.getCenter();return{longitude:e.lng,latitude:e.lat,zoom:i.getZoom(),bearing:i.getBearing(),pitch:i.getPitch()}}var fe=[{zoom:6,threshold:120},{zoom:8,threshold:108},{zoom:10,threshold:92},{zoom:12,threshold:80},{zoom:14,threshold:68},{zoom:16,threshold:56}];function J(i){for(let e of fe)if(i<=e.zoom)return e.threshold;return 48}function $({primaryType:i,markers:e,map:t,selectedMarkerId:r,zoom:a,collisionThresholdPx:n,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=J(a),o=ge(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===i,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)=>ke(P.marker,M.marker,i)),[p,...g]=f,v=p.marker.type===i,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===i;k.push({kind:"primary",marker:M.marker,key:`primary-${M.marker.tripadvisor_id}-p${P?1:0}-s1`});return}ye(p,M)<=o?x.push(M):b.push(M)}),x.forEach(M=>{let P=M.marker.type===i;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=$({markers:b.map(P=>P.marker),map:t,selectedMarkerId:r,zoom:a,primaryType:i,collisionThresholdPx:n,dotCollisionThresholdPx:c});k.push(...M)}}),k}function ye(i,e){return Math.hypot(i.x-e.x,i.y-e.y)}function ge(i){let e=J(i);return Math.max(48,e)}function ke(i,e,t){var s,o;let r=i.type===t,a=e.type===t;if(r&&!a)return 1;if(!r&&a)return-1;let n=K(i)-K(e);if(n!==0)return n;let c=Z(i)-Z(e);if(c!==0)return c;let d=((s=i.reviews)!=null?s:0)-((o=e.reviews)!=null?o:0);return d!==0?d:i.tripadvisor_id-e.tripadvisor_id}function K(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 Z(i){var t,r,a;if(!((r=(t=i.pricing)==null?void 0:t.offer)!=null&&r.price))return-1/0;let e=Number(((a=i.pricing.offer.displayPrice)!=null?a:"0").replace(/[^0-9.,-]+/g,"").replace(/,/g,""));return Number.isNaN(e)?-1/0:e}var be={prod:"https://api.mapfirst.ai",test:"https://ta-backend-test-290791666935.us-central1.run.app"},O=class extends Error{constructor({message:e,status:t,code:r}){super(e),this.name="PropertiesFetchError",this.status=t,this.code=r}};async function ee(i,e,{signal:t}={}){var a,n;let r=await fetch(i,{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=(n=(a=s.detail)!=null?a:s.error)!=null?n:c,d=s.code}catch{}throw new O({message:c,status:r.status,code:d})}return await r.json()}function Y(i){return typeof i=="string"?i:i.toISOString().slice(0,10)}var X="Accommodation";function Me(){let e=new Date(Date.now()+864e6),t=(6-e.getDay()+7)%7,r=new Date(e.getTime()+t*864e5),a=r.getDay(),n=a===0?6:6-a,c=new Date(r.getTime()+(n+1)*864e5);return{checkIn:r,checkOut:c}}var G=class{constructor(e){this.options=e;this.adapter=null;this.properties=[];this.selectedMarkerId=null;this.destroyed=!1;this.clusterItems=[];this.isMapAttached=!1;var a,n,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=(n=e.selectedMarkerId)!=null?n:null,this.environment=(c=e.environment)!=null?c:"prod",this.apiUrl=be[this.environment],this.mfid=(d=e.mfid)!=null?d:"default",this.requestBody=e.requestBody;let t=Q(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=Me();this.state={center:[0,0],zoom:0,bounds:null,pendingBounds:null,tempBounds:null,properties:this.properties,primary:(f=this.primaryType)!=null?f:X,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:n}=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 ve(e)&&e.mapInstance?this.initializeAdapter(new F(e.mapInstance),{maplibregl:e.maplibregl,onMarkerClick:e.onMarkerClick}):Q(e)&&e.mapInstance?this.initializeAdapter(new R(e.mapInstance),{google:e.google,onMarkerClick:e.onMarkerClick}):Pe(e)&&e.mapInstance?this.initializeAdapter(new z(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:n=>{var c;n.location&&this.flyMapTo(n.location.lon,n.location.lat,14),n.type!==this.primaryType&&this.setPrimaryType(n.type),r&&this.setSelectedMarker(n.tripadvisor_id===this.selectedMarkerId?null:n.tripadvisor_id),(c=t.onMarkerClick)==null||c.call(t,n)},onRefresh:()=>this.refresh()}),e}_setProperties(e){var t,r;this.ensureAlive(),this.properties=[...e.filter(a=>{var n;return a.type==="Accommodation"?((n=a.pricing)==null?void 0:n.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(n=>n.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,n,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=(n=this.callbacks).onZoomChange)==null||c.call(n,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 n=this.adapter.getMap();if(n){if(this.options.platform==="google"){this.setFlyToAnimating(!1),n.setCenter({lat:t,lng:e}),r!==null&&typeof r=="number"&&n.setZoom(r!=null?r:13);return}if(a===!1){this.setFlyToAnimating(!1),n.jumpTo&&n.jumpTo({center:[e,t],...r!==null&&{zoom:r!=null?r:13}});return}this.setFlyToAnimating(!0),n.flyTo&&n.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 n=e;if((!n||n.length===0)&&(n=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}))),!(!n||n.length===0)){if(n.length===1){let s=n[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;n.forEach(u=>{o.extend({lat:u.lat,lng:u.lng})}),this.setFlyToAnimating(!0),a.fitBounds(o,this.fitBoundsPadding)}}else if(a.fitBounds){let s=[[n[0].lng,n[0].lat],[n[0].lng,n[0].lat]];n.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=Y(e.checkIn)),e.checkOut instanceof Date&&(e.checkOut=Y(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 n=a.reduce((d,s)=>(d[s.type]=(d[s.type]||0)+1,d),{}),c=Object.entries(n).reduce((d,s)=>n[d[0]]>n[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:n,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 O({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,V,q,U;if(!b.location)return;(I=(P=b.pricing)==null?void 0:P.offer)!=null&&I.price&&n&&(((V=(T=b.pricing)==null?void 0:T.offer)==null?void 0:V.price)<(n==null?void 0:n.min)||((U=(q=b.pricing)==null?void 0:q.offer)==null?void 0:U.price)>(n==null?void 0:n.max))&&(b.pricing.availability="unavailable");let M=x.findIndex(te=>te.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 n,c,d,s,o,u,h;this.ensureAlive(),this.setState({firstCallDone:!1}),this.setSearching(!0),this.clearProperties();try{let l=await ee(`${this.apiUrl}/${this.mfid}/hotels`,e),y=null,k=30,m=l.filters.primary_type;if(t){let p=t(l);y=(n=p.price)!=null?n: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,n,c;if(this.ensureAlive(),!this.adapter)return;let e=this.safeExtractViewState(),t=this.resolvePrimaryType();this.clusterItems=$({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=(n=this.options).onClusterUpdate)==null||c.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,r;return(r=(t=this.primaryType)!=null?t:(e=this.properties.find(a=>a.type))==null?void 0:e.type)!=null?r:X}safeExtractViewState(){if(!this.adapter)return null;try{return W(this.adapter)}catch{return null}}ensureAlive(){if(this.destroyed)throw new Error("MapFirstCore instance has been destroyed")}};function ve(i){return i.platform==="maplibre"}function Q(i){return i.platform==="google"}function Pe(i){return i.platform==="mapbox"}return oe(xe);})();
|
|
2
|
+
`);function A(i,e,t,r){var h,l,y;if(typeof document=="undefined")return null;let a=i.marker,n=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":n?"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":n?"":" 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 pe='<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>',le='<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>',me='<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>',ce='<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(i,e,t,r){var k,m,f,p,g,v,C,x;if(typeof document=="undefined")return null;let a=i.marker,n=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":n?"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":n?"":" 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",n||(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=le;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=pe,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=me:a.type==="Attraction"&&(y.innerHTML=ce),l.appendChild(y),l.addEventListener("click",b=>{b.stopPropagation(),o||r==null||r(a)}),h.appendChild(l),h}function E(i,e,t,r){let a=i;a.style.zIndex=t?"20":e?"12":"11";let n=a.querySelector(".mapfirst-marker-pill");n&&(r?n.className="mapfirst-marker-pill mapfirst-marker-pill-pending":n.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(i,e,t,r){let a=i;a.style.zIndex=t?"20":e?"3":"1";let n=a.querySelector(".mapfirst-dot-marker-button");n&&(r?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 N(i){let e=i.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 n,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=de(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=(n=o.marker.pricing)==null?void 0:n.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 de(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 _=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 n,c,d,s,o,u;if(t&&t!==this.primaryType&&(this.primaryType=t),r!==void 0&&(this.selectedMarkerId=r),!((c=(n=this.google)==null?void 0:n.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=ue(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,n=this.selectedMarkerId===e.marker.tripadvisor_id,c=e.kind==="primary"?n?20:a?12:11:n?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 ue(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 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 n,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=he(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=(n=o.marker.pricing)==null?void 0:n.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 he(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 L=class{constructor(e){this.map=e}getMap(){return this.map}};var F=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 R=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(n=>{let c=this.map.addListener(n,t);a.push(c)}),this.cleanupFns.push(()=>{a.forEach(n=>{try{n.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 n=new a.LatLng(t[1],t[0]),c=r.fromLatLngToContainerPixel(n);return c?{x:c.x,y:c.y}:{x:0,y:0}}on(t,r){this.map.addListener(t,r)}off(t,r){var n;let a=(n=globalThis.google)==null?void 0:n.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 z=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 W(i){let e=i.getCenter();return{longitude:e.lng,latitude:e.lat,zoom:i.getZoom(),bearing:i.getBearing(),pitch:i.getPitch()}}var fe=[{zoom:6,threshold:120},{zoom:8,threshold:108},{zoom:10,threshold:92},{zoom:12,threshold:80},{zoom:14,threshold:68},{zoom:16,threshold:56}];function J(i){for(let e of fe)if(i<=e.zoom)return e.threshold;return 48}function $({primaryType:i,markers:e,map:t,selectedMarkerId:r,zoom:a,collisionThresholdPx:n,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=J(a),o=ge(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===i,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)=>ke(P.marker,M.marker,i)),[p,...g]=f,v=p.marker.type===i,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===i;k.push({kind:"primary",marker:M.marker,key:`primary-${M.marker.tripadvisor_id}-p${P?1:0}-s1`});return}ye(p,M)<=o?x.push(M):b.push(M)}),x.forEach(M=>{let P=M.marker.type===i;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=$({markers:b.map(P=>P.marker),map:t,selectedMarkerId:r,zoom:a,primaryType:i,collisionThresholdPx:n,dotCollisionThresholdPx:c});k.push(...M)}}),k}function ye(i,e){return Math.hypot(i.x-e.x,i.y-e.y)}function ge(i){let e=J(i);return Math.max(48,e)}function ke(i,e,t){var s,o;let r=i.type===t,a=e.type===t;if(r&&!a)return 1;if(!r&&a)return-1;let n=K(i)-K(e);if(n!==0)return n;let c=Z(i)-Z(e);if(c!==0)return c;let d=((s=i.reviews)!=null?s:0)-((o=e.reviews)!=null?o:0);return d!==0?d:i.tripadvisor_id-e.tripadvisor_id}function K(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 Z(i){var t,r,a;if(!((r=(t=i.pricing)==null?void 0:t.offer)!=null&&r.price))return-1/0;let e=Number(((a=i.pricing.offer.displayPrice)!=null?a:"0").replace(/[^0-9.,-]+/g,"").replace(/,/g,""));return Number.isNaN(e)?-1/0:e}var be={prod:"https://api.mapfirst.ai",test:"https://ta-backend-test-290791666935.us-central1.run.app"},O=class extends Error{constructor({message:e,status:t,code:r}){super(e),this.name="PropertiesFetchError",this.status=t,this.code=r}};async function ee(i,e,{signal:t}={}){var a,n;let r=await fetch(i,{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=(n=(a=s.detail)!=null?a:s.error)!=null?n:c,d=s.code}catch{}throw new O({message:c,status:r.status,code:d})}return await r.json()}function Y(i){return typeof i=="string"?i:i.toISOString().slice(0,10)}var X="Accommodation";function Me(){let e=new Date(Date.now()+864e6),t=(6-e.getDay()+7)%7,r=new Date(e.getTime()+t*864e5),a=r.getDay(),n=a===0?6:6-a,c=new Date(r.getTime()+(n+1)*864e5);return{checkIn:r,checkOut:c}}var G=class{constructor(e){this.options=e;this.adapter=null;this.properties=[];this.selectedMarkerId=null;this.destroyed=!1;this.clusterItems=[];this.isMapAttached=!1;var a,n,c,d,s,o,u,h,l,y,k,m,f,p,g,v;this.properties=[...(a=e.properties)!=null?a:[]],this.primaryType=e.primaryType,this.selectedMarkerId=(n=e.selectedMarkerId)!=null?n:null,this.environment=(c=e.environment)!=null?c:"prod",this.apiUrl=(d=e.apiUrl)!=null?d:be[this.environment],this.mfid=(s=e.mfid)!=null?s:"default",this.requestBody=e.requestBody;let t=Q(e);this.fitBoundsPadding={top:(u=(o=e.fitBoundsPadding)==null?void 0:o.top)!=null?u:t?0:50,bottom:(l=(h=e.fitBoundsPadding)==null?void 0:h.bottom)!=null?l:t?0:160,left:(k=(y=e.fitBoundsPadding)==null?void 0:y.left)!=null?k:t?0:50,right:(f=(m=e.fitBoundsPadding)==null?void 0:m.right)!=null?f:t?0:50};let r=Me();this.state={center:[0,0],zoom:0,bounds:null,pendingBounds:null,tempBounds:null,properties:this.properties,primary:(p=this.primaryType)!=null?p:X,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=(v=e.callbacks)!=null?v:{},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:n}=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 ve(e)&&e.mapInstance?this.initializeAdapter(new F(e.mapInstance),{maplibregl:e.maplibregl,onMarkerClick:e.onMarkerClick}):Q(e)&&e.mapInstance?this.initializeAdapter(new R(e.mapInstance),{google:e.google,onMarkerClick:e.onMarkerClick}):Pe(e)&&e.mapInstance?this.initializeAdapter(new z(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:n=>{var c;n.location&&this.flyMapTo(n.location.lon,n.location.lat,14),n.type!==this.primaryType&&this.setPrimaryType(n.type),r&&this.setSelectedMarker(n.tripadvisor_id===this.selectedMarkerId?null:n.tripadvisor_id),(c=t.onMarkerClick)==null||c.call(t,n)},onRefresh:()=>this.refresh()}),e}_setProperties(e){var t,r;this.ensureAlive(),this.properties=[...e.filter(a=>{var n;return a.type==="Accommodation"?((n=a.pricing)==null?void 0:n.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(n=>n.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,n,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=(n=this.callbacks).onZoomChange)==null||c.call(n,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 n=this.adapter.getMap();if(n){if(this.options.platform==="google"){this.setFlyToAnimating(!1),n.setCenter({lat:t,lng:e}),r!==null&&typeof r=="number"&&n.setZoom(r!=null?r:13);return}if(a===!1){this.setFlyToAnimating(!1),n.jumpTo&&n.jumpTo({center:[e,t],...r!==null&&{zoom:r!=null?r:13}});return}this.setFlyToAnimating(!0),n.flyTo&&n.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 n=e;if((!n||n.length===0)&&(n=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}))),!(!n||n.length===0)){if(n.length===1){let s=n[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;n.forEach(u=>{o.extend({lat:u.lat,lng:u.lng})}),this.setFlyToAnimating(!0),a.fitBounds(o,this.fitBoundsPadding)}}else if(a.fitBounds){let s=[[n[0].lng,n[0].lat],[n[0].lng,n[0].lat]];n.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=Y(e.checkIn)),e.checkOut instanceof Date&&(e.checkOut=Y(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 n=a.reduce((d,s)=>(d[s.type]=(d[s.type]||0)+1,d),{}),c=Object.entries(n).reduce((d,s)=>n[d[0]]>n[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:n,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 O({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,V,q,U;if(!b.location)return;(I=(P=b.pricing)==null?void 0:P.offer)!=null&&I.price&&n&&(((V=(T=b.pricing)==null?void 0:T.offer)==null?void 0:V.price)<(n==null?void 0:n.min)||((U=(q=b.pricing)==null?void 0:q.offer)==null?void 0:U.price)>(n==null?void 0:n.max))&&(b.pricing.availability="unavailable");let M=x.findIndex(te=>te.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 n,c,d,s,o,u,h;this.ensureAlive(),this.setState({firstCallDone:!1}),this.setSearching(!0),this.clearProperties();try{let l=await ee(`${this.apiUrl}/${this.mfid}/hotels`,e),y=null,k=30,m=l.filters.primary_type;if(t){let p=t(l);y=(n=p.price)!=null?n: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,n,c;if(this.ensureAlive(),!this.adapter)return;let e=this.safeExtractViewState(),t=this.resolvePrimaryType();this.clusterItems=$({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=(n=this.options).onClusterUpdate)==null||c.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,r;return(r=(t=this.primaryType)!=null?t:(e=this.properties.find(a=>a.type))==null?void 0:e.type)!=null?r:X}safeExtractViewState(){if(!this.adapter)return null;try{return W(this.adapter)}catch{return null}}ensureAlive(){if(this.destroyed)throw new Error("MapFirstCore instance has been destroyed")}};function ve(i){return i.platform==="maplibre"}function Q(i){return i.platform==="google"}function Pe(i){return i.platform==="mapbox"}return oe(xe);})();
|
|
3
3
|
//# sourceMappingURL=index.global.js.map
|