!function(){const e=document.querySelectorAll(".hb-price-field"),t=document.querySelectorAll(".hb-rating-field"),r=document.querySelectorAll(".hb-type-field"),a=e=>{const t=window.location.search;return new URLSearchParams(t).get(e)},n=e=>{const t=hotel_settings.currency_symbol||"",r=hotel_settings.currency_position||"left";switch(e=c(e),r){case"left":e=t+e;break;case"right":e+=t;break;case"left_with_space":e=t+" "+e;break;case"right_with_space":e=e+" "+t}return e},c=e=>{const t=hotel_settings.number_decimal||0,r=hotel_settings.thousands_separator||"";return(e=(e/1).toFixed(t)).toString().replace(/\B(?=(\d{3})+(?!\d))/g,r)},l=()=>{if(document.querySelector(".hb-selection-field")){if(e.length)for(let t=0;t<e.length;t++)e[t].querySelector(".hb-price-range").noUiSlider.on("update",(function(e,t,r){const a=parseInt(e[0]),c=parseInt(e[1]);o("price",a+"-"+c,n(a)+"-"+n(c))}));if(t.length&&[...t].map((e=>{[...e.querySelectorAll('input[type="checkbox"]')].map((e=>{if(e.checked){const t=e.value,r=e.closest("label").querySelector("span").innerHTML.replace("-"," ");o("rating",t,r)}e.addEventListener("change",(function(){const t=this.value,r=e.closest("label").querySelector("span").innerHTML.replace("-"," ");o("rating",t,r)}))}))})),r.length)for(let e=0;e<r.length;e++)[...r[e].querySelectorAll('input[type="checkbox"]')].map((e=>{if(e.checked){const t=e.value,r=e.closest("label").querySelector("span").innerHTML.replace("-"," ");o("room-type",t,r)}e.addEventListener("change",(function(){const t=this.value,r=e.closest("label").querySelector("span").innerHTML.replace("-"," ");o("room-type",t,r)}))}))}},o=(e,t,r)=>{const a=document.querySelector(".hb-selection-field .list");let n=a.querySelector(`li[data-field="${e}"]`);if("rating"!==e&&"room-type"!==e||(n=a.querySelector(`li[data-field="${e}"][data-value="${t}"]`)),n)"rating"===e||"room-type"===e?n.remove():t?(n.setAttribute("data-value",t),n.querySelector(".title").innerHTML=r):n.remove();else{const n=`<li class="list-item" data-field = "${e}" data-value="${t}">\n            <span class="title">${r}</span>\n            <svg class="remove" xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16" fill="none">\n                <path d="M12.5 3.5L3.5 12.5" stroke="#AAAFB6" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>\n                <path d="M12.5 12.5L3.5 3.5" stroke="#AAAFB6" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>\n           </svg>\n        </li>`;a.insertAdjacentHTML("beforeend",n)}};document.addEventListener("DOMContentLoaded",(()=>{hotel_settings&&hotel_settings.is_page_search||((()=>{if(e)for(let t=0;t<e.length;t++){const r=e[t],c=r.getAttribute("data-min"),l=r.getAttribute("data-max");let o=r.getAttribute("data-step");if(""===c||""===l||""===o)continue;const s=r.querySelector(".hb-min-price"),i=r.querySelector(".hb-max-price"),h=r.querySelector(".hb-price-range"),u=a("min_price")||c,p=a("max_price")||l;o=parseInt(o),noUiSlider.create(h,{start:[parseInt(u),parseInt(p)],connect:!0,step:o,tooltips:!1,range:{min:parseInt(c),max:parseInt(l)}}),h.noUiSlider.on("update",(function(e,t,a){s.value=parseInt(e[0]),i.value=parseInt(e[1]),r.querySelector(".min").innerHTML=n(e[0]),r.querySelector(".max").innerHTML=n(e[1])}))}})(),(()=>{if(t)for(let e=0;e<t.length;e++){const r=t[e],n=r.querySelectorAll('input[type="checkbox"]');let c=[];a("rating")&&(c=a("rating").split(",")),[...c].map((e=>{r.querySelector(`input[name ="rating"][value ="${e}"]`).checked=!0}));for(let e=0;e<n.length;e++)n[e].addEventListener("change",(function(e){const t=r.querySelectorAll('input[type="checkbox"]:checked');let a=[];[...t].map((e=>{a.push(e.value)}));const n=new URL(window.location.href);a.length?n.searchParams.set("rating",a):n.searchParams.delete("rating"),n.searchParams.set("paged",1)}))}})(),(()=>{if(r)for(let e=0;e<r.length;e++){const t=r[e],n=t.querySelectorAll('input[type="checkbox"]');let c=[];a("room_type")&&(c=a("room_type").split(",")),[...c].map((e=>{t.querySelector(`input[name ="room_type"][value ="${e}"]`).checked=!0}));for(let e=0;e<n.length;e++)n[e].addEventListener("change",(function(e){const r=t.querySelectorAll('input[type="checkbox"]:checked');let a=[];[...r].map((e=>{a.push(e.value)}));const n=new URL(window.location.href);a.length?n.searchParams.set("room_type",a):n.searchParams.delete("room_type",a),n.searchParams.set("paged",1)}))}})(),l(),(()=>{const e=document.querySelectorAll(".search-filter-form");if(e)for(let t=0;t<e.length;t++){const r=e[t].querySelector(".clear-filter button");if(!r)return;r.addEventListener("click",(function(){const e=new URL(window.location.href);["min_price","max_price","rating","room_type"].map((t=>{e.searchParams.get(t)&&e.searchParams.delete(t)})),e.searchParams.set("paged",1),window.location.href=e}))}})(),document.addEventListener("click",(function(a){const n=a.target;if(!n.classList.contains("remove"))return;if(!n.closest(".hb-selection-field"))return;const c=n.closest(".list-item");switch(c.getAttribute("data-field")){case"room-type":((e="all")=>{[...r].map((t=>{const r=t.querySelectorAll('input[type="checkbox"]');"all"===e?[...r].map((e=>{e.checked=!1})):t.querySelector(`.room-type-list input[value="${e}"]`).checked=!1;let a=[];[...r].map((e=>{a.push(e.value)}));const n=new URL(window.location.href);a.length?n.searchParams.set("rating",a):n.searchParams.delete("rating"),n.searchParams.set("paged",1),window.location.href=n}))})(c.getAttribute("data-value"));break;case"rating":((e="all")=>{[...t].map((t=>{const r=t.querySelectorAll('input[type="checkbox"]');"all"===e?[...r].map((e=>{e.checked=!1})):t.querySelector(`.rating-list input[value="${e}"]`).checked=!1;let a=[];[...r].map((e=>{a.push(e.value)}));const n=new URL(window.location.href);a.length?n.searchParams.set("rating",a):n.searchParams.delete("rating"),n.searchParams.set("paged",1),window.location.href=n}))})(c.getAttribute("data-value"));break;case"price":(()=>{if(e.length)for(let t=0;t<e.length;t++){const r=e[t];r.querySelector(".hb-price-range").noUiSlider.updateOptions({start:[parseInt(r.getAttribute("data-min")),parseInt(r.getAttribute("data-max"))]})}const t=new URL(window.location.href);["min_price","max_price"].map((e=>{t.searchParams.get(e)&&t.searchParams.delete(e)})),t.searchParams.set("paged",1),window.location.href=t})()}c&&c.remove()})),(()=>{const e=document.querySelector(".hb-room-filter-btn");e&&e.addEventListener("click",(function(e){e.preventDefault();const t=document.querySelectorAll(".hb-price-field"),r=document.querySelectorAll(".hb-rating-field"),a=document.querySelectorAll(".hb-type-field"),n=new URL(window.location.href);n.searchParams.set("paged",1);for(let e=0;e<t.length;e++){const r=t[e],a=r.querySelector(".hb-min-price").value,c=r.querySelector(".hb-max-price").value;n.searchParams.set("min_price",a),n.searchParams.set("max_price",c)}for(let e=0;e<r.length;e++){const t=r[e].querySelectorAll('input[type="checkbox"]:checked');let a=[];[...t].map((e=>{a.push(e.value)})),a.length?n.searchParams.set("rating",a):n.searchParams.has("rating")&&n.searchParams.delete("rating")}for(let e=0;e<a.length;e++){const t=a[e].querySelectorAll('input[type="checkbox"]:checked');let r=[];[...t].map((e=>{r.push(e.value)})),r.length?n.searchParams.set("room_type",r):n.searchParams.has("room_type")&&n.searchParams.delete("room_type")}window.location.href=n}))})())}))}();