"use strict";const e=require("../../../../common/vendor.js"),o=require("../common/util.js"),t=require("./useRaf.js");exports.useCountDown=function(n){let a,r;const{start:s,cancel:u}=t.useRaf((function(){n.millisecond?r&&(h(c()),l.value>0&&s()):(()=>{if(r){const t=c();e=t,o=l.value,(Math.floor(e/1e3)!==Math.floor(o/1e3)||0===t)&&h(t),l.value>0&&s()}var e,o})()})),l=e.ref(n.time),i=e.computed((()=>{return{total:e=l.value,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)};var e})),f=()=>{r=!1,u()},c=()=>Math.max(a-Date.now(),0),h=e=>{l.value=e,o.isDef(n.onChange)&&n.onChange(i.value),0===e&&(f(),o.isDef(n.onFinish)&&n.onFinish())};return e.onBeforeUnmount(f),{start:()=>{r||(a=Date.now()+l.value,r=!0,s())},pause:f,reset:(e=n.time)=>{f(),l.value=e},current:i}};
