import { Tooltip, UnstyledButton } from "@mantine/core"; import { IconClock } from "@tabler/icons-react"; import { createContext, useContext, useState, type ReactNode } from "react"; import { formatExactTime, formatRelativeTime } from "../../time.js"; const RelativeTimeClock = createContext(null); export function RelativeTimeProvider({ children, now }: { children: ReactNode; now: number }) { return {children}; } export function RelativeTime({ icon, label, value, }: { icon?: ReactNode; label: string; value: string | null | undefined; }) { const [exact, setExact] = useState(false); useContext(RelativeTimeClock); const text = exact ? formatExactTime(value) : formatRelativeTime(value); const exactText = formatExactTime(value); const unavailable = exactText === "—"; const tooltip = unavailable ? "Updated time unavailable" : exact ? formatRelativeTime(value) : exactText; return ( setExact((value) => !value)} > {icon ?? } {text} ); }