var e,t;import{Y as i,Z as s,o as a,j as m,w as o,a0 as n,h as r,I as h,l,y as u,A as c,B as d}from"./index-9bec188e.js";import{_ as T}from"./_plugin-vue_export-helper.1b428a4d.js";const f={props:{time:{type:[String,Number],default:0},format:{type:String,default:"HH:mm:ss"},autoStart:{type:Boolean,default:!0},millisecond:{type:Boolean,default:!1},...null==(t=null==(e=uni.$uv)?void 0:e.props)?void 0:t.countDown}};function p(e,t=2){let i=`${e}`;for(;i.length<t;)i=`0${i}`;return i}function g(e){return{days:Math.floor(e/864e5),hours:Math.floor(e%864e5/36e5),minutes:Math.floor(e%36e5/6e4),seconds:Math.floor(e%6e4/1e3),milliseconds:Math.floor(e%1e3)}}const y=T({name:"uv-count-down",mixins:[i,s,f],data:()=>({timer:null,timeData:g(0),formattedTime:"0",runing:!1,endTime:0,remainTime:0}),watch:{time(e){this.reset()}},mounted(){this.init()},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 e=this.getRemainTime();var t,i;t=e,i=this.remainTime,(Math.floor(t/1e3)!==Math.floor(i/1e3)||0===e)&&this.setRemainTime(e),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(e){this.remainTime=e;const t=g(e);this.$emit("change",t),this.formattedTime=function(e,t){let{days:i,hours:s,minutes:a,seconds:m,milliseconds:o}=t;return-1===e.indexOf("DD")?s+=24*i:e=e.replace("DD",p(i)),-1===e.indexOf("HH")?a+=60*s:e=e.replace("HH",p(s)),-1===e.indexOf("mm")?m+=60*a:e=e.replace("mm",p(a)),-1===e.indexOf("ss")?o+=1e3*m:e=e.replace("ss",p(m)),e.replace("SSS",p(o,3))}(this.format,t),e<=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}},beforeDestroy(){this.clearTimeout()}},[["render",function(e,t,i,s,T,f){const p=c,g=d;return a(),m(g,{class:"uv-count-down",style:u([e.$uv.addStyle(e.customStyle)])},{default:o((()=>[n(e.$slots,"default",{},(()=>[r(p,{class:"uv-count-down__text"},{default:o((()=>[h(l(T.formattedTime),1)])),_:1})]),!0)])),_:3},8,["style"])}],["__scopeId","data-v-fa107fc1"]]);export{y as _};
