import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
/*
 * Copyright (c) 2023-2025 Datalayer, Inc.
 * Distributed under the terms of the Modified BSD License.
 */
import { useEffect, useMemo, useState } from 'react';
import { formatRelativeTime } from '../../utils/index.js';
/**
 * Display a live-updating relative time label (e.g. "5m ago").
 */
export function LiveRelativeTime({ value, refreshIntervalMs = 1000, fallback = '—', }) {
    const [now, setNow] = useState(() => new Date());
    useEffect(() => {
        const timer = window.setInterval(() => {
            setNow(new Date());
        }, refreshIntervalMs);
        return () => window.clearInterval(timer);
    }, [refreshIntervalMs]);
    const label = useMemo(() => formatRelativeTime(value, now), [value, now]);
    return _jsx(_Fragment, { children: label ?? fallback });
}
