(()=>{"use strict";const e=["days","hours","minutes","seconds"],t={days:86400,hours:3600,minutes:60,seconds:1};function n(n){const o=Date.parse(n.getAttribute("data-end")||"");if(Number.isNaN(o))return;const s=n.getAttribute("data-expired-action")||"hide",a=n.getAttribute("data-expired-message")||"",r=n.querySelector(".flexa-countdown__timer"),d=new Map;if(e.forEach(e=>{const t=n.querySelector(`.flexa-countdown__digit[data-unit="${e}"]`);t&&d.set(e,t)}),!d.size)return;const c={days:d.has("days"),hours:d.has("hours"),minutes:d.has("minutes"),seconds:d.has("seconds")};let i=!1;const u=()=>{if(i)return;const u=o-Date.now(),l=((n,o)=>{let s=Math.max(0,Math.floor(n/1e3));const a={days:0,hours:0,minutes:0,seconds:0};for(const n of e)o[n]&&("seconds"===n?a.seconds=s:(a[n]=Math.floor(s/t[n]),s-=a[n]*t[n]));return a})(u,c);d.forEach((e,t)=>{var n;e.textContent=(n=l[t],String(Math.max(0,n)).padStart(2,"0"))}),u<=0&&(()=>{if(i=!0,"hide"!==s){if("message"===s){r&&(r.hidden=!0);const e=document.createElement("div");e.className="flexa-countdown__message",e.textContent=a,n.appendChild(e)}}else n.style.display="none"})()};if(u(),!i){const e=window.setInterval(()=>{u(),i&&window.clearInterval(e)},1e3)}}function o(e){e.classList.add("flexa-bg-loaded"),e.removeAttribute("data-flexa-lazy-bg")}function s(){document.querySelectorAll("[data-flexa-countdown]").forEach(n);const e=document.querySelectorAll("[data-flexa-lazy-bg]");if(!e.length)return;if(void 0===window.IntersectionObserver)return void e.forEach(o);const t=new window.IntersectionObserver((e,t)=>{e.forEach(e=>{e.isIntersecting&&(o(e.target),t.unobserve(e.target))})},{rootMargin:"200px 0px"});e.forEach(e=>t.observe(e))}"loading"===document.readyState?document.addEventListener("DOMContentLoaded",s):s()})();