(()=>{"use strict";var t={n:e=>{var o=e&&e.__esModule?()=>e.default:()=>e;return t.d(o,{a:o}),o},d:(e,o)=>{for(var a in o)t.o(o,a)&&!t.o(e,a)&&Object.defineProperty(e,a,{enumerable:!0,get:o[a]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e)};const e=window.lodash;var o=t.n(e);document.addEventListener("DOMContentLoaded",(function(){const t=document.querySelector(".wpte-upcoming-tours-content-wrap"),e=document.querySelector(".wpte-dates-filter"),a=document.querySelectorAll(".wpte-filter-btn");t.addEventListener("click",(function(o){if(o.target.matches(".wpte-btn-view-details")&&(t.classList.add("loading"),s(o.target.dataset.id,o.target.dataset.nonce)(o.target)),o.target.closest(".wpte-upcoming-tours-details-close-btn")){const e=t.querySelector(".wpte-upcoming-tours-details");e&&(e.classList.remove("active"),e.remove())}const a=o.target.closest(".wpte-load-more-btn"),c=o.target.closest(".wpte-load-less-btn");if(a||c){var l;const a=e.querySelector(".wpte-filter-options").querySelector(".active"),s=parseInt(t.querySelector(".wpte-upcoming-tours-list").dataset.itemsCount),i=c?s-10:s+10,d=document.querySelector("#wpte-custom-filter-date").value,u=null!==(l=a?.dataset.date)&&void 0!==l?l:d?r(d):"all",m=document.querySelector("#status"),p=m?m.value:"all";u?n(u,e.dataset.nonce,i,p)(o.target):console.error("No trip data found")}}));const s=(e,o)=>async a=>{const s=new URLSearchParams({action:"wte_upcoming_tours_details",nonce:o,id:e}),r=`${wp.ajax.settings.url}?${s.toString()}`;try{const e=await fetch(r,{method:"GET",headers:{"Content-Type":"application/x-www-form-urlencoded"}}),o=await e.json();if(o.success){const e=o.data.html;t.innerHTML+=e,t.classList.remove("loading"),t.querySelector(".wpte-upcoming-tours-details").classList.add("active")}else console.error("Invalid HTML returned:",o)}catch(t){console.error("Error:",t)}};function r(t){if(o().isString(t)){const[e,o]=t.split(" to ");return JSON.stringify({from:e,to:o||e})}{var e;const o=t.map((t=>{const e=new Date(t);return e.setDate(e.getDate()+1),e.toISOString().split("T")[0]}));return JSON.stringify({from:o[0],to:null!==(e=o[1])&&void 0!==e?e:o[0]})}}a.forEach((t=>{t.addEventListener("click",(t=>{const{date:o}=t.target.dataset,a=e.dataset.nonce,s=e.querySelector("#wpte-custom-filter-date");s&&(s.value=""),t.target.parentElement.querySelector(".active")?.classList.remove("active"),t.target.classList.add("active");const r=document.querySelector("#status"),c=r?r.value:"all";o&&n(o,a,void 0,c)(t.target)}))})),flatpickr("#wpte-custom-filter-date",{mode:"range",showMonths:2,minDate:"today",onClose:function(t){if(o().isEmpty(t))return;const a=r(t);e.querySelector(".wpte-filter-options").querySelector(".active")?.classList.remove("active");const s=document.querySelector("#status"),c=s?s.value:"all";n(a,e.dataset.nonce,void 0,c)(document.querySelector("#wpte-custom-filter-date"))}});const n=(e,o,a,s="all")=>async r=>{r.classList.add("btn-loading"),r.disabled=!0,t.classList.add("loading");try{const n=await fetch(wp.ajax.settings.url,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({action:"wte_filter_upcoming_tours",nonce:o,date:e||"all",count:a||t.querySelector(".wpte-upcoming-tours-list").dataset.itemsCount,status:s||"all"})}),c=await n.json();if(c.success&&c.data?.html){t.innerHTML=c.data.html,t.classList.remove("loading"),r.classList.remove("btn-loading"),r.disabled=!1;const e=document.querySelector("#status");e&&s&&(e.value=s)}else console.error("Invalid HTML returned:",c),t.classList.remove("loading"),r.classList.remove("btn-loading"),r.disabled=!1}catch(e){console.error("Error:",e),t.classList.remove("loading"),r.classList.remove("btn-loading"),r.disabled=!1}}}))})();