const engine=window.engine||document.getElementById("engine"),main=document.getElementById("main")||document.querySelector("body.main"),typeOfInputClicked="";let engineSamples=[];const engineSamplesData=engine.getAttribute("data-default-sample");if(engineSamplesData)try{engineSamples=JSON.parse(engineSamplesData)}catch(e){console.warn(e.message)}const autocompleteInput=document.getElementById("destination-input"),submitButtonEngine=document.getElementById("engine-submit"),defaultSearchUrl=submitButtonEngine.getAttribute("data-default-url")||myApp.defaultSearchUrl;defaultSearchUrl||console.warn("[engine] No default search url");let currentSelection={url:defaultSearchUrl&&!defaultSearchUrl.includes(".html")&&"admin/superdeal"!==defaultSearchUrl?`/${defaultSearchUrl}.html`:""};currentSelection.url=currentSelection.url.replace("/.html",".html");let sampleInterval,currentQuery=null;function scrollToTop(){window.scrollTo({top:0,behavior:"smooth"})}const autoScroll=!1;function handleEngineMini(){let e=window.scrollY;const t=document.getElementById("menu"),n=document.getElementById("engine-large"),a=document.getElementById("controls-main"),o=t&&t.offsetHeight||0,s=document.getElementsByClassName("hamburger")[0],i=document.body,l=document.querySelector("a.home-logo");"/"!==document.location.pathname&&window.addEventListener("scroll",()=>{if(i.classList.contains("engine-deployed")&&"search-results"===myApp.page&&i.classList.remove("engine-deployed"),(e=window.scrollY)>=30?t.classList.add("menu-top"):t.classList.remove("menu-top"),document.querySelector(".easyvoyage-preheader").style.maxHeight="200px",e>=o){const e=document.getElementById("duration-list");e&&e.classList.remove("show");const t=document.getElementById("date-list"),o=document.getElementById("autoComplete_list_1");"toocamp"===myApp.siteType&&t&&t.classList.remove("show"),o&&o.setAttribute("hidden",""),a&&(a.classList.add("mini-controls"),a&&a.classList.contains("hide-controls")&&a.classList.remove("hide-controls")),a&&a.classList.add("mini-controls"),l&&l.classList.add("move-logo-to-the-background"),n.classList.add("scroll-controls"),s.classList.add("set-z-index-to-0")}else a&&a.classList.remove("mini-controls"),l&&l.classList.remove("move-logo-to-the-background"),n.classList.remove("scroll-controls"),s.classList.remove("set-z-index-to-0")})}const openCalendar=()=>{document.getElementById("datetimerange-input1").click()};function openMobileEngineLarge(e,t){const n=document.body;let a;const o=document.getElementById("controls-main");if(o&&o.classList.add("hide-controls"),n&&0===window.scrollY&&"search-results"===myApp.page&&window.innerWidth<900&&!n.classList.contains("engine-deployed")&&(n.classList.add("engine-deployed"),"lokapi"===myApp.siteType&&"date"===e&&(clearInterval(a),a=setTimeout(()=>{openCalendar()},200))),"duration"===e){document.getElementById("duration-list").classList.add("show")}if("date"===e)if("toocamp"===myApp.siteType){document.getElementById("date-list").classList.add("show"),selectDefautDate(t)}else openCalendar(),selectDefautDate(t)}handleEngineMini();const engineSampleRotation=()=>{if(!autocompleteInput.value){autocompleteInput.value=engineSamples[0];let e=0;sampleInterval=setInterval(()=>{e>=engineSamples.length&&(e=0),autocompleteInput.value=engineSamples[e],e++},2e3)}};async function initDefaultDestination(){if(!autoCompleteJS.input.value.length&&!engineSamples.includes(autoCompleteJS.input.value)){const e=await fetch("/engine/search",{method:"POST",body:JSON.stringify({q:autoCompleteJS.input.value}),headers:{"Content-type":"application/json; charset=UTF-8"}}),t=await e.json();t&&t.length&&(currentSelection=Object.assign(currentSelection,{id:t[0].idt,index:t[0].index,type:t[0].categorie,url:t[0].url,direct:!1,query:autoCompleteJS.input.value}),autoCompleteJS.input.value=t[0].display.split("-")[0]||t[0].display)}}function initAutocomplete(){if(window.autoCompleteJS)return;if(!window.autoComplete)return void console.log("autoComplete not yet ready");const e=new autoComplete({selector:"#destination-input",debounce:200,threshold:3,data:{name:"destination-autocomplete",src:async e=>{currentQuery=e;let t="/engine/search";new URLSearchParams(window.location.search).has("marketing")&&"lokapi"===myApp.siteType&&(t+="?marketingMode=true");try{const n=await fetch(t,{method:"POST",body:JSON.stringify({q:e}),headers:{"Content-type":"application/json; charset=UTF-8"}}),a=document.getElementById("controls-main");return a&&a.classList.contains("mini-controls")&&a.classList.add("hide-controls"),await n.json()}catch(e){return e}},keys:["display"]},separator:{destinations:null,etablissements:null},searchEngine:(e,t)=>t,diacritics:!0,resultsList:{noResults:!0,maxResults:50,tabSelect:!0,element:(e,t)=>{t&&t.matches.forEach((e,t)=>e.index=t),this.separator={destinations:null,etablissements:null}}},events:{input:{focus:()=>{e.input.value.length&&(clearInterval(sampleInterval),e.input.value="",e.start())},blur:()=>{e.close()}}},resultItem:{element:(e,t,n)=>{const a=t.match;myApp.translations||(myApp.translations={});if(["city","zone","ville","departement","Departement","region","pays"].includes(t.value.type)&&this.separator&&!this.separator.destinations){const t=document.createElement("span");t.classList.add("autocomplete-separator"),t.innerText=myApp.translations["geographic-destinations"],e.parentNode.insertBefore(t,e),this.separator.destinations=!0}if(["etablissement","hotel","residence"].includes(t.value.type)&&this.separator&&!this.separator.etablissements){const t=document.createElement("span");t.classList.add("autocomplete-separator"),t.innerText=myApp.translations.Campings,e.parentNode.insertBefore(t,e),this.separator.etablissements=!0}e.style="display: flex; justify-content: space-between;","etablissement"===t.value.type&&e.classList.add(`suggestion-${t.value.type}`);let o=a.split(" - ");o=o.map((e,t)=>0===t?e:1===t?` - ${e} - `:t===o.length-1?`${e}`:`${e} - `).join(""),e.innerHTML=` `}}});window.autoCompleteJS=e,e.input.addEventListener("selection",t=>{const n=t.detail;e.input.blur();const a=n.selection.value;myApp.superDealDisplayMode&&!a.url.includes("/admin/superdeal")&&(a.url=`/admin/superdeal${a.url}`),e.input.value=a[n.selection.key],currentSelection=Object.assign(currentSelection,{id:a.idt,index:a.index,type:a.categorie||a.type,url:a.url,direct:!1,query:currentQuery,display:a.display})}),initDefaultDestination().then().catch(console.warn)}function handleInputList(e,t,n,a,o){const s=document.getElementById(t),i=document.getElementById(n);let l;if(!s)return;if(i){l=document.querySelectorAll(`#${n} li`);let e=document.querySelectorAll(`#${n} li.selected`);e.length&&(e=e[0],i.scrollTop=e.offsetTop-10)}const r=document.getElementById(o);let c=s.getAttribute("data-value");const d=s.getAttribute("data-lang");if(c&&'""'!==c)"date"===e?(c=JSON.parse(c),"lokapi"===myApp.siteType&&["home","search-results"].includes(myApp.page)?(s.value=`${c.date}`,currentSelection.startDate=`${c.date}`.replaceAll("-","")):(s.value=`${c.dayName} ${c.dayNumber} ${c.monthName}`,currentSelection.date=c.date,currentSelection.endDate=c.endDate)):d?(s.value=`${c} ${d}`,currentSelection[e]=c):(s.value=c,currentSelection[e]=c),i&&l.forEach(t=>{t.value==c?t.classList.add("selected"):"date"===e&&t.value==c.date&&t.classList.add("selected")});else if("date"===e){const e=s.getAttribute("data-date-value");currentSelection.startDate=e}i?(s.addEventListener("focus",e=>{i.classList.remove("inactive"),e.preventDefault()}),s.addEventListener("blur",()=>{setTimeout(()=>{i.classList.add("inactive")},200)}),document.addEventListener("click",e=>{r.contains(e.target)||i.classList.add("inactive")}),s.addEventListener("focus",e=>{i.classList.remove("inactive"),e.preventDefault()}),s.addEventListener("blur",()=>{setTimeout(()=>{i.classList.add("inactive")},200)}),r.addEventListener("click",()=>{i.classList.remove("inactive")}),document.addEventListener("click",e=>{r.contains(e.target)||i.classList.add("inactive")}),l.forEach(t=>{t.addEventListener("click",n=>{n.stopPropagation(),l.forEach(e=>{e.classList.remove("selected")}),currentSelection=Object.assign(currentSelection,{[e]:t.value}),i.classList.add("inactive"),s.value=t.innerHTML.trim(),t.classList.add("selected")})})):s.addEventListener("change",e=>{if(e.target&&e.target.value){const t=e.target.value,n=new Date(t).getDay(),a=new Date(t).getDate()<10?`0${new Date(t).getDate()}`:new Date(t).getDate(),o=new Date(t).getMonth()+1<10?`0${new Date(t).getMonth()+1}`:new Date(t).getMonth()+1,i=`${myApp.translations[`day-${n}`].toLowerCase()} ${a} ${myApp.translations[`month-${o-1}`].toLowerCase()}`;s.setAttribute("data-date-label",i);const l=e.target.value.replaceAll("-","");currentSelection.startDate=l}})}function submitSearch(){"function"==typeof addToDataLayer&&addToDataLayer("tooEvent","Recherche",currentSelection.type||"not_set",currentSelection.display||"not_set","","");let e=!1;(window.location.search.includes("widget=1")||window.location.search.includes("widget=true")||window.location.href.includes("/widget/engine"))&&(e=!0);let t=!1;(window.location.search.includes("marketing=1")||window.location.search.includes("marketing=true"))&&(t=!0);const n=document.location.search?document.location.search.replace("?","").split("&"):[],a=[];n.length&&n.forEach(e=>{const t=(e=e.split("="))[0],n=e[1];!currentSelection[t]&&["date","personnes","nuits","client_id"].includes(t)&&a.push(`${t}=${n}`)}),currentSelection.startDate&&"lokapi"===myApp.siteType&&a.push(`startDate=${currentSelection.startDate}`),currentSelection.endDate&&"lokapi"===myApp.siteType&&a.push(`endDate=${currentSelection.endDate}`),currentSelection.date&&a.push(`date=${currentSelection.date}`),currentSelection.personnes&&a.push(`personnes=${currentSelection.personnes}`),currentSelection.nuits&&"toocamp"===myApp.siteType&&a.push(`nuits=${currentSelection.nuits}`),e&&a.push("widget=true"),t&&a.push("marketing=1");const o=currentSelection.url.split("?")[0];let s=`${o}?${a.join("&")}`;s=`${o}?${a.join("&")}`,currentSelection.url=s,fetch("/engine/submit",{method:"POST",body:JSON.stringify({...currentSelection,isSubmitFromWidget:e}),headers:{"Content-Type":"application/json; charset=UTF-8"}}).then(e=>{currentSelection={},window.incrementSearchCookie(),document.location=s}).catch(e=>{console.warn(e)})}function selectDefautDate(e){const t=document.getElementById("date-list");let n=document.querySelectorAll("#date-list li.selected");n.length&&(n=n[0],t.scrollTop=n.offsetTop)}let dateRangePicker;autocompleteInput.value||engineSampleRotation(),handleInputList("nuits","duration-input","duration-list","duration-label","duration-parent"),handleInputList("personnes","guest-input","guest-list","guest-label","guest-parent"),handleInputList("date","date-input","date-list","date-label","date-parent"),window.incrementSearchCookie=window.incrementSearchCookie||function(){if(!window.getCookie)return void console.log("getCookie is not defined");const e=parseInt(getCookie("search_cookie"),10);e?setCookie("search_cookie",e+1,2):setCookie("search_cookie",1,2)},(()=>{if(window.document.addEventListener("autocompleteloaded",()=>console.log("[autocompleteloaded] autocompleteloaded"),!1),window.autoComplete)initAutocomplete();else var e=setInterval(()=>{window.autoComplete&&(window.autoCompleteJS?clearInterval(e):initAutocomplete())},3e3)})();let defaultStartDate=currentSelection.startDate||myApp.searchParams&&myApp.searchParams.startDate||myApp.searchParams&&myApp.searchParams.date||myApp.defaultDate&&myApp.defaultDate.from&&myApp.defaultDate.from.date,defaultEndDate=currentSelection.endDate||myApp.searchParams&&myApp.searchParams.endDate||myApp.defaultDate&&myApp.defaultDate.to&&myApp.defaultDate.to.date;currentSelection.startDate=defaultStartDate,currentSelection.endDate=defaultEndDate,defaultStartDate=formatDateToStringDayMonth(defaultStartDate),defaultEndDate=formatDateToStringDayMonth(defaultEndDate),window.addEventListener("load",function(e,t){if("toocamp"===window.myApp.siteType)return;const n=window.innerWidth||document.documentElement.clientWidth||document.body.clientWidth,a=[],o=[];if(myApp&&myApp.translations){for(let e=0;e<=11;e++)a.push(myApp.translations[`month-long-${e}`]);for(let e=0;e<=6;e++)o.push(myApp.translations[`day-calendar-${e}`][0])}dateRangePicker=new window.DateRangePicker("datetimerange-input1",{minDate:moment().startOf("hour"),cancelButtonClasses:"hide-cancel-button",applyButtonClasses:"hide-apply-button",opens:"left",drops:["down"],startDate:myApp.searchParams&&myApp.searchParams.startDate||myApp.defaultDate&&myApp.defaultDate.from&&myApp.defaultDate.from.date,endDate:currentSelection.endDate||myApp.searchParams&&myApp.searchParams.endDate||myApp.defaultDate&&myApp.defaultDate.to&&myApp.defaultDate.to.date,alwaysShowCalendars:!0,autoApply:!0,numberOfMonths:n>800?0:24,locale:{format:"YYYYMMDD",separator:!1,applyLabel:myApp.translations["close-calendar"],cancelLabel:"X",firstDay:1,monthNames:a,daysOfWeek:o}},function(e,t){document.querySelector(".daterangepicker").style="display: none;",currentSelection.startDate=e.format("YYYYMMDD"),document.getElementById("datetimerange-input1").value=formatDateToStringDayMonth(currentSelection.startDate),currentSelection.endDate=t.format("YYYYMMDD"),document.getElementById("date-input-departure").value=formatDateToStringDayMonth(currentSelection.endDate)}),document.getElementById("datetimerange-input1").value=defaultStartDate});const saturdays=[];function formatDateToStringDayMonth(e){if(!e)return;const t=`${e.slice(0,4)}-${e.slice(4,6)}-${e.slice(6,8)}`,n=new Date(t).getDay(),a=new Date(t).getDate()<10?`0${new Date(t).getDate()}`:new Date(t).getDate(),o=new Date(t).getMonth()+1<10?`0${new Date(t).getMonth()+1}`:new Date(t).getMonth()+1;return`${myApp.translations[`day-${n}`].toLowerCase()} ${a} ${myApp.translations[`month-${o-1}`].toLowerCase()}`}function onClassChange(e,t){const n=new MutationObserver(e=>{e.forEach(e=>{"attributes"===e.type&&"class"===e.attributeName&&t(e.target)})});return n.observe(e,{attributes:!0}),n.disconnect}"lokapi"===window.myApp.siteType&&(window.addEventListener("show.daterangepicker",function(e){const t=document.querySelector(".drp-selected");document.querySelectorAll("td.available[data-col='5']").forEach(e=>{e.setAttribute("black-popup-content",myApp.translations["black-popup-content"])}),t.innerHTML=`${myApp.translations["saturday-calendar-catch-phrase-1"]}
${myApp.translations["saturday-calendar-catch-phrase-3"]}`,document.querySelector(".home-engine")&&!document.querySelector(".home-engine").classList.contains("calendar-open")&&document.querySelector(".home-engine").classList.add("calendar-open")}),window.addEventListener("clickNextorPrev.daterangepicker",function(e){const t=document.querySelector(".next.available"),n=document.querySelector(".prev.available"),a=[];n&&a.push(n),t&&a.push(t),setTimeout(()=>{const e=document.querySelectorAll("td.weekend.available[data-col='5']");e&&e.length&&e.forEach(e=>{e.setAttribute("black-popup-content",myApp.translations["black-popup-content"])})},500)}),window.addEventListener("hide.daterangepicker",function(e){document.getElementById("datetimerange-input1").value=formatDateToStringDayMonth(currentSelection.startDate)||defaultStartDate,document.getElementById("date-input-departure").value=formatDateToStringDayMonth(currentSelection.endDate)||defaultEndDate,document.querySelector(".home-engine")&&document.querySelector(".home-engine").classList.contains("calendar-open")&&document.querySelector(".home-engine").classList.remove("calendar-open")}),window.addEventListener("pickStartDate.daterangepicker",function(e){document.getElementById("datetimerange-input1").value=formatDateToStringDayMonth(e.detail.startDate.format("YYYYMMDD")),document.getElementById("date-input-departure").value="",setTimeout(()=>{const e=document.querySelectorAll("td.weekend.available[data-col='5']");e&&e.length&&e.forEach(e=>{e.setAttribute("black-popup-content",myApp.translations["black-popup-content"])})},100)}));const engineDiv=document.getElementById("engine");onClassChange(engineDiv,()=>{const e=document.querySelector(".daterangepicker");e&&engineDiv&&(engineDiv.classList&&engineDiv.classList.contains("mini")&&engineDiv.classList.contains("scrolled")?e.classList.add("date-range-picker-engine-mini"):e.classList&&e.classList.contains("date-range-picker-engine-mini")&&e.classList.remove("date-range-picker-engine-mini"))});