import type { StackProps } from '@chakra-ui/react'; import { createListCollection, HStack } from '@chakra-ui/react'; import React from 'react'; import { useSettingsContext } from 'lib/contexts/settings'; import dayjs from 'lib/date/dayjs'; import { IconButton } from 'toolkit/chakra/icon-button'; import type { SelectOption } from 'toolkit/chakra/select'; import { SelectContent, SelectItem, SelectRoot, SelectControl } from 'toolkit/chakra/select'; import { Skeleton } from 'toolkit/chakra/skeleton'; import { TruncatedText } from 'toolkit/components/truncation/TruncatedText'; import IconSvg from 'ui/shared/IconSvg'; import TextSeparator from 'ui/shared/TextSeparator'; const FORMAT_OPTIONS = [ { label: 'Local', value: 'local' as const }, { label: 'UTC', value: 'utc' as const }, { label: 'Unix', value: 'unix' as const }, ]; const collection = createListCollection({ items: FORMAT_OPTIONS, }); type Format = (typeof FORMAT_OPTIONS)[number]['value']; interface Props extends StackProps { timestamp: string | number; isLoading?: boolean; noRelativeTime?: boolean; }; const DetailedInfoTimestamp = ({ timestamp, isLoading, noRelativeTime, ...rest }: Props) => { const settings = useSettingsContext(); const [ format, setFormat ] = React.useState>(settings?.isLocalTime === false ? [ 'utc' ] : [ 'local' ]); const handleFormatChange = React.useCallback(({ value }: { value: Array }) => { setFormat(value as Array); }, []); const timeText = (() => { if (format.includes('local')) { return dayjs(timestamp).format('llll'); } if (format.includes('utc')) { return dayjs(timestamp).utc().format('MMM DD YYYY HH:mm:ss'); } return dayjs(timestamp).unix().toString(); })(); return ( { !noRelativeTime && ( <> { dayjs(timestamp).fromNow() } ) } { collection.items.map((item) => ( { item.label } )) } ); }; export default DetailedInfoTimestamp;