'use client';
import { jsx as _jsx } from "react/jsx-runtime";
import { useState, useEffect, startTransition } from 'react';
export function formatElapsed(elapsedMs) {
    const totalSeconds = Math.floor(elapsedMs / 1000);
    if (totalSeconds >= 3600) {
        const hours = Math.floor(totalSeconds / 3600);
        return `${hours}h`;
    }
    const minutes = Math.floor(totalSeconds / 60);
    const seconds = totalSeconds % 60;
    return `${String(minutes).padStart(2, '0')}:${String(seconds).padStart(2, '0')}`;
}
export function ElapsedTime({ startedAt }) {
    const [elapsed, setElapsed] = useState(() => Date.now() - startedAt);
    useEffect(() => {
        const id = setInterval(() => {
            startTransition(() => setElapsed(Date.now() - startedAt));
        }, 1000);
        return () => clearInterval(id);
    }, [startedAt]);
    return (_jsx("span", { "data-testid": "elapsed-time", className: "tabular-nums", children: formatElapsed(elapsed) }));
}
