import { useUiTranslation as e } from "../../../i18n/useUiTranslation.js";
import { useMemo as t } from "react";
import { jsx as n } from "react/jsx-runtime";
//#region src/atomic/atoms/relative-time-text/RelativeTimeText.tsx
var r = 1e3, i = 60 * r, a = 60 * i, o = 24 * a, s = 30 * o, c = 365 * o, l = {
	year: "numeric",
	month: "short",
	day: "numeric",
	hour: "2-digit",
	minute: "2-digit"
}, u = (e) => {
	let t = Math.abs(e);
	return t < i ? {
		value: Math.round(e / r),
		unit: "second"
	} : t < a ? {
		value: Math.round(e / i),
		unit: "minute"
	} : t < o ? {
		value: Math.round(e / a),
		unit: "hour"
	} : t < s ? {
		value: Math.round(e / o),
		unit: "day"
	} : t < c ? {
		value: Math.round(e / s),
		unit: "month"
	} : {
		value: Math.round(e / c),
		unit: "year"
	};
}, d = (e, t) => {
	try {
		return new Intl.DateTimeFormat(t, l).format(e);
	} catch {
		return;
	}
}, f = ({ className: r, fallback: i, locale: a, titleMode: o = "absolute", value: s }) => {
	let { i18n: c, t: l } = e(), f = i ?? l("common.notAvailable"), p = a ?? c.language, m = t(() => {
		if (s == null) return null;
		let e = new Date(String(s));
		return Number.isNaN(e.getTime()) ? null : e;
	}, [s]), h = t(() => {
		if (m == null) return f;
		let { unit: e, value: t } = u(m.getTime() - Date.now());
		try {
			return new Intl.RelativeTimeFormat(p, { numeric: "auto" }).format(t, e);
		} catch {
			return f;
		}
	}, [
		m,
		f,
		p
	]), g;
	return o === "absolute" && m != null && (g = d(m, p)), /* @__PURE__ */ n("span", {
		className: r,
		title: g,
		children: h
	});
}, p = {
	resolveRelativeParts: u,
	formatAbsoluteTitle: d
};
//#endregion
export { f as RelativeTimeText, f as default, p as __test };

//# sourceMappingURL=RelativeTimeText.js.map