"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const h=require("dayjs"),r=require("vue"),b=require("./utils.js");function s(n,u){const t=Math.abs(n-u),e={diffMs:t,type:n<u?"ago":"late",diffFormatted:b.formatDuration(t)};return t<60*1e3?(e.unit="s",e.count=Math.round(t/1e3)):t<3600*1e3?(e.unit="m",e.count=Math.round(t/(60*1e3))):t<1440*60*1e3?(e.unit="h",e.count=Math.round(t/(3600*1e3))):t<720*60*60*1e3?(e.unit="d",e.count=Math.round(t/(1440*60*1e3))):t<365*24*60*60*1e3?(e.unit="M",e.count=Math.round(t/(720*60*60*1e3))):(e.unit="y",e.count=Math.round(t/365/(1440*60*1e3))),e}function i(n){return h(n).valueOf()}let p=1;function v(){return p++}const o=new Map;let l,c;function M(n,u){o.set(n,u),o.size&&!c&&(clearInterval(l),l=setInterval(()=>{c=!0;const t=Date.now();o.forEach(e=>{e.interval&&Math.abs(t-e.updated-e.interval)<50&&(e.timeAgo.value=s(e.ts,t),e.updated=t)})},5e3))}function m(n){o.delete(n),o.size||(clearInterval(l),c=!1)}const T=(n,u,t)=>{const e=v(),a=r.ref(s(i(n.value),i(u))),f={ts:i(n.value),timeAgo:a,interval:t.value,updated:Date.now()};return r.watch(()=>n.value,g=>{const d=i(g);f.ts=d,a.value=s(d,i(u))}),M(e,f),r.onBeforeUnmount(()=>{m(e)}),a};exports.default=T;exports.getId=v;exports.getTimeAgo=s;exports.subscribe=M;exports.unsubscribe=m;
