/*! UIkit 3.20.4-dev.c54f44b4f | https://www.getuikit.com | (c) 2014 - 2024 YOOtheme | MIT License */import{addClass as d,attr as h,toFloat as l,trigger as s,$ as c,html as p}from"uikit-util";var u={connected(){d(this.$el,this.$options.id)}};const m=["days","hours","minutes","seconds"];var o={mixins:[u],props:{date:String,clsWrapper:String,role:String},data:{date:"",clsWrapper:".uk-countdown-%unit%",role:"timer"},connected(){h(this.$el,"role",this.role),this.date=l(Date.parse(this.$props.date)),this.end=!1,this.start()},disconnected(){this.stop()},events:{name:"visibilitychange",el:()=>document,handler(){document.hidden?this.stop():this.start()}},methods:{start(){this.stop(),this.update(),this.timer||(s(this.$el,"countdownstart"),this.timer=setInterval(this.update,1e3))},stop(){this.timer&&(clearInterval(this.timer),s(this.$el,"countdownstop"),this.timer=null)},update(){const n=f(this.date);n.total||(this.stop(),this.end||(s(this.$el,"countdownend"),this.end=!0));for(const e of m){const i=c(this.clsWrapper.replace("%unit%",e),this.$el);if(!i)continue;let t=String(Math.trunc(n[e]));t=t.length<2?`0${t}`:t,i.textContent!==t&&(t=t.split(""),t.length!==i.children.length&&p(i,t.map(()=>"<span></span>").join("")),t.forEach((a,r)=>i.children[r].textContent=a))}}}};function f(n){const e=Math.max(0,n-Date.now())/1e3;return{total:e,seconds:e%60,minutes:e/60%60,hours:e/60/60%24,days:e/60/60/24}}typeof window<"u"&&window.UIkit&&window.UIkit.component("countdown",o);export{o as default};
