class Favorites{#favoriteButtonCssClass='favourite';#favoriteButtons=[];constructor(){const favButtons=document.getElementsByClassName(this.#favoriteButtonCssClass);for(let i=0;i<favButtons.length;i++){this.#favoriteButtons.push(new FavoriteButton(favButtons[i]));}
this.#setSelectedFavorites();}
async#setSelectedFavorites(){if(typeof window.user==='undefined'){window.user=new User();}
while(!window.user.isReady){await new Promise(resolve=>setTimeout(resolve,100));}
if(user.authenticated){if(this.#favoriteButtons.length>0){const me=this;if(user.authenticated){const favorites=cookies.getNullable('favorites');if(favorites!=null){me.setSelectedFavoritesToArray(favorites.split(','));}else{fetch('/Umbraco/Api/Favorites/Get').then(response=>response.json()).then(data=>{me.setSelectedFavoritesToArray(data);});}}}}}
setSelectedFavoritesToArray(favoritesIds){for(let i=0;i<favoritesIds.length;i++){const found=this.#favoriteButtons.find(fb=>fb.hotelId==favoritesIds[i]);if(found){found.setSelectedStatus(true);}}}}
class FavoriteButton{selected=false;#htmlElement;hotelId;#selectedCssClass='selected';#enabled=true;constructor(favButton){this.#htmlElement=favButton;this.selected=this.#htmlElement.classList.contains(this.#selectedCssClass);if(Website.pdpId){this.hotelId=Website.pdpId;}else{this.hotelId=this.#htmlElement.closest('.hotel').getAttribute('data-hotel-ref-id');}
var me=this;this.#htmlElement.addEventListener("click",function(){me.#clickFavButton();});}#clickFavButton(){if(this.#enabled){if(user.authenticated){if(this.selected){this.#removeFavorite();}else{this.#addFavorite();}}else{Authentication.showLoginPanel('hotels-form',Website.contentId,undefined,true,true,"Favorites.");}}}#addFavorite(){const me=this;this.#enabled=false;this.setSelectedStatus(true);fetch('/Umbraco/Api/Favorites/Add?hotelId='+this.hotelId,{method:'POST'}).then(response=>{if(response.ok){me.#enabled=true;}}).catch(err=>console.error(err));this.#addFavoriteDataLayer();}#removeFavorite(){const me=this;this.#enabled=false;this.setSelectedStatus(false);fetch('/Umbraco/Api/Favorites/Remove?hotelId='+this.hotelId,{method:'POST'}).then(response=>{if(response.ok){me.#enabled=true;}}).catch(err=>console.error(err));}
setSelectedStatus(isSelected){this.selected=isSelected;if(this.selected){this.#htmlElement.classList.add(this.#selectedCssClass);}else{this.#htmlElement.classList.remove(this.#selectedCssClass);}}#addFavoriteDataLayer(){let hotelName;let hotelCity;let hotelCountry;if(Website.pdpId){hotelName=document.querySelector('h1').textContent.trim();const locationHtml=document.querySelector('.location');let hotelCities=[];locationHtml.querySelectorAll('.city').forEach((x,i)=>hotelCities.push(x.textContent));hotelCity=hotelCities.join(', ');hotelCountry=locationHtml.querySelector('.country').textContent.replace(/\((.*)\)/,"").trim();}else{hotelName=this.#htmlElement.closest('.hotel').querySelector('h3').textContent.trim();const location=this.#htmlElement.closest('.hotel').querySelector('.location').textContent.trim();const locationElements=location.split(',');hotelCountry=locationElements[locationElements.length-1];hotelCity=location.substring(0,location.lastIndexOf(','));}
window.dataLayer=window.dataLayer||[];window.dataLayer.push({ecommerce:null});window.dataLayer.push({'event':'add_to_wishlist','eventName':'add_to_wishlist','ecommerce':{'items':[{'item_name':hotelName,'item_id':this.hotelId,'price':'','item_brand':window.location.pathname,'item_category':hotelCity,'item_category2':hotelCountry,'item_category3':'','item_variant':'','quantity':''}]}});}}
window.favorites=new Favorites();;;class CurrencyConverter{#defaultCurrency='EUR';constructor(){this.#setCurrentCurrencyToHtml();this.#bindActions();}#bindActions(){const buttons=document.querySelectorAll('.currency-btn');buttons.forEach(button=>{button.onclick=()=>{const currencyCode=button.dataset.currency;this.#setCurrency(currencyCode);};});}#setCurrentCurrencyToHtml(){var currentCurrency=cookies.get('currency');if(currentCurrency==''){currentCurrency=this.#defaultCurrency;}
document.querySelectorAll('.current-currency').forEach(element=>{element.textContent=currentCurrency;});}#setCurrency(currencyCode){fetch('/umbraco/api/CurrencyConverter/SetCurrency?currencyCode='+currencyCode,{method:'GET',headers:{'Accept':'application/xml'}}).then(response=>{if(!response.ok){return response.text().then(text=>{throw new Error(text);});}
return response.text();}).then(xml=>{location.reload();}).catch(error=>{alert(error.message);});}
getCurrency(){var currentCurrency=cookies.get('currency');if(currentCurrency===''){currentCurrency=this.#defaultCurrency;}
return currentCurrency;}}
window.currencyConverter=new CurrencyConverter();;;