import{dg as v,dq as s,dm as A}from"./index-D_pphaE2.js";var c=[60,60,24,7,365/7/12,12];function l(e){return e instanceof Date?e:!isNaN(e)||/^\d+$/.test(e)?new Date(parseInt(e)):(e=(e||"").trim().replace(/\.\d+/,"").replace(/-/,"/").replace(/-/,"/").replace(/(\d)T(\d)/,"$1 $2").replace(/Z/," UTC").replace(/([+-]\d\d):?(\d\d)/," $1$2"),new Date(e))}function T(e,r){var n=e<0?1:0;e=Math.abs(e);for(var t=e,a=0;e>=c[a]&&a<c.length;a++)e/=c[a];return e=Math.floor(e),a*=2,e>(a===0?9:1)&&(a+=1),r(e,a,t)[n].replace("%s",e.toString())}function g(e,r){var n=r?l(r):new Date;return(+n-+l(e))/1e3}function b(e){for(var r=1,n=0,t=Math.abs(e);e>=c[n]&&n<c.length;n++)e/=c[n],r*=c[n];return t=t%r,t=t?r-t:r,Math.ceil(t)}var E=function(e,r,n){var t=g(e,n&&n.relativeDate);return T(t,v(r))},D="timeago-id";function M(e){return e.getAttribute("datetime")}function R(e,r){e.setAttribute(D,r)}function h(e){return parseInt(e.getAttribute(D))}var i={},u=function(e){clearTimeout(e),delete i[e]};function I(e,r,n,t){u(h(e));var a=t.relativeDate,x=t.minInterval,o=g(r,a);e.innerText=T(o,n);var f=setTimeout(function(){I(e,r,n,t)},Math.min(Math.max(b(o),x||1)*1e3,2147483647));i[f]=0,R(e,f)}function m(e){e?u(h(e)):Object.keys(i).forEach(u)}function $(e,r,n){var t=e.length?e:[e];return t.forEach(function(a){I(a,M(a),v(r),n||{})}),t}const S=e=>e instanceof Date?`${e.toISOString()}`:`${e}`,_=({datetime:e,locale:r,opts:n})=>{const t=s.useRef(null);return s.useEffect(()=>{if(t.current)return m(t.current),t.current.setAttribute("datetime",S(e)),$(t.current,r,n),()=>{t.current&&m(t.current)}},[e,r,n]),A.jsx("time",{ref:t,children:E(e,r,n)})};export{_ as T};
