import{defineComponent as p,ref as u,onMounted as w,onUpdated as g,onBeforeUnmount as C,createVNode as D}from"vue";import T from"../_util/omit.mjs";import h from"../_util/props-util/initDefaultProps.mjs";import{someType as F}from"../_util/type.mjs";import R,{statisticProps as S}from"./Statistic.mjs";import{formatCountdown as E}from"./utils.mjs";const H=1e3/30;function r(n){return new Date(n).getTime()}const I=()=>({...S(),value:F([Number,String,Object]),format:String,onFinish:Function,onChange:Function}),M=p({compatConfig:{MODE:3},name:"AStatisticCountdown",props:h(I(),{format:"HH:mm:ss"}),setup(n,{emit:i,slots:c}){const e=u(),m=u(),o=()=>{const{value:t}=n;r(t)>=Date.now()?f():s()},f=()=>{if(e.value)return;const t=r(n.value);e.value=setInterval(()=>{m.value.$forceUpdate(),t>Date.now()&&i("change",t-Date.now()),o()},H)},s=()=>{const{value:t}=n;e.value&&(clearInterval(e.value),e.value=void 0,r(t)<Date.now()&&i("finish"))},l=({value:t,config:a})=>{const{format:v}=n;return E(t,{...a,format:v})},d=t=>t;return w(()=>{o()}),g(()=>{o()}),C(()=>{s()}),()=>{const t=n.value;return D(R,{ref:m,...T(n,["onFinish","onChange"]),value:t,valueRender:d,formatter:l},c)}}});export{I as countdownProps,M as default};
