import{H as t,J as e,K as i,L as s,o as a,c as n,w as o,R as m,d as r,e as h,t as u,j as c,i as l}from"./index-IX2tYR8R.js";import{_ as d}from"./_plugin-vue_export-helper.BCo6x5W8.js";const T=t({props:{time:{type:[String,Number],default:()=>e.countDown.time},format:{type:String,default:()=>e.countDown.format},autoStart:{type:Boolean,default:()=>e.countDown.autoStart},millisecond:{type:Boolean,default:()=>e.countDown.millisecond}}});function f(t,e=2){let i=`${t}`;for(;i.length({timer:null,timeData:p(0),formattedTime:"0",runing:!1,endTime:0,remainTime:0}),watch:{time(t){this.reset()}},mounted(){this.init()},emits:["change","finish"],methods:{init(){this.reset()},start(){this.runing||(this.runing=!0,this.endTime=Date.now()+this.remainTime,this.toTick())},toTick(){this.millisecond?this.microTick():this.macroTick()},macroTick(){this.clearTimeout(),this.timer=setTimeout((()=>{const t=this.getRemainTime();var e,i;e=t,i=this.remainTime,(Math.floor(e/1e3)!==Math.floor(i/1e3)||0===t)&&this.setRemainTime(t),0!==this.remainTime&&this.macroTick()}),30)},microTick(){this.clearTimeout(),this.timer=setTimeout((()=>{this.setRemainTime(this.getRemainTime()),0!==this.remainTime&&this.microTick()}),50)},getRemainTime(){return Math.max(this.endTime-Date.now(),0)},setRemainTime(t){this.remainTime=t;const e=p(t);this.$emit("change",e),this.formattedTime=function(t,e){let{days:i,hours:s,minutes:a,seconds:n,milliseconds:o}=e;return-1===t.indexOf("DD")?s+=24*i:t=t.replace("DD",f(i)),-1===t.indexOf("HH")?a+=60*s:t=t.replace("HH",f(s)),-1===t.indexOf("mm")?n+=60*a:t=t.replace("mm",f(a)),-1===t.indexOf("ss")?o+=1e3*n:t=t.replace("ss",f(n)),t.replace("SSS",f(o,3))}(this.format,e),t<=0&&(this.pause(),this.$emit("finish"))},reset(){this.pause(),this.remainTime=this.time,this.setRemainTime(this.remainTime),this.autoStart&&this.start()},pause(){this.runing=!1,this.clearTimeout()},clearTimeout(){clearTimeout(this.timer),this.timer=null}},beforeUnmount(){this.clearTimeout()}},[["render",function(t,e,i,s,d,T){const f=c,p=l;return a(),n(p,{class:"u-count-down"},{default:o((()=>[m(t.$slots,"default",{},(()=>[r(f,{class:"u-count-down__text"},{default:o((()=>[h(u(d.formattedTime),1)])),_:1})]),!0)])),_:3})}],["__scopeId","data-v-0a1a6ab6"]]);export{g as _};