import { ctw } from '../../../../common/utils/ctw/ctw'; import { checkIsUrl, isObject } from '@ballerine/common'; import { FunctionComponent } from 'react'; import { INestedComponentProps } from './interfaces'; import { keyFactory } from '../../../../common/utils/key-factory/key-factory'; import { camelCaseToSpace } from '../../../../common/utils/camel-case-to-space/camel-case-to-space'; import { NestedContainer } from './NestedContainer'; import { handleNestedValue } from './handle-nested-value'; import { buttonVariants } from '../../../../common/components/atoms/Button/Button'; export const NestedComponent: FunctionComponent = ({ id, value, isNested = false, }) => { if (!value?.data?.length) return; return ( {value?.data?.map(({ title, value, showNull, showUndefined, anchorUrls }) => { const Component = anchorUrls && checkIsUrl(value) ? 'a' : 'p'; return (

{camelCaseToSpace(title)}

{isObject(value) && ( ({ title, value, showUndefined, showNull, anchorUrls, })), }} /> )} {Array.isArray(value) && value?.map((item, index) => { if (isObject(item)) { return ( ({ title, value, showUndefined, showNull, anchorUrls, })), }} /> ); } if (Array.isArray(item)) { return ( ({ title: 'Custom Property', value: item, showUndefined, showNull, anchorUrls, })), }} /> ); } if (!isObject(item) && !Array.isArray(item)) { return ( {handleNestedValue({ value, showUndefined, showNull })} ); } })} {!isObject(value) && !Array.isArray(value) && ( {handleNestedValue({ value, showUndefined, showNull })} )}
); })}
); };