import{ag as E}from"./ui-BXZpfH9y.js";function N(t){const n=new Date(t);if(!Number.isNaN(n.valueOf()))return n;const r=String(t).match(/\d+/g);if(r==null||r.length<=2)return n;{const[o,g,...p]=r.map(T=>parseInt(T)),M=[o,g-1,...p];return new Date(Date.UTC(...M))}}const l=(t,n,r)=>{const o=t!==1?n+"s":n;return t+" "+o+" "+r};function S(){return S=Object.assign?Object.assign.bind():function(t){for(var n=1;n<arguments.length;n++){var r=arguments[n];for(var o in r)({}).hasOwnProperty.call(r,o)&&(t[o]=r[o])}return t},S.apply(null,arguments)}const d=60,h=d*60,c=h*24,v=c*7,A=c*30,U=c*365,R=()=>Date.now();function C({date:t,formatter:n,component:r="time",live:o=!0,minPeriod:g=0,maxPeriod:p=v,title:M,now:s=R,...T}){const[O,x]=E.useState(s());E.useEffect(()=>{if(!o)return;const f=(()=>{const m=N(t).valueOf();if(!m)return console.warn("[react-timeago] Invalid Date provided"),0;const b=Math.round(Math.abs(O-m)/1e3),k=b<d?1e3:b<h?1e3*d:b<c?1e3*h:1e3*v,D=Math.min(Math.max(k,g*1e3),p*1e3);return D?setTimeout(()=>{x(s())},D):0})();return()=>{f&&clearTimeout(f)}},[t,o,p,g,s,O]),E.useEffect(()=>{x(s())},[t]);const F=r,a=N(t).valueOf();if(!a)return null;const e=Math.round(Math.abs(O-a)/1e3),y=a<O?"ago":"from now",[w,I]=e<d?[Math.round(e),"second"]:e<h?[Math.round(e/d),"minute"]:e<c?[Math.round(e/h),"hour"]:e<v?[Math.round(e/c),"day"]:e<A?[Math.round(e/v),"week"]:e<U?[Math.round(e/A),"month"]:[Math.round(e/U),"year"],j=typeof M>"u"?typeof t=="string"?t:N(t).toISOString().substring(0,16).replace("T"," "):M,H=F==="time"?{...T,dateTime:N(t).toISOString()}:T,P=(i=i,f=f,m=m,b=a,k=l,D=D)=>l(i,f,m),K=n||l;let u;try{u=K(w,I,y,a,P,s),u||(u=l(w,I,y,a,P,s))}catch(i){console.error("[react-timeago] Formatter threw an error:",i),u=l(w,I,y)}return E.createElement(F,S({},H,{title:j}),u)}export{C as T};
