import { checkIsIsoDate, checkIsUrl, isNullish, isObject } from '@ballerine/common'; import { BallerineLink, checkIsDate, JsonDialog, TextWithNAFallback } from '@ballerine/ui'; import { isValidDatetime } from '@/common/utils/is-valid-datetime'; import { Checkbox_ } from '@/common/components/atoms/Checkbox_/Checkbox_'; import { FunctionComponent } from 'react'; import dayjs from 'dayjs'; import { FileJson2 } from 'lucide-react'; import { ExtendedJson } from '@/common/types'; import { ctw } from '@/common/utils/ctw/ctw'; export const ReadOnlyDetail: FunctionComponent<{ children: ExtendedJson; parse?: { date?: boolean; isoDate?: boolean; datetime?: boolean; boolean?: boolean; url?: boolean; nullish?: boolean; }; className?: string; }> = ({ children, parse, className, ...props }) => { if (Array.isArray(children) || isObject(children)) { return (
} dialogButtonText={`View Information`} json={JSON.stringify(children)} />
); } if (parse?.datetime && isValidDatetime(children)) { const value = children.endsWith(':00') ? children : `${children}:00`; return ( {dayjs(value).utc().format('DD/MM/YYYY HH:mm')} ); } if ( (parse?.date && checkIsDate(children, { isStrict: false })) || (parse?.isoDate && checkIsIsoDate(children)) ) { return ( {dayjs(children).format('DD/MM/YYYY')} ); } if (parse?.boolean && typeof children === 'boolean') { return ( ); } if (typeof children === 'boolean') { return ( {`${children}`} ); } if (parse?.url && checkIsUrl(children)) { return ( {children} ); } if (parse?.nullish && isNullish(children)) { return ( {children} ); } if (isNullish(children)) { return ( {`${children}`} ); } return ( {children} ); };