import dayjs from "dayjs";
import "dayjs/locale/nl";
import { getLocale, i18n } from "./i18n";
/**
 * Get relative time but prevent future timestamps from showing "in a few seconds"
 * This handles cases where server timestamps are slightly ahead of client time
 * due to clock synchronization differences or network latency
 */
export const getSafeRelativeTime = (timestamp, locale) => {
    const currentLocale = getLocale(locale);
    if (timestamp === null ||
        timestamp === undefined ||
        (typeof timestamp === "number" && timestamp === 0) ||
        (typeof timestamp === "string" && timestamp === "")) {
        return i18n.t("ui:time.unknown", { lng: currentLocale });
    }
    const now = dayjs();
    const time = dayjs(timestamp);
    const secondsAgo = now.diff(time, "second");
    // If timestamp is in the future (within reasonable bounds),
    // or less than 60 seconds ago, show it as "Just now"
    // This prevents "in a few seconds" from appearing due to clock drift
    if (time.isAfter(now) || secondsAgo < 60) {
        return i18n.t("ui:time.just_now", { lng: currentLocale });
    }
    return time.locale(currentLocale).fromNow();
};
//# sourceMappingURL=safe-relative-time.js.map
