@mapfirst.ai/core 0.0.25 → 0.0.26
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 +11 -7
- package/dist/index.d.ts +11 -7
- package/dist/index.global.js +21 -20
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +21 -20
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +20 -19
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,32 +1,33 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
`);function K(
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
"use strict";var N=Object.defineProperty;var pe=Object.getOwnPropertyDescriptor;var le=Object.getOwnPropertyNames;var ce=Object.prototype.hasOwnProperty;var me=(i,e)=>{for(var t in e)N(i,t,{get:e[t],enumerable:!0})},de=(i,e,t,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of le(e))!ce.call(i,r)&&r!==t&&N(i,r,{get:()=>e[r],enumerable:!(a=pe(e,r))||a.enumerable});return i};var ue=i=>de(N({},"__esModule",{value:!0}),i);var Be={};me(Be,{MapFirstCore:()=>V,PropertiesFetchError:()=>R,convertToApiFilters:()=>re,fetchImages:()=>z,fetchProperties:()=>se,processApiFilters:()=>te});module.exports=ue(Be);function O(i,{insertAt:e}={}){if(!i||typeof document=="undefined")return;let t=document.head||document.getElementsByTagName("head")[0],a=document.createElement("style");a.type="text/css",e==="top"&&t.firstChild?t.insertBefore(a,t.firstChild):t.appendChild(a),a.styleSheet?a.styleSheet.cssText=i:a.appendChild(document.createTextNode(i))}O(`.mapfirst-marker-root{display:flex;z-index:20;flex-direction:column;align-items:center;pointer-events:auto}.mapfirst-marker-pill{border:2px solid;border-radius:999px;padding:8px;font-size:16px;font-weight:600;font-family:system-ui,-apple-system,sans-serif;box-shadow:0 4px 6px #6b728080;display:flex;align-items:center;justify-content:center;position:relative;transition:transform .2s;transform-origin:center bottom}.mapfirst-marker-pill-pending{background:#ffffff80;backdrop-filter:blur(4px);border-color:transparent;cursor:default}.mapfirst-marker-pill-active{background:#012b11;border-color:#fff;color:#fff;cursor:pointer}.mapfirst-marker-pill-active.mapfirst-marker-non-primary{background:#ffffffb3;border-color:#03852e80;color:#03852e80;padding:4px}.mapfirst-marker-pill-active.mapfirst-marker-selected{background:#fff;border-color:#03852e;color:#03852e;transform:scale(1.2)}.mapfirst-marker-pill-active:hover{transform:scale(1.2)}.mapfirst-marker-badge{position:absolute;top:-12px;right:-20px}.mapfirst-marker-award-container{position:relative;width:32px;height:32px}.mapfirst-marker-award-back{position:absolute;stroke:#f5f5f5;stroke-width:2px}.mapfirst-marker-award-dot{position:absolute;top:6.2px;left:6.3px;width:18.5px;height:18.5px;border-radius:50%;z-index:1}.mapfirst-marker-award-dot-type-0{background:#ffef0e}.mapfirst-marker-award-dot-type-1{background:#01ea5b}.mapfirst-marker-award-front{position:relative;z-index:2;color:#012b11}.mapfirst-marker-rating-badge{display:flex;align-items:center;justify-content:center;border-radius:999px;background:#03852e;color:#fff;font-size:12px;line-height:1;box-shadow:0 2px 4px #0003;padding:2px 6px;border:2px solid #ffffff;font-weight:400}.mapfirst-marker-content{display:flex;align-items:center}.mapfirst-marker-loading-video{width:20px;height:20px;display:block}.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}.mapfirst-property-hover-card{position:absolute;width:270px;background:#fff;border-radius:8px;box-shadow:0 4px 12px #00000026;overflow:hidden;display:flex;pointer-events:auto;z-index:9999;transition:opacity .2s;height:120px;text-decoration:none;color:inherit}.mapfirst-property-hover-card img{width:120px;height:120px;object-fit:cover;flex-shrink:0}.mapfirst-property-hover-image{width:120px;height:120px;flex-shrink:0}.mapfirst-property-hover-image-placeholder{background-color:#e5e7eb}.mapfirst-property-hover-details{display:flex;flex-direction:column;padding:8px 12px;flex:1;gap:4px}.mapfirst-property-hover-name{font-size:12px;font-weight:600;color:#1a1a1a;overflow:hidden;text-overflow:ellipsis;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;line-height:1.3}.mapfirst-property-hover-rating{display:flex;align-items:center;gap:4px;font-size:12px}.mapfirst-property-hover-rating .rating-value{font-weight:600;color:#1a1a1a}.mapfirst-property-hover-rating .stars{display:flex;gap:1px;font-size:10px;line-height:1;align-items:center}.mapfirst-property-hover-rating .reviews{color:#666;font-size:11px}.mapfirst-property-hover-price{font-size:12px;color:#666;margin-top:2px}.mapfirst-property-hover-price strong{color:#1a1a1a;font-weight:600}.mapfirst-property-hover-learn-more{font-size:12px;color:#03852e;text-decoration:none;font-weight:500;margin-top:auto;pointer-events:auto;display:inline-block}.mapfirst-property-hover-learn-more:hover{text-decoration:underline}
|
|
2
|
+
`);function K(i,e,t,a){var M,c,p;if(typeof document=="undefined")return null;let r=i.marker,n=r.type===e,s=t===r.tripadvisor_id,l=r.type==="Accommodation"&&((c=(M=r.pricing)==null?void 0:M.offer)==null?void 0:c.availability)!=="available",u=document.createElement("div");u.className="mapfirst-dot-marker-container",u.style.zIndex=s?"20":n?"3":"1";let y=document.createElement("div");return y.className=l?"mapfirst-dot-marker-button mapfirst-dot-marker-button-pending":`mapfirst-dot-marker-button mapfirst-dot-marker-button-active${s?" mapfirst-dot-marker-selected":n?"":" mapfirst-dot-marker-non-primary"}`,y.title=(p=r.name)!=null?p:String(r.tripadvisor_id),y.addEventListener("click",b=>{b.stopPropagation(),l||a==null||a(r)}),u.appendChild(y),u}var fe='<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>',he='<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>',ge='<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>',ye='<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>',be='<video class="mapfirst-marker-loading-video" src="https://api.mapfirst.ai/static/images/loading.webm" autoplay loop muted></video>';function $(i,e,t,a){if(i.dataset.hasHoverCard==="true")return;i.dataset.hasHoverCard="true";let r=ke(t),n=null,s=null,o=null,l=()=>{n&&(clearTimeout(n),n=null),s&&(clearTimeout(s),s=null),o&&(cancelAnimationFrame(o),o=null),r.parentElement&&r.remove()},u=()=>{if(r.parentElement){let p=i.parentElement;for(;p&&getComputedStyle(p).position==="static";)p=p.parentElement;p&&(Z(r,i,p),o=requestAnimationFrame(u))}},y=(p=!1)=>{s&&(clearTimeout(s),s=null);let b=()=>{let d=i.parentElement;for(;d&&getComputedStyle(d).position==="static";)d=d.parentElement;d&&(d.appendChild(r),Z(r,i,d),ve(r,t),o=requestAnimationFrame(u))};p?b():n=setTimeout(b,300)},M=()=>{a||(n&&(clearTimeout(n),n=null),o&&(cancelAnimationFrame(o),o=null),s=setTimeout(()=>{r.parentElement&&r.remove()},100))};a&&y(!0),e.addEventListener("mouseenter",()=>y(!1)),e.addEventListener("mouseleave",M),r.addEventListener("mouseenter",()=>{s&&(clearTimeout(s),s=null),!o&&r.parentElement&&(o=requestAnimationFrame(u))}),r.addEventListener("mouseleave",M);let c=new MutationObserver(p=>{for(let b of p)for(let d of b.removedNodes)if(d===i||d.contains(i)){l(),c.disconnect();return}});if(i.parentElement)c.observe(i.parentElement,{childList:!0,subtree:!0});else{let p=setInterval(()=>{i.parentElement&&(c.observe(i.parentElement,{childList:!0,subtree:!0}),clearInterval(p))},100)}}function Me(i){return`/img/${i.toLowerCase().replace(/\s+/g,"").replace(/&/g,"")}.webp`}function ke(i){var l,u,y,M,c,p;let e=(y=(u=(l=i.pricing)==null?void 0:l.offer)==null?void 0:u.clickUrl)!=null?y:i.url,t=document.createElement(e?"a":"div");t.className="mapfirst-property-hover-card",t.setAttribute("data-marker-id",i.tripadvisor_id.toString()),e&&(t.href=e,t.target="_blank");let a=i.rating||0,r=i.reviews||0,n=(p=(c=(M=i.pricing)==null?void 0:M.offer)==null?void 0:c.displayPrice)!=null?p:i.price_level,s=()=>{let b=Math.floor(a),d=a%1!==0,g=[],f=`
|
|
3
|
+
display: inline-block;
|
|
4
|
+
width: 8px;
|
|
5
|
+
height: 8px;
|
|
6
|
+
border: 1px solid #03852e;
|
|
7
|
+
border-radius: 9999px;
|
|
8
|
+
`;for(let h=0;h<b;h++)g.push(`<span style="${f} background-color: #03852e;"></span>`);d&&g.push(`<span style="${f} background: linear-gradient(90deg, #03852e 50%, transparent 50%);"></span>`);let m=5-Math.ceil(a);for(let h=0;h<m;h++)g.push(`<span style="${f}"></span>`);return g.join("")},o=Me(i.type);return t.innerHTML=`
|
|
9
|
+
<div
|
|
10
|
+
class="mapfirst-property-hover-image mapfirst-property-hover-image-placeholder"
|
|
11
|
+
data-tripadvisor-id="${i.tripadvisor_id}"
|
|
12
|
+
data-default-image="${o}"
|
|
13
|
+
></div>
|
|
8
14
|
<div class="mapfirst-property-hover-details">
|
|
9
|
-
<div class="mapfirst-property-hover-name">${
|
|
15
|
+
<div class="mapfirst-property-hover-name">${i.name}</div>
|
|
10
16
|
<div class="mapfirst-property-hover-rating">
|
|
11
|
-
<span class="rating-value">${
|
|
17
|
+
<span class="rating-value">${a.toFixed(1)}</span>
|
|
12
18
|
<span class="stars">${s()}</span>
|
|
13
19
|
<span class="reviews">(${r})</span>
|
|
14
20
|
</div>
|
|
15
|
-
${
|
|
21
|
+
${i.type==="Accommodation"&&n?`
|
|
16
22
|
<div class="mapfirst-property-hover-price">
|
|
17
|
-
Starting at <strong>${
|
|
23
|
+
Starting at <strong>${n}</strong>
|
|
18
24
|
</div>
|
|
19
25
|
`:""}
|
|
20
|
-
${
|
|
21
|
-
<
|
|
22
|
-
href="${i}"
|
|
23
|
-
target="_blank"
|
|
24
|
-
rel="noopener noreferrer"
|
|
25
|
-
class="mapfirst-property-hover-learn-more"
|
|
26
|
-
>
|
|
26
|
+
${e?`
|
|
27
|
+
<span class="mapfirst-property-hover-learn-more">
|
|
27
28
|
Learn More
|
|
28
|
-
</
|
|
29
|
+
</span>
|
|
29
30
|
`:""}
|
|
30
31
|
</div>
|
|
31
|
-
`,e}function U(n,e,t){let r=e.getBoundingClientRect(),a=t.getBoundingClientRect(),i=270,s=120,l=12,o=a.right-r.right,p=r.left-a.left,h=a.bottom-r.bottom,g=r.top-a.top,c=r.left-a.left+r.width/2-i/2,y=r.top-a.top+r.height+l;c<0?c=8:c+i>a.width&&(c=a.width-i-8),h<s+l&&g>h&&(y=r.top-a.top-s-l),n.style.left=`${c}px`,n.style.top=`${y}px`}function Z(n,e,t,r){var M,d,f,u,m,k,T;if(typeof document=="undefined")return null;let a=n.marker,i=a.type===e,s=t===a.tripadvisor_id,l=a.type==="Accommodation",o=(d=(M=a.pricing)==null?void 0:M.offer)==null?void 0:d.displayPrice,p=l&&!o,h=(()=>{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)})(),g=document.createElement("div");g.className="mapfirst-marker-root",g.style.zIndex=s?"20":i?"12":"11";let c=document.createElement("div");if(c.className=p?"mapfirst-marker-pill mapfirst-marker-pill-pending":`mapfirst-marker-pill mapfirst-marker-pill-active${s?" mapfirst-marker-selected":i?"":" mapfirst-marker-non-primary"}`,!p&&((f=a.awards)!=null&&f.length||h)){let b=document.createElement("div");if(b.className="mapfirst-marker-badge",i||(b.style.opacity="0.2"),b.className="mapfirst-marker-badge",(u=a.awards)!=null&&u.length&&a.awards[0].type){let P=document.createElement("div");P.className="mapfirst-marker-award-container";let x=document.createElement("div");x.className="mapfirst-marker-award-back",x.innerHTML=he;let L=document.createElement("div");L.className=`mapfirst-marker-award-dot mapfirst-marker-award-dot-type-${a.awards[0].type}`;let v=document.createElement("div");v.className="mapfirst-marker-award-front",v.innerHTML=fe,P.appendChild(x),P.appendChild(L),P.appendChild(v),b.appendChild(P)}else h&&(b.className="mapfirst-marker-badge mapfirst-marker-rating-badge",b.textContent=h);c.appendChild(b)}let y=document.createElement("span");if(y.className="mapfirst-marker-content",l?y.textContent=(T=(k=(m=a.pricing)==null?void 0:m.offer)==null?void 0:k.displayPrice)!=null?T:"\u2014":a.type==="Eat & Drink"?y.innerHTML=ge:a.type==="Attraction"&&(y.innerHTML=ye),c.appendChild(y),c.addEventListener("click",b=>{b.stopPropagation(),p||r==null||r(a)}),!p){let b=Me(a),P=null,x=null,L=null,v=()=>{P&&(clearTimeout(P),P=null),x&&(clearTimeout(x),x=null),L&&(cancelAnimationFrame(L),L=null),b.parentElement&&b.remove()},A=()=>{if(b.parentElement){let C=g.parentElement;for(;C&&getComputedStyle(C).position==="static";)C=C.parentElement;C&&(U(b,g,C),L=requestAnimationFrame(A))}},I=(C=!1)=>{x&&(clearTimeout(x),x=null);let O=()=>{let w=g.parentElement;for(;w&&getComputedStyle(w).position==="static";)w=w.parentElement;w&&(w.appendChild(b),U(b,g,w),L=requestAnimationFrame(A))};C?O():P=setTimeout(O,300)},_=()=>{s||(P&&(clearTimeout(P),P=null),L&&(cancelAnimationFrame(L),L=null),x=setTimeout(()=>{b.parentElement&&b.remove()},100))};s&&I(!0),c.addEventListener("mouseenter",()=>I(!1)),c.addEventListener("mouseleave",_),b.addEventListener("mouseenter",()=>{x&&(clearTimeout(x),x=null),!L&&b.parentElement&&(L=requestAnimationFrame(A))}),b.addEventListener("mouseleave",_);let B=new MutationObserver(C=>{for(let O of C)for(let w of O.removedNodes)if(w===g||w.contains(g)){v(),B.disconnect();return}});if(g.parentElement)B.observe(g.parentElement,{childList:!0,subtree:!0});else{let C=setInterval(()=>{g.parentElement&&(B.observe(g.parentElement,{childList:!0,subtree:!0}),clearInterval(C))},100)}}return g.appendChild(c),g}function W(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 s=a.querySelector(".mapfirst-marker-badge");s instanceof HTMLElement&&(s.style.opacity=!e&&!t?"0.2":"")}function X(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 J(n){let e=n.match(/^(?:primary|dot)-(\d+)-/);return e?parseInt(e[1],10):null}var S=class{constructor(e,t){this.markerCache=new Map;this.primaryType="Accommodation";this.selectedMarkerId=null;this.mapInstance=e,this.onMarkerClick=t}render(e,t,r){var i,s,l,o;t&&t!==this.primaryType&&(this.primaryType=t),r!==void 0&&(this.selectedMarkerId=r);let a=new Set(e.map(p=>p.key));for(let[p,h]of this.markerCache.entries())a.has(p)||(this.removeMarkerFromMap(h.marker),this.markerCache.delete(p));for(let p of e){let h=ke(p.marker.location);if(!h)continue;let g=this.markerCache.get(p.key);if(g)try{this.updateMarkerPosition(g.marker,h)}catch{this.removeMarkerFromMap(g.marker),this.markerCache.delete(p.key),this.createAndAddMarker(p,h)}else{let c=p.marker.tripadvisor_id,y,M;for(let[d,f]of this.markerCache.entries())if(J(d)===c&&f.kind===p.kind){y=f,M=d;break}if(y&&M){let d=p.marker.type===this.primaryType,f=this.selectedMarkerId===p.marker.tripadvisor_id,u=p.marker.type==="Accommodation",m=p.kind==="primary"?u&&!((s=(i=p.marker.pricing)==null?void 0:i.offer)!=null&&s.displayPrice):u&&((o=(l=p.marker.pricing)==null?void 0:l.offer)==null?void 0:o.availability)!=="available",k=this.getMarkerElement(y.marker);k&&(p.kind==="primary"?W(k,d,f,m):X(k,d,f,m)),this.updateMarkerZIndex(y.marker,p,d,f),this.markerCache.delete(M),this.markerCache.set(p.key,y);try{this.updateMarkerPosition(y.marker,h)}catch{}}else this.createAndAddMarker(p,h)}}}destroy(){for(let e of this.markerCache.values())this.removeMarkerFromMap(e.marker);this.markerCache.clear()}createAndAddMarker(e,t){let r=e.kind==="primary"?Z(e,this.primaryType,this.selectedMarkerId,this.onMarkerClick):K(e,this.primaryType,this.selectedMarkerId,this.onMarkerClick);if(!r)return;let a=e.marker.type===this.primaryType,i=this.selectedMarkerId===e.marker.tripadvisor_id;try{let s=this.createMarker(r,t,e,a,i);s&&this.markerCache.set(e.key,{key:e.key,marker:s,kind:e.kind,parentId:e.kind==="dot"?e.parentId:void 0})}catch(s){console.error("Error creating marker",s)}}updateMarkerZIndex(e,t,r,a){}};function ke(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 R=class extends S{constructor(e){var t;super(e.mapInstance,e.onMarkerClick),this.MarkerCtor=(t=e.maplibregl)==null?void 0:t.Marker}render(e,t,r){this.MarkerCtor&&super.render(e,t,r)}createMarker(e,t,r){return this.MarkerCtor?new this.MarkerCtor({element:e,anchor:r.kind==="primary"?"bottom":"center"}).setLngLat([t.lon,t.lat]).addTo(this.mapInstance):null}removeMarkerFromMap(e){try{e.remove()}catch{}}updateMarkerPosition(e,t){e.setLngLat([t.lon,t.lat])}getMarkerElement(e){return e.getElement()}};var F=class extends S{constructor(e){super(e.mapInstance,e.onMarkerClick),this.google=e.google}render(e,t,r){var a,i;if(!((i=(a=this.google)==null?void 0:a.marker)!=null&&i.AdvancedMarkerElement)){console.warn("AdvancedMarkerElement not available");return}super.render(e,t,r)}createMarker(e,t,r,a,i){var l,o;if(!((o=(l=this.google)==null?void 0:l.marker)!=null&&o.AdvancedMarkerElement))return null;let s=r.kind==="primary"?i?20:a?12:11:i?20:a?3:1;return new this.google.marker.AdvancedMarkerElement({map:this.mapInstance,position:{lat:t.lat,lng:t.lon},content:e,zIndex:s})}removeMarkerFromMap(e){try{e.map=null}catch(t){console.error("Error removing marker",t)}}updateMarkerPosition(e,t){e.position={lat:t.lat,lng:t.lon}}getMarkerElement(e){let t=e.content;return t instanceof HTMLElement?t:null}updateMarkerZIndex(e,t,r,a){let i=t.kind==="primary"?a?20:r?12:11:a?20:r?3:1;e.zIndex=i}};var N=class extends S{constructor(e){var t;super(e.mapInstance,e.onMarkerClick),this.MarkerCtor=(t=e.mapboxgl)==null?void 0:t.Marker}render(e,t,r){this.MarkerCtor&&super.render(e,t,r)}createMarker(e,t,r){return this.MarkerCtor?new this.MarkerCtor({element:e,anchor:r.kind==="primary"?"bottom":"center"}).setLngLat([t.lon,t.lat]).addTo(this.mapInstance):null}removeMarkerFromMap(e){try{e.remove()}catch{}}updateMarkerPosition(e,t){e.setLngLat([t.lon,t.lat])}getMarkerElement(e){return e.getElement()}};var E=class{constructor(e){this.map=e}getMap(){return this.map}setupImpressionTracking(e){if(typeof window=="undefined"||!window.IntersectionObserver)return;let t=this.getContainer();if(!t)return;let r=new IntersectionObserver(s=>{s.forEach(l=>{l.isIntersecting&&(e(),r.disconnect())})},{threshold:.1});r.observe(t);let a=()=>r.disconnect(),i=this.cleanup.bind(this);this.cleanup=()=>{a(),i()}}};var H=class extends E{constructor(t){super(t);this.cleanupFns=[]}initialize(t){return this.markerManager=new R({mapInstance:this.map,maplibregl:t.maplibregl,onMarkerClick:t.onMarkerClick}),t.onRefresh&&this.attachEventListeners(t.onRefresh),t.onMapMoveEnd&&this.attachBoundsTracking(t.onMapMoveEnd),this.markerManager}attachBoundsTracking(t){if(!this.map||typeof this.map.on!="function")return;let r=()=>{let i=this.getMapBounds();t(i)},a=()=>{let i=this.getMapBounds();t(i)};this.map.loaded&&this.map.loaded()?a():(this.map.once("load",a),this.cleanupFns.push(()=>{typeof this.map.off=="function"&&this.map.off("load",a)})),this.map.on("moveend",r),this.cleanupFns.push(()=>{typeof this.map.off=="function"&&this.map.off("moveend",r)})}attachEventListeners(t){if(!this.map||typeof this.map.on!="function")return;["move","zoom","dragend","pitch","rotate"].forEach(a=>{this.map.on(a,t),this.cleanupFns.push(()=>{typeof this.map.off=="function"&&this.map.off(a,t)})})}getMarkerManager(){return this.markerManager}getContainer(){var t,r;return((r=(t=this.map)==null?void 0:t.getContainer)==null?void 0:r.call(t))||null}cleanup(){for(let t of this.cleanupFns)try{t()}catch{}this.cleanupFns.length=0}getMap(){return this.map}getCenter(){let t=this.map.getCenter();return{lng:t.lng,lat:t.lat}}getZoom(){return this.map.getZoom()}getBearing(){return this.map.getBearing()}getPitch(){return this.map.getPitch()}getMapBounds(){let t=this.map.getBounds(),r=t.getSouthWest(),a=t.getNorthEast();return{sw:{lat:r.lat,lng:r.lng},ne:{lat:a.lat,lng:a.lng}}}project(t){return this.map.project({lng:t[0],lat:t[1]})}on(t,r){this.map.on(t,r)}off(t,r){this.map.off(t,r)}resize(){this.map.resize()}remove(){this.cleanup(),this.map.remove()}};var z=class extends E{constructor(t){super(t);this.cleanupFns=[];this.initializeOverlayView()}initialize(t){return this.markerManager=new F({mapInstance:this.map,google:t.google,onMarkerClick:t.onMarkerClick}),t.onRefresh&&this.attachEventListeners(t.onRefresh),t.onMapMoveEnd&&this.attachBoundsTracking(t.onMapMoveEnd,t.google),this.markerManager}attachBoundsTracking(t,r){if(!this.map)return;let a=()=>{let s=this.getMapBounds();t(s)};a();let i=r.event.addListener(this.map,"idle",a);this.cleanupFns.push(()=>{r.event.removeListener(i)})}attachEventListeners(t){let r=["center_changed","zoom_changed","drag","heading_changed","tilt_changed"],a=[];r.forEach(i=>{let s=this.map.addListener(i,t);a.push(s)}),this.cleanupFns.push(()=>{a.forEach(i=>{try{i.remove()}catch{}})})}getMarkerManager(){return this.markerManager}getContainer(){var t,r;return((r=(t=this.map)==null?void 0:t.getDiv)==null?void 0:r.call(t))||null}cleanup(){for(let t of this.cleanupFns)try{t()}catch{}this.cleanupFns.length=0}initializeOverlayView(){var a;let t=(a=globalThis.google)==null?void 0:a.maps;if(!t)return;let r=t.OverlayView;r&&(this.overlayView=new r,this.overlayView.draw=function(){},this.overlayView.setMap(this.map))}getMap(){return this.map}getCenter(){let t=this.map.getCenter();return t?{lng:t.lng(),lat:t.lat()}:{lng:0,lat:0}}getZoom(){var t;return(t=this.map.getZoom())!=null?t:0}getBearing(){var t;return(t=this.map.getHeading())!=null?t:0}getPitch(){var t;return(t=this.map.getTilt())!=null?t:0}getMapBounds(){let t=this.map.getBounds();if(!t)return{sw:{lat:0,lng:0},ne:{lat:0,lng:0}};let r=t.getSouthWest(),a=t.getNorthEast();return{sw:{lat:r.lat(),lng:r.lng()},ne:{lat:a.lat(),lng:a.lng()}}}project(t){var l;if(!this.overlayView)return{x:0,y:0};let r=this.overlayView.getProjection();if(!r)return{x:0,y:0};let a=(l=globalThis.google)==null?void 0:l.maps;if(!a)return{x:0,y:0};let i=new a.LatLng(t[1],t[0]),s=r.fromLatLngToContainerPixel(i);return s?{x:s.x,y:s.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 $=class extends E{constructor(t){super(t);this.cleanupFns=[]}initialize(t){return this.markerManager=new N({mapInstance:this.map,mapboxgl:t.mapboxgl,onMarkerClick:t.onMarkerClick}),t.onRefresh&&this.attachEventListeners(t.onRefresh),t.onMapMoveEnd&&this.attachBoundsTracking(t.onMapMoveEnd),this.markerManager}attachBoundsTracking(t){if(!this.map||typeof this.map.on!="function")return;let r=()=>{let i=this.getMapBounds();t(i)},a=()=>{let i=this.getMapBounds();t(i)};this.map.loaded&&this.map.loaded()?a():(this.map.once("load",a),this.cleanupFns.push(()=>{typeof this.map.off=="function"&&this.map.off("load",a)})),this.map.on("moveend",r),this.cleanupFns.push(()=>{typeof this.map.off=="function"&&this.map.off("moveend",r)})}attachEventListeners(t){if(!this.map||typeof this.map.on!="function")return;["move","zoom","dragend","pitch","rotate"].forEach(a=>{this.map.on(a,t),this.cleanupFns.push(()=>{typeof this.map.off=="function"&&this.map.off(a,t)})})}getMarkerManager(){return this.markerManager}getContainer(){var t,r;return((r=(t=this.map)==null?void 0:t.getContainer)==null?void 0:r.call(t))||null}cleanup(){for(let t of this.cleanupFns)try{t()}catch{}this.cleanupFns.length=0}getMap(){return this.map}getCenter(){let t=this.map.getCenter();return{lng:t.lng,lat:t.lat}}getZoom(){return this.map.getZoom()}getBearing(){return this.map.getBearing()}getPitch(){return this.map.getPitch()}getMapBounds(){let t=this.map.getBounds(),r=t.getSouthWest(),a=t.getNorthEast();return{sw:{lat:r.lat,lng:r.lng},ne:{lat:a.lat,lng:a.lng}}}project(t){return this.map.project({lng:t[0],lat:t[1]})}on(t,r){this.map.on(t,r)}off(t,r){this.map.off(t,r)}resize(){this.map.resize()}remove(){this.cleanup(),this.map.remove()}};function ee(n){let e=n.getCenter();return{longitude:e.lng,latitude:e.lat,zoom:n.getZoom(),bearing:n.getBearing(),pitch:n.getPitch()}}var ve=[{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 te(n){for(let e of ve)if(n<=e.zoom)return e.threshold;return 48}function G({primaryType:n,markers:e,map:t,selectedMarkerId:r,zoom:a,collisionThresholdPx:i,dotCollisionThresholdPx:s}){if(!e.length)return[];if(!t)return e.map(d=>({kind:"primary",marker:d,key:`primary-${d.tripadvisor_id}`}));let l=e.map((d,f)=>{let u=d.location;if(typeof(u==null?void 0:u.lon)!="number"||typeof(u==null?void 0:u.lat)!="number")return null;let{x:m,y:k}=t.project([u.lon,u.lat]);return{marker:d,index:f,x:m,y:k}}).filter(d=>!!d);if(!l.length)return[];let o=te(a),p=xe(a),h=l.map((d,f)=>f),g=d=>h[d]===d?d:(h[d]=g(h[d]),h[d]),c=(d,f)=>{let u=g(d),m=g(f);u!==m&&(h[m]=u)};for(let d=0;d<l.length;d+=1)for(let f=d+1;f<l.length;f+=1){let u=l[d].x-l[f].x,m=l[d].y-l[f].y;Math.hypot(u,m)<=o&&c(d,f)}let y=new Map;for(let d of l){let f=g(d.index),u=y.get(f);u?u.push(d):y.set(f,[d])}let M=[];return y.forEach(d=>{var x,L;if(d.length===1){let[{marker:v}]=d,A=v.type===n,I=r===v.tripadvisor_id;M.push({kind:"primary",marker:v,key:`primary-${v.tripadvisor_id}-p${A?1:0}-s${I?1:0}-${(x=v.pricing)==null?void 0:x.availability}`});return}let f=[...d].sort((v,A)=>Le(A.marker,v.marker,n)),[u,...m]=f,k=u.marker.type===n,T=r===u.marker.tripadvisor_id;if(M.push({kind:"primary",marker:u.marker,key:`primary-${u.marker.tripadvisor_id}-p${k?1:0}-s${T?1:0}-${(L=u.marker.pricing)==null?void 0:L.availability}`}),!m.length)return;let b=[],P=[];if(m.forEach(v=>{var A;if(r&&v.marker.tripadvisor_id===r){let I=v.marker.type===n;M.push({kind:"primary",marker:v.marker,key:`primary-${v.marker.tripadvisor_id}-p${I?1:0}-s1-${(A=v.marker.pricing)==null?void 0:A.availability}`});return}Pe(u,v)<=p?b.push(v):P.push(v)}),b.forEach(v=>{var I;let A=v.marker.type===n;M.push({kind:"dot",marker:v.marker,key:`dot-${v.marker.tripadvisor_id}-p${A?1:0}-s0-${(I=v.marker.pricing)==null?void 0:I.availability}`,parentId:u.marker.tripadvisor_id})}),P.length){let v=G({markers:P.map(A=>A.marker),map:t,selectedMarkerId:r,zoom:a,primaryType:n,collisionThresholdPx:i,dotCollisionThresholdPx:s});M.push(...v)}}),M}function Pe(n,e){return Math.hypot(n.x-e.x,n.y-e.y)}function xe(n){let e=te(n);return Math.max(48,e)}function Le(n,e,t){var o,p;let r=n.type===t,a=e.type===t;if(r&&!a)return 1;if(!r&&a)return-1;let i=Y(n)-Y(e);if(i!==0)return i;let s=Q(n)-Q(e);if(s!==0)return s;let l=((o=n.reviews)!=null?o:0)-((p=e.reviews)!=null?p:0);return l!==0?l:n.tripadvisor_id-e.tripadvisor_id}function Y(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 Q(n){var t,r,a;if(!((r=(t=n.pricing)==null?void 0:t.offer)!=null&&r.price))return-1/0;let e=Number(((a=n.pricing.offer.displayPrice)!=null?a:"0").replace(/[^0-9.,-]+/g,"").replace(/,/g,""));return Number.isNaN(e)?-1/0:e}function re(n){let e=[];return n.amenities&&Array.isArray(n.amenities)&&n.amenities.forEach(t=>{e.push({id:`amenity-${t}`,label:t,type:"amenity",value:t})}),n.hotelStyle&&Array.isArray(n.hotelStyle)&&n.hotelStyle.forEach(t=>{e.push({id:`hotelStyle-${t}`,label:t,type:"hotelStyle",value:t})}),n.price&&e.push({id:"priceRange",label:"Price Range",type:"priceRange",value:`${n.price.min}-${n.price.max}`,priceRange:n.price}),typeof n.minRating=="number"&&Number.isFinite(n.minRating)&&e.push({id:"minRating",label:`${n.minRating}+`,type:"minRating",value:String(n.minRating),numericValue:n.minRating}),typeof n.starRating=="number"&&Number.isFinite(n.starRating)&&e.push({id:"starRating",label:`${n.starRating} Stars`,type:"starRating",value:String(n.starRating),numericValue:n.starRating}),n.transformed_query&&e.push({id:"transformed_query",label:n.transformed_query,type:"transformed_query",value:n.transformed_query}),n.selected_restaurant_price_levels&&e.push({id:"selected_restaurant_price_levels",label:n.selected_restaurant_price_levels.join(", "),type:"selected_restaurant_price_levels",value:n.selected_restaurant_price_levels.join(", "),priceLevels:n.selected_restaurant_price_levels}),e}function ae(n){return n.map(e=>{let t={id:e.id,label:typeof e.label=="string"?e.label:String(e.label||""),type:e.type,value:e.value};if(e.numericValue!==void 0&&(t.numericValue=e.numericValue),e.priceRange){let r=e.priceRange.min,a=e.priceRange.max;r!==void 0&&(t.priceRange={min:r,...a!==void 0&&{max:a}})}return e.priceLevels&&(t.priceLevels=e.priceLevels),t})}var Ae={prod:"https://api.mapfirst.ai",test:"https://api.mapfirst.ai/test"},D=class extends Error{constructor({message:e,status:t,code:r}){super(e),this.name="PropertiesFetchError",this.status=t,this.code=r}};async function oe(n,e,t,{signal:r}={}){var i,s;let a=await fetch(n,{method:"POST",headers:{"Content-Type":"application/json",...t&&{"X-API-Key":t}},body:JSON.stringify(e),signal:r});if(!a.ok){let l=`Unexpected response: ${a.status}`,o;try{let p=await a.json();l=(s=(i=p.detail)!=null?i:p.error)!=null?s:l,o=p.code}catch{}throw new D({message:l,status:a.status,code:o})}return await a.json()}function ie(n){return typeof n=="string"?n:n.toISOString().slice(0,10)}var ne="Accommodation";function Ce(){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,s=new Date(r.getTime()+(i+1)*864e5);return{checkIn:r,checkOut:s}}var V=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,s,l,o,p,h,g,c,y,M,d,f,u,m,k;if(this.properties=[...(a=e.properties)!=null?a:[]],this.primaryType=e.primaryType,this.selectedMarkerId=(i=e.selectedMarkerId)!=null?i:null,this.useApi=(s=e.useApi)!=null?s:!0,this.environment=(l=e.environment)!=null?l:"prod",this.apiUrl=(o=e.apiUrl)!=null?o:Ae[this.environment],this.apiKey=e.apiKey,this.requestBody=e.requestBody,this.currentPlatform=e.platform,!this.useApi&&e.platform&&e.platform!=="maplibre")throw new Error("When useApi is false, only maplibre platform is supported. Google Maps and Mapbox require API usage.");let t=se(e);this.fitBoundsPadding={top:(h=(p=e.fitBoundsPadding)==null?void 0:p.top)!=null?h:t?0:50,bottom:(c=(g=e.fitBoundsPadding)==null?void 0:g.bottom)!=null?c:t?0:160,left:(M=(y=e.fitBoundsPadding)==null?void 0:y.left)!=null?M:t?0:50,right:(f=(d=e.fitBoundsPadding)==null?void 0:d.right)!=null?f:t?0:50};let r=Ce();this.state={center:[0,0],zoom:0,bounds:null,pendingBounds:null,tempBounds:null,properties:this.properties,primary:(u=this.primaryType)!=null?u:ne,selectedPropertyId:this.selectedMarkerId,initialLoading:!0,isSearching:!1,firstCallDone:!1,filters:{checkIn:r.checkIn,checkOut:r.checkOut,numAdults:2,numRooms:1,...((m=e.initialLocationData)==null?void 0:m.currency)&&{currency:e.initialLocationData.currency}},activeLocation:{country:"",location_id:null,locationName:"",coordinates:[0,0]},isFlyToAnimating:!1,...e.state},this.callbacks=(k=e.callbacks)!=null?k:{},this.hasMapInstance(e)&&(this.adapter=this.createAdapter(e),this.isMapAttached=!0,this.refresh()),e.initialLocationData?this.initializeFromLocationData(e.initialLocationData):this.requestBody&&this.isMapAttached&&this.autoLoadProperties()}hasMapInstance(e){return!!("adapter"in e&&e.adapter||"mapInstance"in e&&e.mapInstance)}async initializeFromLocationData(e){if(!this.useApi){console.warn("initializeFromLocationData requires API usage. Set useApi to true.");return}try{let{city:t,country:r,query:a}=e,i={filters:this.getFilters(),initial:!0};if(t&&r||r){let s=await fetch(`${this.apiUrl}/geo-lookup?country=${encodeURIComponent(r)}${t?`&city=${encodeURIComponent(t)}`:""}`,{headers:{...this.apiKey&&{"X-API-Key":this.apiKey}}});if(s.ok){let l=await s.json(),o=t;l.location_name&&l.path3_name&&l.location_name===l.path3_name&&(o=void 0),l.location_name&&(o=l.location_name);let p=l.path3_name||r;i={...i,city:o,country:p,location_id:l.location_id,longitude:l.longitude,latitude:l.latitude},this.setActiveLocation({city:o,country:p,location_id:l.location_id,locationName:o&&p?`${o}, ${p}`:p||"",coordinates:[l.latitude,l.longitude]}),this.setState({center:[l.latitude,l.longitude],zoom:12})}else this.handleError(new Error(`Geo mapping fetch failed: ${s.statusText}`),"initializeFromLocationData")}else a&&(i.query=a);this.requestBody=i,this.isMapAttached&&await this.autoLoadProperties()}catch(t){this.handleError(t,"initializeFromLocationData")}}async autoLoadProperties(){if(!this.useApi){console.warn("autoLoadProperties requires API usage. Set useApi to true.");return}if(!this.requestBody)return;let e={filters:this.getFilters(),initial:!0,...this.requestBody};await this.runPropertiesSearch({body:e,onError:t=>{var r,a;this.handleError(t,"autoLoadProperties"),(a=(r=this.callbacks).onPropertiesLoadError)==null||a.call(r,t)}})}attachMap(e,t){if(!this.useApi&&t.platform!=="maplibre")throw new Error("When useApi is false, only maplibre platform is supported. Google Maps and Mapbox require API usage.");if(this.isMapAttached&&(console.warn("Map is already attached. Destroying previous adapter."),this.adapter)){let a=this.adapter.getMarkerManager();a==null||a.destroy(),this.adapter.cleanup()}let r={...this.options,platform:t.platform,mapInstance:e,maplibregl:t.maplibregl,google:t.google,mapboxgl:t.mapboxgl,onMarkerClick:t.onMarkerClick};this.currentPlatform=t.platform,this.adapter=this.createAdapter(r),this.isMapAttached=!0,this.refresh(),this.requestBody&&!this.state.firstCallDone&&this.autoLoadProperties()}createAdapter(e){return Te(e)&&e.mapInstance?this.initializeAdapter(new H(e.mapInstance),{maplibregl:e.maplibregl,onMarkerClick:e.onMarkerClick}):se(e)&&e.mapInstance?this.initializeAdapter(new z(e.mapInstance),{google:e.google,onMarkerClick:e.onMarkerClick}):Ie(e)&&e.mapInstance?this.initializeAdapter(new $(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 s;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),(s=t.onMarkerClick)==null||s.call(t,i)},onRefresh:()=>this.refresh(),onMapMoveEnd:i=>{this.state.tempBounds===null?(this.setTempBounds(i),this.setPendingBounds(null)):this.handleMapMoveEnd(i)}}),this.useApi&&e.setupImpressionTracking(()=>{console.log("ToDo: Track Map Impression")}),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,s,l,o,p,h,g,c,y,M,d,f,u,m;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&&((s=(i=this.callbacks).onZoomChange)==null||s.call(i,e.zoom)),e.bounds!==void 0&&e.bounds!==t.bounds&&((o=(l=this.callbacks).onBoundsChange)==null||o.call(l,e.bounds)),e.pendingBounds!==void 0&&e.pendingBounds!==t.pendingBounds&&((h=(p=this.callbacks).onPendingBoundsChange)==null||h.call(p,e.pendingBounds)),e.filters!==void 0&&e.filters!==t.filters&&((c=(g=this.callbacks).onFiltersChange)==null||c.call(g,e.filters)),e.activeLocation!==void 0&&e.activeLocation!==t.activeLocation&&((M=(y=this.callbacks).onActiveLocationChange)==null||M.call(y,e.activeLocation)),e.initialLoading!==void 0&&e.initialLoading!==t.initialLoading&&((f=(d=this.callbacks).onLoadingStateChange)==null||f.call(d,e.initialLoading)),e.isSearching!==void 0&&e.isSearching!==t.isSearching&&((m=(u=this.callbacks).onSearchingStateChange)==null||m.call(u,e.isSearching))}setFilters(e){this.setState({filters:e})}setActiveLocation(e){this.setState({activeLocation:e})}setBounds(e){this.setState({bounds:e})}setPendingBounds(e){this.setState({pendingBounds:e})}setTempBounds(e){this.setState({tempBounds:e})}setLoading(e){this.setState({initialLoading:e})}setSearching(e){this.setState({isSearching:e})}setFlyToAnimating(e){this.setState({isFlyToAnimating:e})}handleMapMoveEnd(e){if(this.state.isFlyToAnimating){this.setState({isFlyToAnimating:!1,tempBounds:e,pendingBounds:null});return}let t=this.state.tempBounds;if(!t){this.setState({tempBounds:e,pendingBounds:e});return}let r=.01;Math.abs(e.sw.lat-t.sw.lat)>r||Math.abs(e.sw.lng-t.sw.lng)>r||Math.abs(e.ne.lat-t.ne.lat)>r||Math.abs(e.ne.lng-t.ne.lng)>r?this.setState({pendingBounds:e}):this.setState({pendingBounds:null})}flyMapTo(e,t,r,a=!0){if(this.ensureAlive(),this.setState({center:[t,e]}),typeof r=="number"&&this.setState({zoom:r}),!this.adapter)return;let i=this.adapter.getMap();if(i){if(this.currentPlatform==="google"){this.setFlyToAnimating(!1),i.setCenter({lat:t,lng:e}),r!==null&&typeof r=="number"&&i.setZoom(r!=null?r:13);return}if(a===!1){this.setFlyToAnimating(!1),i.jumpTo&&i.jumpTo({center:[e,t],...r!==null&&{zoom:r!=null?r:13}});return}this.setFlyToAnimating(!0),i.flyTo&&i.flyTo({center:[e,t],...r!==null&&{zoom:r!=null?r:13}})}}flyToPOIs(e,t,r=!0){var s,l;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(o=>o.location!==void 0&&(t!==void 0?o.type===t:!0)).map(o=>({lat:o.location.lat,lng:o.location.lon}))),!(!i||i.length===0)){if(i.length===1){let o=i[0];this.currentPlatform==="google"?(a.setCenter({lat:o.lat,lng:o.lng}),a.setZoom(13)):a.flyTo&&a.flyTo({center:[o.lng,o.lat],zoom:13})}else if(this.currentPlatform==="google"){let o=(l=(s=window.google)==null?void 0:s.maps)==null?void 0:l.LatLngBounds;if(o){let p=new o;i.forEach(h=>{p.extend({lat:h.lat,lng:h.lng})}),r&&this.setFlyToAnimating(!0),a.fitBounds(p,this.fitBoundsPadding)}}else if(a.fitBounds){let o=[[i[0].lng,i[0].lat],[i[0].lng,i[0].lat]];i.forEach(p=>{o[0][0]=Math.min(o[0][0],p.lng),o[0][1]=Math.min(o[0][1],p.lat),o[1][0]=Math.max(o[1][0],p.lng),o[1][1]=Math.max(o[1][1],p.lat)}),r&&this.setFlyToAnimating(!0),a.fitBounds(o,{padding:this.fitBoundsPadding,animate:r})}}}getFilters(){let e={...this.state.filters};return e.checkIn instanceof Date&&(e.checkIn=ie(e.checkIn)),e.checkOut instanceof Date&&(e.checkOut=ie(e.checkOut)),e}async pollForPricing({pollingLink:e,maxAttempts:t=15,delayMs:r=2e3,isCancelled:a,price:i,limit:s}){var g,c,y,M,d;if(this.ensureAlive(),!this.useApi)return console.warn("pollForPricing requires API usage. Set useApi to true."),{completed:!1};if(!e)return{completed:!1};let l=!1,o,p=this.getFilters();s&&(p.limit=s);let h={filters:p,pollingLink:e};for(let f=0;f<t;f++){if(a!=null&&a())return{completed:l,pollData:o};try{let u=await fetch(`${this.apiUrl}/ta-polling?pollingNumber=${f}`,{method:"POST",body:JSON.stringify(h),headers:{"Content-Type":"application/json",...this.apiKey&&{"X-API-Key":this.apiKey}}});if(!u.ok)throw new D({message:`Poll failed: ${u.status}`,status:u.status});if(o=await u.json(),a!=null&&a())return{completed:l,pollData:o};let m=(c=(g=o==null?void 0:o.success)==null?void 0:g.results)!=null?c:[];if(m.length>0&&this.setProperties(k=>{let T=new Set(m.map(P=>P.tripadvisor_id)),b=k.filter(P=>P.type!=="Accommodation"||T.has(P.tripadvisor_id));return m.forEach(P=>{var L,v,A,I,_,B;if(!P.location)return;(v=(L=P.pricing)==null?void 0:L.offer)!=null&&v.price&&i&&(((I=(A=P.pricing)==null?void 0:A.offer)==null?void 0:I.price)<(i==null?void 0:i.min)||((B=(_=P.pricing)==null?void 0:_.offer)==null?void 0:B.price)>(i==null?void 0:i.max))&&(P.pricing.availability="unavailable");let x=b.findIndex(C=>C.tripadvisor_id===P.tripadvisor_id);x>=0?b[x]=P:b.push(P)}),b}),(y=o==null?void 0:o.success)!=null&&y.isComplete){l=!0;break}}catch(u){this.handleError(u,"pollForPricing"),(d=(M=this.callbacks).onPropertiesLoadError)==null||d.call(M,u);break}f<t-1&&await new Promise(u=>setTimeout(u,r))}return{completed:l,pollData:o}}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,s,l,o,p,h,g;if(this.ensureAlive(),!this.useApi)return console.warn("runPropertiesSearch requires API usage. Set useApi to true."),a==null||a(new Error("API usage is disabled")),null;this.setState({firstCallDone:!1}),this.setSearching(!0),this.clearProperties();try{let c=await oe(`${this.apiUrl}/properties`,e,this.apiKey);this.updateActiveLocationFromResponse(c);let y=null,M=30,d=c.filters.primary_type;if(t){let m=t(c);y=(i=m.price)!=null?i:null,M=(s=m.limit)!=null?s:30}let f=c.properties.some(m=>!!m.location),u=y?c.properties.map(m=>{var k;return(k=m.pricing)!=null&&k.offer?{...m,pricing:{...m.pricing,availability:m.pricing.offer.price&&(m.pricing.offer.price<y.min||m.pricing.offer.price>y.max)?"unavailable":m.pricing.availability}}:m}):c.properties;if(this._setProperties(u),f&&this.flyToPOIs(c.properties.filter(m=>!!m.location&&(c.filters.primary_type?m.type===c.filters.primary_type:!0)).map(m=>({lat:m.location.lat,lng:m.location.lon})),void 0,e.initial!==!0),c.filters.primary_type&&c.properties.filter(m=>{var k;return m.type===c.filters.primary_type&&(m.type==="Accommodation"?((k=m.pricing)==null?void 0:k.availability)!=="unavailable":!0)}).length>0)d=c.filters.primary_type,this.setPrimaryType(c.filters.primary_type);else if(c.properties.length>0){let m=this.mostCommonTypeFromProperties(c.properties);this.setPrimaryType(m),d=m}if(this.setState({firstCallDone:!0}),c.isComplete===!1&&c.pollingLink){let{completed:m,pollData:k}=await this.pollForPricing({pollingLink:c.pollingLink,...y&&{price:y},...M&&{limit:M}});if(m&&((l=k==null?void 0:k.success)!=null&&l.results)&&k.success.results.filter(T=>{var b;return T.type===c.filters.primary_type&&(T.type==="Accommodation"?((b=T.pricing)==null?void 0:b.availability)!=="unavailable":!0)}).length===0&&d&&d!==c.filters.primary_type){let T=this.mostCommonTypeFromProperties(c.properties);this.setPrimaryType(T)}}return f||(c.properties.some(m=>!!m.location)?this.flyToPOIs(c.properties.filter(m=>!!m.location&&(c.filters.primary_type?m.type===c.filters.primary_type:!0)).map(m=>({lat:m.location.lat,lng:m.location.lon})),void 0,e.initial!==!0):(o=c.filters.location)!=null&&o.latitude&&((p=c.filters.location)!=null&&p.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),(g=(h=this.callbacks).onPropertiesLoadError)==null||g.call(h,c),this.clearProperties(),this.setState({firstCallDone:!0}),null}finally{this.setSearching(!1),this.setState({firstCallDone:!0})}}async performBoundsSearch(){var i;if(this.ensureAlive(),!this.useApi)return console.warn("performBoundsSearch requires API usage. Set useApi to true."),null;if(!this.state.pendingBounds)return null;let e=this.getFilters(),t={bounds:this.state.pendingBounds,filters:e},r=(i=e==null?void 0:e.price)!=null?i:void 0,a=await this.runPropertiesSearch({body:t,beforeApplyProperties:()=>({price:r!=null?r:null})});return a&&(this.setBounds(this.state.pendingBounds),this.setTempBounds(this.state.pendingBounds),this.setPendingBounds(null)),a}updateActiveLocationFromResponse(e){var l,o,p,h;let t=(l=e.location_id)!=null?l:null,r=(p=(o=e.filters.location)==null?void 0:o.city)!=null?p:void 0,a=((h=e.filters.location)==null?void 0:h.country)||"",i=e.filters.location?[e.filters.location.latitude,e.filters.location.longitude]:void 0;if(!i)return;let s=this.state.activeLocation;(t!==(s==null?void 0:s.location_id)||r!==(s==null?void 0:s.city)||a!==(s==null?void 0:s.country))&&this.setActiveLocation({city:r,country:a,location_id:t,locationName:r&&a?`${r}, ${a}`:a||"",coordinates:i})}async runSmartFilterSearch({query:e,filters:t,onProcessFilters:r,onError:a}){if(this.ensureAlive(),!this.useApi)return console.warn("runSmartFilterSearch requires API usage. Set useApi to true."),a==null||a(new Error("API usage is disabled")),null;let i=this.getFilters(),s=this.getState();if(t&&t.length>0){let o=new Set,p=new Set,h,g,c,y,M,d;t.forEach(f=>{var u,m,k;switch(f.type){case"amenity":o.add(f.value);break;case"hotelStyle":p.add(f.value);break;case"priceRange":f.priceRange&&(h={min:f.priceRange.min,max:(u=f.priceRange.max)!=null?u:0});break;case"minRating":g=(m=f.numericValue)!=null?m:Number(f.value);break;case"starRating":c=(k=f.numericValue)!=null?k:Number(f.value);break;case"primary_type":y=f.propertyType;break;case"transformed_query":M=f.value;break;case"selected_restaurant_price_levels":d=f.priceLevels;break}}),i={...i,...o.size>0&&{amenities:Array.from(o)},...p.size>0&&{hotelStyle:Array.from(p)},...h&&{price:h},...g!==void 0&&{minRating:g},...c!==void 0&&{starRating:c},...y&&{primary_type:y},...M&&{transformed_query:M},...d&&{selected_restaurant_price_levels:d}}}else e||(i.minRating=4);let l={filters:i,...e&&{query:e},...s.bounds?{bounds:s.bounds}:s.activeLocation.location_id?{location_id:s.activeLocation.location_id}:s.activeLocation.coordinates?{latitude:s.activeLocation.coordinates[0],longitude:s.activeLocation.coordinates[1]}:{}};return this.runPropertiesSearch({body:l,beforeApplyProperties:r?o=>{var h,g;let p=r(o.filters,o.location_id);return{price:(h=p.price)!=null?h:null,limit:(g=p.limit)!=null?g:30}}:void 0,smartFiltersClearable:!!e,onError:a})}getClusters(){return this.ensureAlive(),[...this.clusterItems]}setUseApi(e,t=!0){this.ensureAlive(),this.useApi=e,!e&&this.currentPlatform&&this.currentPlatform!=="maplibre"&&console.warn("When useApi is false, only maplibre platform is supported. Please switch to maplibre."),e||this.clearProperties(),e&&t&&(this.options.initialLocationData?this.initializeFromLocationData(this.options.initialLocationData):this.requestBody&&this.isMapAttached&&this.autoLoadProperties())}setApiKey(e){this.ensureAlive();let t=this.apiKey;this.apiKey=e,t!==this.apiKey&&this.isMapAttached&&(this.refresh(),this.useApi&&(this.options.initialLocationData?this.initializeFromLocationData(this.options.initialLocationData):this.requestBody&&this.autoLoadProperties()))}getApiKey(){return this.apiKey}refresh(){var a,i,s;if(this.ensureAlive(),!this.adapter)return;let e=this.safeExtractViewState(),t=this.resolvePrimaryType();this.clusterItems=G({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),(s=(i=this.options).onClusterUpdate)==null||s.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:ne}safeExtractViewState(){if(!this.adapter)return null;try{return ee(this.adapter)}catch{return null}}ensureAlive(){if(this.destroyed)throw new Error("MapFirstCore instance has been destroyed")}};function Te(n){return n.platform==="maplibre"}function se(n){return n.platform==="google"}function Ie(n){return n.platform==="mapbox"}0&&(module.exports={MapFirstCore,PropertiesFetchError,convertToApiFilters,fetchProperties,processApiFilters});
|
|
32
|
+
`,t}function ve(i,e){let t=i.querySelector(".mapfirst-property-hover-image");if(t&&e.tripadvisor_id&&!t.dataset.imageLoaded){t.dataset.imageLoaded="loading";let a=t.dataset.defaultImage;z(e.tripadvisor_id,1).then(r=>{if(r&&t){let n=document.createElement("img");n.src=r,n.alt=e.name,n.style.width="100%",n.style.height="100%",n.style.objectFit="cover",t.innerHTML="",t.appendChild(n),t.classList.remove("mapfirst-property-hover-image-placeholder"),t.dataset.imageLoaded="true"}else throw new Error("No image URL")}).catch(()=>{if(a&&t){let r=document.createElement("img");r.src=a,r.alt=e.name,r.style.width="100%",r.style.height="100%",r.style.objectFit="cover",t.innerHTML="",t.appendChild(r),t.classList.remove("mapfirst-property-hover-image-placeholder"),t.dataset.imageLoaded="false"}})}}function Z(i,e,t){let a=e.getBoundingClientRect(),r=t.getBoundingClientRect(),n=270,s=120,o=12,l=r.right-a.right,u=a.left-r.left,y=r.bottom-a.bottom,M=a.top-r.top,c=a.left-r.left+a.width/2-n/2,p=a.top-r.top+a.height+o;c<0?c=8:c+n>r.width&&(c=r.width-n-8),y<s+o&&M>y&&(p=a.top-r.top-s-o),i.style.left=`${c}px`,i.style.top=`${p}px`}function W(i,e,t,a){var d,g,f,m,h,P,T,x,C;if(typeof document=="undefined")return null;let r=i.marker,n=r.type===e,s=t===r.tripadvisor_id,o=r.type==="Accommodation",l=(g=(d=r.pricing)==null?void 0:d.offer)==null?void 0:g.displayPrice,u=o&&!l,y=(()=>{if(r.rating===void 0||r.rating===null)return null;let L=typeof r.rating=="number"?r.rating:Number(r.rating);return Number.isNaN(L)||L<=0?null:L.toFixed(1)})(),M=document.createElement("div");M.className="mapfirst-marker-root",M.style.zIndex=s?"20":n?"12":"11";let c=(h=(m=(f=r.pricing)==null?void 0:f.offer)==null?void 0:m.clickUrl)!=null?h:r.url,p=document.createElement(c?"a":"div");if(c&&(p.href=c,p.target="_blank",p.style.textDecoration="none"),p.className=u?"mapfirst-marker-pill mapfirst-marker-pill-pending":`mapfirst-marker-pill mapfirst-marker-pill-active${s?" mapfirst-marker-selected":n?"":" mapfirst-marker-non-primary"}`,!u&&((P=r.awards)!=null&&P.length||y)){let L=document.createElement("div");if(L.className="mapfirst-marker-badge",n||(L.style.opacity="0.2"),L.className="mapfirst-marker-badge",(T=r.awards)!=null&&T.length&&r.awards[0].type){let k=document.createElement("div");k.className="mapfirst-marker-award-container";let v=document.createElement("div");v.className="mapfirst-marker-award-back",v.innerHTML=he;let A=document.createElement("div");A.className=`mapfirst-marker-award-dot mapfirst-marker-award-dot-type-${r.awards[0].type}`;let w=document.createElement("div");w.className="mapfirst-marker-award-front",w.innerHTML=fe,k.appendChild(v),k.appendChild(A),k.appendChild(w),L.appendChild(k)}else y&&(L.className="mapfirst-marker-badge mapfirst-marker-rating-badge",L.textContent=y);p.appendChild(L)}let b=document.createElement("span");return b.className="mapfirst-marker-content",o?(C=(x=r.pricing)==null?void 0:x.offer)!=null&&C.displayPrice?(b.innerHTML=r.pricing.offer.displayPrice,b.dataset.price=r.pricing.offer.displayPrice):(b.innerHTML=be,b.dataset.price=""):r.type==="Eat & Drink"?b.innerHTML=ge:r.type==="Attraction"&&(b.innerHTML=ye),p.appendChild(b),p.addEventListener("click",L=>{L.stopPropagation(),u||a==null||a(r)}),u||$(M,p,r,s),M.appendChild(p),M}var Pe='<video class="mapfirst-marker-loading-video" src="https://api.mapfirst.ai/static/images/loading.webm" autoplay loop muted></video>';function q(i,e,t,a,r){var u,y,M,c,p,b,d,g,f,m;let n=(y=(u=i.querySelector(".mapfirst-marker-pill"))==null?void 0:u.classList.contains("mapfirst-marker-pill-pending"))!=null?y:!1,s=i;s.style.zIndex=t?"20":e?"12":"11";let o=s.querySelector(".mapfirst-marker-pill");o&&(a?o.className="mapfirst-marker-pill mapfirst-marker-pill-pending":o.className=`mapfirst-marker-pill mapfirst-marker-pill-active${t?" mapfirst-marker-selected":e?"":" mapfirst-marker-non-primary"}`);let l=s.querySelector(".mapfirst-marker-badge");if(l instanceof HTMLElement&&(l.style.opacity=!e&&!t?"0.2":""),n&&!a&&r){let h=s.querySelector(".mapfirst-marker-pill");h instanceof HTMLElement&&$(s,h,r,t)}if(r&&r.type==="Accommodation"){let h=s.querySelector(".mapfirst-marker-content");if(h instanceof HTMLElement){let P=(c=(M=r.pricing)==null?void 0:M.offer)==null?void 0:c.displayPrice;h.dataset.price!==P&&(P?(h.innerHTML=P,h.dataset.price=P):(h.innerHTML=Pe,h.dataset.price=""))}}if(r){let h=document.querySelector(`.mapfirst-property-hover-card[data-marker-id="${r.tripadvisor_id}"]`);if(h){let P=r.rating||0,T=r.reviews||0,x=(d=(b=(p=r.pricing)==null?void 0:p.offer)==null?void 0:b.displayPrice)!=null?d:r.price_level,C=h.querySelector(".rating-value");if(C){let v=P.toFixed(1);C.textContent!==v&&(C.textContent=v)}let L=h.querySelector(".reviews");if(L){let v=`(${T})`;L.textContent!==v&&(L.textContent=v)}if(r.type==="Accommodation"&&x){let v=h.querySelector(".mapfirst-property-hover-price");if(!v){v=document.createElement("div"),v.className="mapfirst-property-hover-price";let A=h.querySelector(".mapfirst-property-hover-details"),w=h.querySelector(".mapfirst-property-hover-learn-more");A&&(w?A.insertBefore(v,w):A.appendChild(v))}if(v){let A=`Starting at <strong>${x}</strong>`;v.innerHTML!==A&&(v.innerHTML=A)}}let k=(m=(f=(g=r.pricing)==null?void 0:g.offer)==null?void 0:f.clickUrl)!=null?m:r.url;k&&h instanceof HTMLAnchorElement&&h.href!==k&&(h.href=k)}}}function j(i,e,t,a){let r=i;r.style.zIndex=t?"20":e?"3":"1";let n=r.querySelector(".mapfirst-dot-marker-button");n&&(a?n.className="mapfirst-dot-marker-button mapfirst-dot-marker-button-pending":n.className=`mapfirst-dot-marker-button mapfirst-dot-marker-button-active${t?" mapfirst-dot-marker-selected":e?"":" mapfirst-dot-marker-non-primary"}`)}function X(i){let e=i.match(/^(?:primary|dot)-(\d+)-/);return e?parseInt(e[1],10):null}var I=class{constructor(e,t){this.markerCache=new Map;this.primaryType="Accommodation";this.selectedMarkerId=null;this.mapInstance=e,this.onMarkerClick=t}render(e,t,a){var n,s,o,l,u,y,M,c;t&&t!==this.primaryType&&(this.primaryType=t),a!==void 0&&(this.selectedMarkerId=a);let r=new Set(e.map(p=>p.key));for(let[p,b]of this.markerCache.entries())r.has(p)||(this.removeMarkerFromMap(b.marker),this.markerCache.delete(p));for(let p of e){let b=xe(p.marker.location);if(!b)continue;let d=this.markerCache.get(p.key);if(d){let g=p.marker.type===this.primaryType,f=this.selectedMarkerId===p.marker.tripadvisor_id,m=p.marker.type==="Accommodation",h=p.kind==="primary"?m&&!((s=(n=p.marker.pricing)==null?void 0:n.offer)!=null&&s.displayPrice):m&&((l=(o=p.marker.pricing)==null?void 0:o.offer)==null?void 0:l.availability)!=="available",P=this.getMarkerElement(d.marker);P&&(p.kind==="primary"?q(P,g,f,h,p.marker):j(P,g,f,h));try{this.updateMarkerPosition(d.marker,b)}catch{this.removeMarkerFromMap(d.marker),this.markerCache.delete(p.key),this.createAndAddMarker(p,b)}}else{let g=p.marker.tripadvisor_id,f,m;for(let[h,P]of this.markerCache.entries())if(X(h)===g&&P.kind===p.kind){f=P,m=h;break}if(f&&m){let h=p.marker.type===this.primaryType,P=this.selectedMarkerId===p.marker.tripadvisor_id,T=p.marker.type==="Accommodation",x=p.kind==="primary"?T&&!((y=(u=p.marker.pricing)==null?void 0:u.offer)!=null&&y.displayPrice):T&&((c=(M=p.marker.pricing)==null?void 0:M.offer)==null?void 0:c.availability)!=="available",C=this.getMarkerElement(f.marker);C&&(p.kind==="primary"?q(C,h,P,x,p.marker):j(C,h,P,x)),this.updateMarkerZIndex(f.marker,p,h,P),this.markerCache.delete(m),this.markerCache.set(p.key,f);try{this.updateMarkerPosition(f.marker,b)}catch{}}else this.createAndAddMarker(p,b)}}}destroy(){for(let e of this.markerCache.values())this.removeMarkerFromMap(e.marker);this.markerCache.clear()}createAndAddMarker(e,t){let a=e.kind==="primary"?W(e,this.primaryType,this.selectedMarkerId,this.onMarkerClick):K(e,this.primaryType,this.selectedMarkerId,this.onMarkerClick);if(!a)return;let r=e.marker.type===this.primaryType,n=this.selectedMarkerId===e.marker.tripadvisor_id;try{let s=this.createMarker(a,t,e,r,n);s&&this.markerCache.set(e.key,{key:e.key,marker:s,kind:e.kind,parentId:e.kind==="dot"?e.parentId:void 0})}catch(s){console.error("Error creating marker",s)}}updateMarkerZIndex(e,t,a,r){}};function xe(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 S=class extends I{constructor(e){var t;super(e.mapInstance,e.onMarkerClick),this.MarkerCtor=(t=e.maplibregl)==null?void 0:t.Marker}render(e,t,a){this.MarkerCtor&&super.render(e,t,a)}createMarker(e,t,a){return this.MarkerCtor?new this.MarkerCtor({element:e,anchor:a.kind==="primary"?"bottom":"center"}).setLngLat([t.lon,t.lat]).addTo(this.mapInstance):null}removeMarkerFromMap(e){try{e.remove()}catch{}}updateMarkerPosition(e,t){e.setLngLat([t.lon,t.lat])}getMarkerElement(e){return e.getElement()}};var B=class extends I{constructor(e){super(e.mapInstance,e.onMarkerClick),this.google=e.google}render(e,t,a){var r,n;if(!((n=(r=this.google)==null?void 0:r.marker)!=null&&n.AdvancedMarkerElement)){console.warn("AdvancedMarkerElement not available");return}super.render(e,t,a)}createMarker(e,t,a,r,n){var o,l;if(!((l=(o=this.google)==null?void 0:o.marker)!=null&&l.AdvancedMarkerElement))return null;let s=a.kind==="primary"?n?20:r?12:11:n?20:r?3:1;return new this.google.marker.AdvancedMarkerElement({map:this.mapInstance,position:{lat:t.lat,lng:t.lon},content:e,zIndex:s})}removeMarkerFromMap(e){try{e.map=null}catch(t){console.error("Error removing marker",t)}}updateMarkerPosition(e,t){e.position={lat:t.lat,lng:t.lon}}getMarkerElement(e){let t=e.content;return t instanceof HTMLElement?t:null}updateMarkerZIndex(e,t,a,r){let n=t.kind==="primary"?r?20:a?12:11:r?20:a?3:1;e.zIndex=n}};var _=class extends I{constructor(e){var t;super(e.mapInstance,e.onMarkerClick),this.MarkerCtor=(t=e.mapboxgl)==null?void 0:t.Marker}render(e,t,a){this.MarkerCtor&&super.render(e,t,a)}createMarker(e,t,a){return this.MarkerCtor?new this.MarkerCtor({element:e,anchor:a.kind==="primary"?"bottom":"center"}).setLngLat([t.lon,t.lat]).addTo(this.mapInstance):null}removeMarkerFromMap(e){try{e.remove()}catch{}}updateMarkerPosition(e,t){e.setLngLat([t.lon,t.lat])}getMarkerElement(e){return e.getElement()}};var E=class{constructor(e){this.map=e}getMap(){return this.map}setupImpressionTracking(e){if(typeof window=="undefined"||!window.IntersectionObserver)return;let t=this.getContainer();if(!t)return;let a=new IntersectionObserver(s=>{s.forEach(o=>{o.isIntersecting&&(e(),a.disconnect())})},{threshold:.1});a.observe(t);let r=()=>a.disconnect(),n=this.cleanup.bind(this);this.cleanup=()=>{r(),n()}}};var F=class extends E{constructor(t){super(t);this.cleanupFns=[]}initialize(t){return this.markerManager=new S({mapInstance:this.map,maplibregl:t.maplibregl,onMarkerClick:t.onMarkerClick}),t.onRefresh&&this.attachEventListeners(t.onRefresh),t.onMapMoveEnd&&this.attachBoundsTracking(t.onMapMoveEnd),this.markerManager}attachBoundsTracking(t){if(!this.map||typeof this.map.on!="function")return;let a=()=>{let n=this.getMapBounds();t(n)},r=()=>{let n=this.getMapBounds();t(n)};this.map.loaded&&this.map.loaded()?r():(this.map.once("load",r),this.cleanupFns.push(()=>{typeof this.map.off=="function"&&this.map.off("load",r)})),this.map.on("moveend",a),this.cleanupFns.push(()=>{typeof this.map.off=="function"&&this.map.off("moveend",a)})}attachEventListeners(t){if(!this.map||typeof this.map.on!="function")return;["move","zoom","dragend","pitch","rotate"].forEach(r=>{this.map.on(r,t),this.cleanupFns.push(()=>{typeof this.map.off=="function"&&this.map.off(r,t)})})}getMarkerManager(){return this.markerManager}getContainer(){var t,a;return((a=(t=this.map)==null?void 0:t.getContainer)==null?void 0:a.call(t))||null}cleanup(){for(let t of this.cleanupFns)try{t()}catch{}this.cleanupFns.length=0}getMap(){return this.map}getCenter(){let t=this.map.getCenter();return{lng:t.lng,lat:t.lat}}getZoom(){return this.map.getZoom()}getBearing(){return this.map.getBearing()}getPitch(){return this.map.getPitch()}getMapBounds(){let t=this.map.getBounds(),a=t.getSouthWest(),r=t.getNorthEast();return{sw:{lat:a.lat,lng:a.lng},ne:{lat:r.lat,lng:r.lng}}}project(t){return this.map.project({lng:t[0],lat:t[1]})}on(t,a){this.map.on(t,a)}off(t,a){this.map.off(t,a)}resize(){this.map.resize()}remove(){this.cleanup(),this.map.remove()}};var H=class extends E{constructor(t){super(t);this.cleanupFns=[];this.initializeOverlayView()}initialize(t){return this.markerManager=new B({mapInstance:this.map,google:t.google,onMarkerClick:t.onMarkerClick}),t.onRefresh&&this.attachEventListeners(t.onRefresh),t.onMapMoveEnd&&this.attachBoundsTracking(t.onMapMoveEnd,t.google),this.markerManager}attachBoundsTracking(t,a){if(!this.map)return;let r=()=>{let s=this.getMapBounds();t(s)};r();let n=a.event.addListener(this.map,"idle",r);this.cleanupFns.push(()=>{a.event.removeListener(n)})}attachEventListeners(t){let a=["center_changed","zoom_changed","drag","heading_changed","tilt_changed"],r=[];a.forEach(n=>{let s=this.map.addListener(n,t);r.push(s)}),this.cleanupFns.push(()=>{r.forEach(n=>{try{n.remove()}catch{}})})}getMarkerManager(){return this.markerManager}getContainer(){var t,a;return((a=(t=this.map)==null?void 0:t.getDiv)==null?void 0:a.call(t))||null}cleanup(){for(let t of this.cleanupFns)try{t()}catch{}this.cleanupFns.length=0}initializeOverlayView(){var r;let t=(r=globalThis.google)==null?void 0:r.maps;if(!t)return;let a=t.OverlayView;a&&(this.overlayView=new a,this.overlayView.draw=function(){},this.overlayView.setMap(this.map))}getMap(){return this.map}getCenter(){let t=this.map.getCenter();return t?{lng:t.lng(),lat:t.lat()}:{lng:0,lat:0}}getZoom(){var t;return(t=this.map.getZoom())!=null?t:0}getBearing(){var t;return(t=this.map.getHeading())!=null?t:0}getPitch(){var t;return(t=this.map.getTilt())!=null?t:0}getMapBounds(){let t=this.map.getBounds();if(!t)return{sw:{lat:0,lng:0},ne:{lat:0,lng:0}};let a=t.getSouthWest(),r=t.getNorthEast();return{sw:{lat:a.lat(),lng:a.lng()},ne:{lat:r.lat(),lng:r.lng()}}}project(t){var o;if(!this.overlayView)return{x:0,y:0};let a=this.overlayView.getProjection();if(!a)return{x:0,y:0};let r=(o=globalThis.google)==null?void 0:o.maps;if(!r)return{x:0,y:0};let n=new r.LatLng(t[1],t[0]),s=a.fromLatLngToContainerPixel(n);return s?{x:s.x,y:s.y}:{x:0,y:0}}on(t,a){this.map.addListener(t,a)}off(t,a){var n;let r=(n=globalThis.google)==null?void 0:n.maps;r!=null&&r.event&&r.event.clearListeners(this.map,t)}resize(){var a;let t=(a=globalThis.google)==null?void 0:a.maps;t!=null&&t.event&&t.event.trigger(this.map,"resize")}remove(){this.cleanup(),this.overlayView&&(this.overlayView.setMap(null),this.overlayView=null)}};var D=class extends E{constructor(t){super(t);this.cleanupFns=[]}initialize(t){return this.markerManager=new _({mapInstance:this.map,mapboxgl:t.mapboxgl,onMarkerClick:t.onMarkerClick}),t.onRefresh&&this.attachEventListeners(t.onRefresh),t.onMapMoveEnd&&this.attachBoundsTracking(t.onMapMoveEnd),this.markerManager}attachBoundsTracking(t){if(!this.map||typeof this.map.on!="function")return;let a=()=>{let n=this.getMapBounds();t(n)},r=()=>{let n=this.getMapBounds();t(n)};this.map.loaded&&this.map.loaded()?r():(this.map.once("load",r),this.cleanupFns.push(()=>{typeof this.map.off=="function"&&this.map.off("load",r)})),this.map.on("moveend",a),this.cleanupFns.push(()=>{typeof this.map.off=="function"&&this.map.off("moveend",a)})}attachEventListeners(t){if(!this.map||typeof this.map.on!="function")return;["move","zoom","dragend","pitch","rotate"].forEach(r=>{this.map.on(r,t),this.cleanupFns.push(()=>{typeof this.map.off=="function"&&this.map.off(r,t)})})}getMarkerManager(){return this.markerManager}getContainer(){var t,a;return((a=(t=this.map)==null?void 0:t.getContainer)==null?void 0:a.call(t))||null}cleanup(){for(let t of this.cleanupFns)try{t()}catch{}this.cleanupFns.length=0}getMap(){return this.map}getCenter(){let t=this.map.getCenter();return{lng:t.lng,lat:t.lat}}getZoom(){return this.map.getZoom()}getBearing(){return this.map.getBearing()}getPitch(){return this.map.getPitch()}getMapBounds(){let t=this.map.getBounds(),a=t.getSouthWest(),r=t.getNorthEast();return{sw:{lat:a.lat,lng:a.lng},ne:{lat:r.lat,lng:r.lng}}}project(t){return this.map.project({lng:t[0],lat:t[1]})}on(t,a){this.map.on(t,a)}off(t,a){this.map.off(t,a)}resize(){this.map.resize()}remove(){this.cleanup(),this.map.remove()}};function Q(i){let e=i.getCenter();return{longitude:e.lng,latitude:e.lat,zoom:i.getZoom(),bearing:i.getBearing(),pitch:i.getPitch()}}var Le=[{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 ee(i){for(let e of Le)if(i<=e.zoom)return e.threshold;return 48}function G({primaryType:i,markers:e,map:t,selectedMarkerId:a,zoom:r,collisionThresholdPx:n,dotCollisionThresholdPx:s}){if(!e.length)return[];if(!t)return e.map(d=>({kind:"primary",marker:d,key:`primary-${d.tripadvisor_id}`}));let o=e.map((d,g)=>{let f=d.location;if(typeof(f==null?void 0:f.lon)!="number"||typeof(f==null?void 0:f.lat)!="number")return null;let{x:m,y:h}=t.project([f.lon,f.lat]);return{marker:d,index:g,x:m,y:h}}).filter(d=>!!d);if(!o.length)return[];let l=ee(r),u=Ae(r),y=o.map((d,g)=>g),M=d=>y[d]===d?d:(y[d]=M(y[d]),y[d]),c=(d,g)=>{let f=M(d),m=M(g);f!==m&&(y[m]=f)};for(let d=0;d<o.length;d+=1)for(let g=d+1;g<o.length;g+=1){let f=o[d].x-o[g].x,m=o[d].y-o[g].y;Math.hypot(f,m)<=l&&c(d,g)}let p=new Map;for(let d of o){let g=M(d.index),f=p.get(g);f?f.push(d):p.set(g,[d])}let b=[];return p.forEach(d=>{var C,L;if(d.length===1){let[{marker:k}]=d,v=k.type===i,A=a===k.tripadvisor_id;b.push({kind:"primary",marker:k,key:`primary-${k.tripadvisor_id}-p${v?1:0}-s${A?1:0}-${(C=k.pricing)==null?void 0:C.availability}`});return}let g=[...d].sort((k,v)=>Ce(v.marker,k.marker,i)),[f,...m]=g,h=f.marker.type===i,P=a===f.marker.tripadvisor_id;if(b.push({kind:"primary",marker:f.marker,key:`primary-${f.marker.tripadvisor_id}-p${h?1:0}-s${P?1:0}-${(L=f.marker.pricing)==null?void 0:L.availability}`}),!m.length)return;let T=[],x=[];if(m.forEach(k=>{var v;if(a&&k.marker.tripadvisor_id===a){let A=k.marker.type===i;b.push({kind:"primary",marker:k.marker,key:`primary-${k.marker.tripadvisor_id}-p${A?1:0}-s1-${(v=k.marker.pricing)==null?void 0:v.availability}`});return}Te(f,k)<=u?T.push(k):x.push(k)}),T.forEach(k=>{var A;let v=k.marker.type===i;b.push({kind:"dot",marker:k.marker,key:`dot-${k.marker.tripadvisor_id}-p${v?1:0}-s0-${(A=k.marker.pricing)==null?void 0:A.availability}`,parentId:f.marker.tripadvisor_id})}),x.length){let k=G({markers:x.map(v=>v.marker),map:t,selectedMarkerId:a,zoom:r,primaryType:i,collisionThresholdPx:n,dotCollisionThresholdPx:s});b.push(...k)}}),b}function Te(i,e){return Math.hypot(i.x-e.x,i.y-e.y)}function Ae(i){let e=ee(i);return Math.max(48,e)}function Ce(i,e,t){var l,u;let a=i.type===t,r=e.type===t;if(a&&!r)return 1;if(!a&&r)return-1;let n=J(i)-J(e);if(n!==0)return n;let s=Y(i)-Y(e);if(s!==0)return s;let o=((l=i.reviews)!=null?l:0)-((u=e.reviews)!=null?u:0);return o!==0?o:i.tripadvisor_id-e.tripadvisor_id}function J(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 Y(i){var t,a,r;if(!((a=(t=i.pricing)==null?void 0:t.offer)!=null&&a.price))return-1/0;let e=Number(((r=i.pricing.offer.displayPrice)!=null?r:"0").replace(/[^0-9.,-]+/g,"").replace(/,/g,""));return Number.isNaN(e)?-1/0:e}function te(i){let e=[];return i.amenities&&Array.isArray(i.amenities)&&i.amenities.forEach(t=>{e.push({id:`amenity-${t}`,label:t,type:"amenity",value:t})}),i.hotelStyle&&Array.isArray(i.hotelStyle)&&i.hotelStyle.forEach(t=>{e.push({id:`hotelStyle-${t}`,label:t,type:"hotelStyle",value:t})}),i.price&&e.push({id:"priceRange",label:"Price Range",type:"priceRange",value:`${i.price.min}-${i.price.max}`,priceRange:i.price}),typeof i.minRating=="number"&&Number.isFinite(i.minRating)&&e.push({id:"minRating",label:`${i.minRating}+`,type:"minRating",value:String(i.minRating),numericValue:i.minRating}),typeof i.starRating=="number"&&Number.isFinite(i.starRating)&&e.push({id:"starRating",label:`${i.starRating} Stars`,type:"starRating",value:String(i.starRating),numericValue:i.starRating}),i.transformed_query&&e.push({id:"transformed_query",label:i.transformed_query,type:"transformed_query",value:i.transformed_query}),i.selected_restaurant_price_levels&&e.push({id:"selected_restaurant_price_levels",label:i.selected_restaurant_price_levels.join(", "),type:"selected_restaurant_price_levels",value:i.selected_restaurant_price_levels.join(", "),priceLevels:i.selected_restaurant_price_levels}),e}function re(i){return i.map(e=>{let t={id:e.id,label:typeof e.label=="string"?e.label:String(e.label||""),type:e.type,value:e.value};if(e.numericValue!==void 0&&(t.numericValue=e.numericValue),e.priceRange){let a=e.priceRange.min,r=e.priceRange.max;a!==void 0&&(t.priceRange={min:a,...r!==void 0&&{max:r}})}return e.priceLevels&&(t.priceLevels=e.priceLevels),t})}var we={prod:"https://api.mapfirst.ai",test:"https://api.mapfirst.ai/test"},R=class extends Error{constructor({message:e,status:t,code:a}){super(e),this.name="PropertiesFetchError",this.status=t,this.code=a}};async function z(i,e=1){try{let t=await fetch(`https://l4detuz832.execute-api.us-east-1.amazonaws.com/dev/photo?id=${i}&limit=${e}`);if(!t.ok)return null;let a=await t.json();if(a.photos&&a.photos.length>0){let r=a.photos[0].FullSizeURL.url;if((await fetch(r)).ok)return r}return null}catch(t){return console.debug("Failed to fetch images:",t),null}}async function se(i,e,t,{signal:a}={}){var n,s;let r=await fetch(i,{method:"POST",headers:{"Content-Type":"application/json",...t&&{"X-API-Key":t}},body:JSON.stringify(e),signal:a});if(!r.ok){let o=`Unexpected response: ${r.status}`,l;try{let u=await r.json();o=(s=(n=u.detail)!=null?n:u.error)!=null?s:o,l=u.code}catch{}throw new R({message:o,status:r.status,code:l})}return await r.json()}function ae(i){return typeof i=="string"?i:i.toISOString().slice(0,10)}var ie="Accommodation";function Ie(){let e=new Date(Date.now()+864e6),t=(6-e.getDay()+7)%7,a=new Date(e.getTime()+t*864e5),r=a.getDay(),n=r===0?6:6-r,s=new Date(a.getTime()+(n+1)*864e5);return{checkIn:a,checkOut:s}}var V=class{constructor(e){this.options=e;this.adapter=null;this.properties=[];this.selectedMarkerId=null;this.destroyed=!1;this.clusterItems=[];this.isMapAttached=!1;var r,n,s,o,l,u,y,M,c,p,b,d,g,f,m,h;if(this.properties=[...(r=e.properties)!=null?r:[]],this.primaryType=e.primaryType,this.selectedMarkerId=(n=e.selectedMarkerId)!=null?n:null,this.useApi=(s=e.useApi)!=null?s:!0,this.environment=(o=e.environment)!=null?o:"prod",this.apiUrl=(l=e.apiUrl)!=null?l:we[this.environment],this.apiKey=e.apiKey,this.requestBody=e.requestBody,this.currentPlatform=e.platform,!this.useApi&&e.platform&&e.platform!=="maplibre")throw new Error("When useApi is false, only maplibre platform is supported. Google Maps and Mapbox require API usage.");let t=ne(e);this.fitBoundsPadding={top:(y=(u=e.fitBoundsPadding)==null?void 0:u.top)!=null?y:t?0:50,bottom:(c=(M=e.fitBoundsPadding)==null?void 0:M.bottom)!=null?c:t?0:160,left:(b=(p=e.fitBoundsPadding)==null?void 0:p.left)!=null?b:t?0:50,right:(g=(d=e.fitBoundsPadding)==null?void 0:d.right)!=null?g:t?0:50};let a=Ie();this.state={center:[0,0],zoom:0,bounds:null,pendingBounds:null,tempBounds:null,properties:this.properties,primary:(f=this.primaryType)!=null?f:ie,selectedPropertyId:this.selectedMarkerId,initialLoading:!0,isSearching:!1,firstCallDone:!1,filters:{checkIn:a.checkIn,checkOut:a.checkOut,numAdults:2,numRooms:1,...((m=e.initialLocationData)==null?void 0:m.currency)&&{currency:e.initialLocationData.currency}},activeLocation:{country:"",location_id:null,locationName:"",coordinates:[0,0]},isFlyToAnimating:!1,...e.state},this.callbacks=(h=e.callbacks)!=null?h:{},this.hasMapInstance(e)&&(this.adapter=this.createAdapter(e),this.isMapAttached=!0,this.refresh()),e.initialLocationData?this.initializeFromLocationData(e.initialLocationData):this.requestBody&&this.isMapAttached&&this.autoLoadProperties()}hasMapInstance(e){return!!("adapter"in e&&e.adapter||"mapInstance"in e&&e.mapInstance)}async initializeFromLocationData(e){if(!this.useApi){console.warn("initializeFromLocationData requires API usage. Set useApi to true.");return}try{let{city:t,country:a,query:r}=e,n={filters:this.getFilters(),initial:!0};if(t&&a||a){let s=await fetch(`${this.apiUrl}/geo-lookup?country=${encodeURIComponent(a)}${t?`&city=${encodeURIComponent(t)}`:""}`,{headers:{...this.apiKey&&{"X-API-Key":this.apiKey}}});if(s.ok){let o=await s.json(),l=t;o.location_name&&o.path3_name&&o.location_name===o.path3_name&&(l=void 0),o.location_name&&(l=o.location_name);let u=o.path3_name||a;n={...n,city:l,country:u,location_id:o.location_id,longitude:o.longitude,latitude:o.latitude},this.setActiveLocation({city:l,country:u,location_id:o.location_id,locationName:l&&u?`${l}, ${u}`:u||"",coordinates:[o.latitude,o.longitude]}),this.setState({center:[o.latitude,o.longitude],zoom:12})}else this.handleError(new Error(`Geo mapping fetch failed: ${s.statusText}`),"initializeFromLocationData")}else r&&(n.query=r);this.requestBody=n,this.isMapAttached&&await this.autoLoadProperties()}catch(t){this.handleError(t,"initializeFromLocationData")}}async autoLoadProperties(){if(!this.useApi){console.warn("autoLoadProperties requires API usage. Set useApi to true.");return}if(!this.requestBody)return;let e={filters:this.getFilters(),initial:!0,...this.requestBody};await this.runPropertiesSearch({body:e,onError:t=>{var a,r;this.handleError(t,"autoLoadProperties"),(r=(a=this.callbacks).onPropertiesLoadError)==null||r.call(a,t)}})}attachMap(e,t){if(!this.useApi&&t.platform!=="maplibre")throw new Error("When useApi is false, only maplibre platform is supported. Google Maps and Mapbox require API usage.");if(this.isMapAttached&&(console.warn("Map is already attached. Destroying previous adapter."),this.adapter)){let r=this.adapter.getMarkerManager();r==null||r.destroy(),this.adapter.cleanup()}let a={...this.options,platform:t.platform,mapInstance:e,maplibregl:t.maplibregl,google:t.google,mapboxgl:t.mapboxgl,onMarkerClick:t.onMarkerClick};this.currentPlatform=t.platform,this.adapter=this.createAdapter(a),this.isMapAttached=!0,this.refresh(),this.requestBody&&!this.state.firstCallDone&&this.autoLoadProperties()}createAdapter(e){return Ee(e)&&e.mapInstance?this.initializeAdapter(new F(e.mapInstance),{maplibregl:e.maplibregl,onMarkerClick:e.onMarkerClick}):ne(e)&&e.mapInstance?this.initializeAdapter(new H(e.mapInstance),{google:e.google,onMarkerClick:e.onMarkerClick}):Se(e)&&e.mapInstance?this.initializeAdapter(new D(e.mapInstance),{mapboxgl:e.mapboxgl,onMarkerClick:e.onMarkerClick}):"adapter"in e&&e.adapter?e.adapter:null}initializeAdapter(e,t){var r;let a=(r=this.options.autoSelectOnClick)!=null?r:!0;return e.initialize({...t,onMarkerClick:n=>{var s;n.location&&this.flyMapTo(n.location.lon,n.location.lat,14),n.type!==this.primaryType&&this.setPrimaryType(n.type),a&&this.setSelectedMarker(n.tripadvisor_id===this.selectedMarkerId?null:n.tripadvisor_id),(s=t.onMarkerClick)==null||s.call(t,n)},onRefresh:()=>this.refresh(),onMapMoveEnd:n=>{this.state.tempBounds===null?(this.setTempBounds(n),this.setPendingBounds(null)):this.handleMapMoveEnd(n)}}),this.useApi&&e.setupImpressionTracking(()=>{console.log("ToDo: Track Map Impression")}),e}_setProperties(e){var t,a;this.ensureAlive(),this.properties=[...e.filter(r=>{var n;return r.type==="Accommodation"?((n=r.pricing)==null?void 0:n.availability)!=="unavailable":!0})],this.updateState({properties:this.properties}),(a=(t=this.callbacks).onPropertiesChange)==null||a.call(t,e),this.refresh()}addProperty(e){var t,a;this.ensureAlive(),this.properties=[...this.properties,e],this.updateState({properties:this.properties}),(a=(t=this.callbacks).onPropertiesChange)==null||a.call(t,this.properties),this.refresh()}clearProperties(){var e,t;this.ensureAlive(),this.properties=[],this.updateState({properties:[]}),(t=(e=this.callbacks).onPropertiesChange)==null||t.call(e,[]),this.refresh()}setPrimaryType(e){var t,a;this.ensureAlive(),this.primaryType!==e&&(this.primaryType=e,this.updateState({primary:e}),(a=(t=this.callbacks).onPrimaryTypeChange)==null||a.call(t,e),this.refresh())}setSelectedMarker(e){var t,a;if(this.ensureAlive(),this.selectedMarkerId!==e){if(e!==null){let r=this.properties.find(n=>n.tripadvisor_id===e);r&&r.type!==this.primaryType&&this.setPrimaryType(r.type)}this.selectedMarkerId=e,this.updateState({selectedPropertyId:e}),(a=(t=this.callbacks).onSelectedPropertyChange)==null||a.call(t,e),this.refresh()}}getState(){return{...this.state}}handleError(e,t="MapFirstCore"){let a=e instanceof Error?e.message:String(e),r=e instanceof Error?e:new Error(a);console.error(`[${t}]`,a),this.callbacks.onError&&this.callbacks.onError(r,t)}updateState(e){this.state={...this.state,...e}}setState(e){var a,r,n,s,o,l,u,y,M,c,p,b,d,g,f,m;let t={...this.state};this.updateState(e),e.center!==void 0&&e.center!==t.center&&((r=(a=this.callbacks).onCenterChange)==null||r.call(a,e.center,this.state.zoom)),e.zoom!==void 0&&e.zoom!==t.zoom&&((s=(n=this.callbacks).onZoomChange)==null||s.call(n,e.zoom)),e.bounds!==void 0&&e.bounds!==t.bounds&&((l=(o=this.callbacks).onBoundsChange)==null||l.call(o,e.bounds)),e.pendingBounds!==void 0&&e.pendingBounds!==t.pendingBounds&&((y=(u=this.callbacks).onPendingBoundsChange)==null||y.call(u,e.pendingBounds)),e.filters!==void 0&&e.filters!==t.filters&&((c=(M=this.callbacks).onFiltersChange)==null||c.call(M,e.filters)),e.activeLocation!==void 0&&e.activeLocation!==t.activeLocation&&((b=(p=this.callbacks).onActiveLocationChange)==null||b.call(p,e.activeLocation)),e.initialLoading!==void 0&&e.initialLoading!==t.initialLoading&&((g=(d=this.callbacks).onLoadingStateChange)==null||g.call(d,e.initialLoading)),e.isSearching!==void 0&&e.isSearching!==t.isSearching&&((m=(f=this.callbacks).onSearchingStateChange)==null||m.call(f,e.isSearching))}setFilters(e){this.setState({filters:e})}setActiveLocation(e){this.setState({activeLocation:e})}setBounds(e){this.setState({bounds:e})}setPendingBounds(e){this.setState({pendingBounds:e})}setTempBounds(e){this.setState({tempBounds:e})}setLoading(e){this.setState({initialLoading:e})}setSearching(e){this.setState({isSearching:e})}setFlyToAnimating(e){this.setState({isFlyToAnimating:e})}handleMapMoveEnd(e){if(this.state.isFlyToAnimating){this.setState({isFlyToAnimating:!1,tempBounds:e,pendingBounds:null});return}let t=this.state.tempBounds;if(!t){this.setState({tempBounds:e,pendingBounds:e});return}let a=.01;Math.abs(e.sw.lat-t.sw.lat)>a||Math.abs(e.sw.lng-t.sw.lng)>a||Math.abs(e.ne.lat-t.ne.lat)>a||Math.abs(e.ne.lng-t.ne.lng)>a?this.setState({pendingBounds:e}):this.setState({pendingBounds:null})}flyMapTo(e,t,a,r=!0){if(this.ensureAlive(),this.setState({center:[t,e]}),typeof a=="number"&&this.setState({zoom:a}),!this.adapter)return;let n=this.adapter.getMap();if(n){if(this.currentPlatform==="google"){this.setFlyToAnimating(!1),n.setCenter({lat:t,lng:e}),a!==null&&typeof a=="number"&&n.setZoom(a!=null?a:13);return}if(r===!1){this.setFlyToAnimating(!1),n.jumpTo&&n.jumpTo({center:[e,t],...a!==null&&{zoom:a!=null?a:13}});return}this.setFlyToAnimating(!0),n.flyTo&&n.flyTo({center:[e,t],...a!==null&&{zoom:a!=null?a:13}})}}flyToPOIs(e,t,a=!0){var s,o;if(this.ensureAlive(),!this.adapter)return;let r=this.adapter.getMap();if(!r)return;let n=e;if((!n||n.length===0)&&(n=this.properties.filter(l=>l.location!==void 0&&(t!==void 0?l.type===t:!0)).map(l=>({lat:l.location.lat,lng:l.location.lon}))),!(!n||n.length===0)){if(n.length===1){let l=n[0];this.currentPlatform==="google"?(r.setCenter({lat:l.lat,lng:l.lng}),r.setZoom(13)):r.flyTo&&r.flyTo({center:[l.lng,l.lat],zoom:13})}else if(this.currentPlatform==="google"){let l=(o=(s=window.google)==null?void 0:s.maps)==null?void 0:o.LatLngBounds;if(l){let u=new l;n.forEach(y=>{u.extend({lat:y.lat,lng:y.lng})}),a&&this.setFlyToAnimating(!0),r.fitBounds(u,this.fitBoundsPadding)}}else if(r.fitBounds){let l=[[n[0].lng,n[0].lat],[n[0].lng,n[0].lat]];n.forEach(u=>{l[0][0]=Math.min(l[0][0],u.lng),l[0][1]=Math.min(l[0][1],u.lat),l[1][0]=Math.max(l[1][0],u.lng),l[1][1]=Math.max(l[1][1],u.lat)}),a&&this.setFlyToAnimating(!0),r.fitBounds(l,{padding:this.fitBoundsPadding,animate:a})}}}getFilters(){let e={...this.state.filters};return e.checkIn instanceof Date&&(e.checkIn=ae(e.checkIn)),e.checkOut instanceof Date&&(e.checkOut=ae(e.checkOut)),e}async pollForPricing({pollingLink:e,maxAttempts:t=15,delayMs:a=2e3,isCancelled:r,price:n,limit:s}){var M,c,p,b,d;if(this.ensureAlive(),!this.useApi)return console.warn("pollForPricing requires API usage. Set useApi to true."),{completed:!1};if(!e)return{completed:!1};let o=!1,l,u=this.getFilters();s&&(u.limit=s);let y={filters:u,pollingLink:e};for(let g=0;g<t;g++){if(r!=null&&r())return{completed:o,pollData:l};try{let f=await fetch(`${this.apiUrl}/ta-polling?pollingNumber=${g}`,{method:"POST",body:JSON.stringify(y),headers:{"Content-Type":"application/json",...this.apiKey&&{"X-API-Key":this.apiKey}}});if(!f.ok)throw new R({message:`Poll failed: ${f.status}`,status:f.status});if(l=await f.json(),r!=null&&r())return{completed:o,pollData:l};let m=(c=(M=l==null?void 0:l.success)==null?void 0:M.results)!=null?c:[];if(m.length>0&&this.setProperties(h=>{let P=new Set(m.map(x=>x.tripadvisor_id)),T=h.filter(x=>x.type!=="Accommodation"||P.has(x.tripadvisor_id));return m.forEach(x=>{var L,k,v,A,w,U;if(!x.location)return;(k=(L=x.pricing)==null?void 0:L.offer)!=null&&k.price&&n&&(((A=(v=x.pricing)==null?void 0:v.offer)==null?void 0:A.price)<(n==null?void 0:n.min)||((U=(w=x.pricing)==null?void 0:w.offer)==null?void 0:U.price)>(n==null?void 0:n.max))&&(x.pricing.availability="unavailable");let C=T.findIndex(oe=>oe.tripadvisor_id===x.tripadvisor_id);C>=0?T[C]=x:T.push(x)}),T}),(p=l==null?void 0:l.success)!=null&&p.isComplete){o=!0;break}}catch(f){this.handleError(f,"pollForPricing"),(d=(b=this.callbacks).onPropertiesLoadError)==null||d.call(b,f);break}g<t-1&&await new Promise(f=>setTimeout(f,a))}return{completed:o,pollData:l}}setProperties(e){let t=e(this.properties);this._setProperties(t)}mostCommonTypeFromProperties(e){let t=e.reduce((a,r)=>(a[r.type]=(a[r.type]||0)+1,a),{});return Object.entries(t).reduce((a,r)=>t[a[0]]>t[r[0]]?a:r)[0]}async runPropertiesSearch({body:e,beforeApplyProperties:t,smartFiltersClearable:a,onError:r}){var n,s,o,l,u,y,M;if(this.ensureAlive(),!this.useApi)return console.warn("runPropertiesSearch requires API usage. Set useApi to true."),r==null||r(new Error("API usage is disabled")),null;this.setState({firstCallDone:!1}),this.setSearching(!0),this.clearProperties();try{let c=await se(`${this.apiUrl}/properties`,e,this.apiKey);this.updateActiveLocationFromResponse(c);let p=null,b=30,d=c.filters.primary_type;if(t){let m=t(c);p=(n=m.price)!=null?n:null,b=(s=m.limit)!=null?s:30}let g=c.properties.some(m=>!!m.location),f=p?c.properties.map(m=>{var h;return(h=m.pricing)!=null&&h.offer?{...m,pricing:{...m.pricing,availability:m.pricing.offer.price&&(m.pricing.offer.price<p.min||m.pricing.offer.price>p.max)?"unavailable":m.pricing.availability}}:m}):c.properties;if(this._setProperties(f),g&&this.flyToPOIs(c.properties.filter(m=>!!m.location&&(c.filters.primary_type?m.type===c.filters.primary_type:!0)).map(m=>({lat:m.location.lat,lng:m.location.lon})),void 0,e.initial!==!0),c.filters.primary_type&&c.properties.filter(m=>{var h;return m.type===c.filters.primary_type&&(m.type==="Accommodation"?((h=m.pricing)==null?void 0:h.availability)!=="unavailable":!0)}).length>0)d=c.filters.primary_type,this.setPrimaryType(c.filters.primary_type);else if(c.properties.length>0){let m=this.mostCommonTypeFromProperties(c.properties);this.setPrimaryType(m),d=m}if(this.setState({firstCallDone:!0}),c.isComplete===!1&&c.pollingLink){let{completed:m,pollData:h}=await this.pollForPricing({pollingLink:c.pollingLink,...p&&{price:p},...b&&{limit:b}});if(m&&((o=h==null?void 0:h.success)!=null&&o.results)&&h.success.results.filter(P=>{var T;return P.type===c.filters.primary_type&&(P.type==="Accommodation"?((T=P.pricing)==null?void 0:T.availability)!=="unavailable":!0)}).length===0&&d&&d!==c.filters.primary_type){let P=this.mostCommonTypeFromProperties(c.properties);this.setPrimaryType(P)}m&&this.refresh()}return g||(c.properties.some(m=>!!m.location)?this.flyToPOIs(c.properties.filter(m=>!!m.location&&(c.filters.primary_type?m.type===c.filters.primary_type:!0)).map(m=>({lat:m.location.lat,lng:m.location.lon})),void 0,e.initial!==!0):(l=c.filters.location)!=null&&l.latitude&&((u=c.filters.location)!=null&&u.longitude)&&this.flyMapTo(c.filters.location.longitude,c.filters.location.latitude,12,e.initial!==!0)),c}catch(c){return this.handleError(c,"runPropertiesSearch"),r==null||r(c),(M=(y=this.callbacks).onPropertiesLoadError)==null||M.call(y,c),this.clearProperties(),this.setState({firstCallDone:!0}),null}finally{this.setSearching(!1),this.setState({firstCallDone:!0})}}async performBoundsSearch(){var n;if(this.ensureAlive(),!this.useApi)return console.warn("performBoundsSearch requires API usage. Set useApi to true."),null;if(!this.state.pendingBounds)return null;let e=this.getFilters(),t={bounds:this.state.pendingBounds,filters:e},a=(n=e==null?void 0:e.price)!=null?n:void 0,r=await this.runPropertiesSearch({body:t,beforeApplyProperties:()=>({price:a!=null?a:null})});return r&&(this.setBounds(this.state.pendingBounds),this.setTempBounds(this.state.pendingBounds),this.setPendingBounds(null)),r}updateActiveLocationFromResponse(e){var o,l,u,y;let t=(o=e.location_id)!=null?o:null,a=(u=(l=e.filters.location)==null?void 0:l.city)!=null?u:void 0,r=((y=e.filters.location)==null?void 0:y.country)||"",n=e.filters.location?[e.filters.location.latitude,e.filters.location.longitude]:void 0;if(!n)return;let s=this.state.activeLocation;(t!==(s==null?void 0:s.location_id)||a!==(s==null?void 0:s.city)||r!==(s==null?void 0:s.country))&&this.setActiveLocation({city:a,country:r,location_id:t,locationName:a&&r?`${a}, ${r}`:r||"",coordinates:n})}async runSmartFilterSearch({query:e,filters:t,onProcessFilters:a,onError:r}){if(this.ensureAlive(),!this.useApi)return console.warn("runSmartFilterSearch requires API usage. Set useApi to true."),r==null||r(new Error("API usage is disabled")),null;let n=this.getFilters(),s=this.getState();if(t&&t.length>0){let l=new Set,u=new Set,y,M,c,p,b,d;t.forEach(g=>{var f,m,h;switch(g.type){case"amenity":l.add(g.value);break;case"hotelStyle":u.add(g.value);break;case"priceRange":g.priceRange&&(y={min:g.priceRange.min,max:(f=g.priceRange.max)!=null?f:0});break;case"minRating":M=(m=g.numericValue)!=null?m:Number(g.value);break;case"starRating":c=(h=g.numericValue)!=null?h:Number(g.value);break;case"primary_type":p=g.propertyType;break;case"transformed_query":b=g.value;break;case"selected_restaurant_price_levels":d=g.priceLevels;break}}),n={...n,...l.size>0&&{amenities:Array.from(l)},...u.size>0&&{hotelStyle:Array.from(u)},...y&&{price:y},...M!==void 0&&{minRating:M},...c!==void 0&&{starRating:c},...p&&{primary_type:p},...b&&{transformed_query:b},...d&&{selected_restaurant_price_levels:d}}}else e||(n.minRating=4);let o={filters:n,...e&&{query:e},...s.bounds?{bounds:s.bounds}:s.activeLocation.location_id?{location_id:s.activeLocation.location_id}:s.activeLocation.coordinates?{latitude:s.activeLocation.coordinates[0],longitude:s.activeLocation.coordinates[1]}:{}};return this.runPropertiesSearch({body:o,beforeApplyProperties:a?l=>{var y,M;let u=a(l.filters,l.location_id);return{price:(y=u.price)!=null?y:null,limit:(M=u.limit)!=null?M:30}}:void 0,smartFiltersClearable:!!e,onError:r})}getClusters(){return this.ensureAlive(),[...this.clusterItems]}setUseApi(e,t=!0){this.ensureAlive(),this.useApi=e,!e&&this.currentPlatform&&this.currentPlatform!=="maplibre"&&console.warn("When useApi is false, only maplibre platform is supported. Please switch to maplibre."),e||this.clearProperties(),e&&t&&(this.options.initialLocationData?this.initializeFromLocationData(this.options.initialLocationData):this.requestBody&&this.isMapAttached&&this.autoLoadProperties())}setApiKey(e){this.ensureAlive();let t=this.apiKey;this.apiKey=e,t!==this.apiKey&&this.isMapAttached&&(this.refresh(),this.useApi&&(this.options.initialLocationData?this.initializeFromLocationData(this.options.initialLocationData):this.requestBody&&this.autoLoadProperties()))}getApiKey(){return this.apiKey}refresh(){var r,n,s;if(this.ensureAlive(),!this.adapter)return;let e=this.safeExtractViewState(),t=this.resolvePrimaryType();this.clusterItems=G({primaryType:t,markers:this.properties,map:this.adapter,selectedMarkerId:this.selectedMarkerId,zoom:(r=e==null?void 0:e.zoom)!=null?r:0}),this.adapter.getMarkerManager().render(this.clusterItems,t,this.selectedMarkerId),(s=(n=this.options).onClusterUpdate)==null||s.call(n,this.clusterItems,e)}destroy(){this.destroyed||(this.adapter&&(this.adapter.getMarkerManager().destroy(),this.adapter.cleanup()),this.clusterItems=[],this.properties=[],this.destroyed=!0,this.isMapAttached=!1)}resolvePrimaryType(){var e,t,a;return(a=(t=this.primaryType)!=null?t:(e=this.properties.find(r=>r.type))==null?void 0:e.type)!=null?a:ie}safeExtractViewState(){if(!this.adapter)return null;try{return Q(this.adapter)}catch{return null}}ensureAlive(){if(this.destroyed)throw new Error("MapFirstCore instance has been destroyed")}};function Ee(i){return i.platform==="maplibre"}function ne(i){return i.platform==="google"}function Se(i){return i.platform==="mapbox"}0&&(module.exports={MapFirstCore,PropertiesFetchError,convertToApiFilters,fetchImages,fetchProperties,processApiFilters});
|
|
32
33
|
//# sourceMappingURL=index.js.map
|