import { Fragment, Children, ReactElement } from 'react';
import { Grid, Flex, FieldGroup, withConfiguration, GridContainerProps } from '@pega/cosmos-react-core';
import type { PConnFieldProps } from './PConnProps';
import './create-nonce';
import DetailsRender from './DetailsRender';
import HighlightRender from './HighlightRender';
import StyledPegaDxilMyDetailsWrapper, { StyledDetailsGridContainer, StyledHighlightedFieldsHrLine } from './styles';
// includes in bundle
import { getAllFields } from './utils';
// interface for props
interface PegaDxilMyDetailsProps extends PConnFieldProps {
// If any, enter additional props that only exist on TextInput here
showLabel: boolean;
showHighlightedData: boolean;
children: any;
}
// props passed in combination of props from property panel (config.json) and run time props from Constellation
// any default values in config.pros should be set in defaultProps at bottom of this file
function PegaDxilMyDetails(props: PegaDxilMyDetailsProps) {
const { getPConnect, label, showLabel = true, showHighlightedData = false } = props;
const propsToUse = { label, showLabel, ...getPConnect().getInheritedProps() };
// storybook doesn't get children of 1 as an array of 1
let { children } = props;
if (!Array.isArray(children)) {
children = Children.toArray(children);
}
// update children with readonly
Children.toArray(children).forEach(child => {
// @ts-ignore
child.props.getPConnect().setInheritedProp('readOnly', true);
// @ts-ignore
child.props.getPConnect().setInheritedProp('displayMode', 'DISPLAY_ONLY');
});
const numRegions = getAllFields(getPConnect)?.length;
const gridRepeat = 'repeat('.concat(numRegions).concat(', 1fr)');
const gridContainer: GridContainerProps = { colGap: 6 };
gridContainer.cols = gridRepeat;
gridContainer.alignItems = 'start';
// Set up highlighted data to pass in return if is set to show, need raw metadata to pass to createComponent
let highlightedDataArr = [];
if (showHighlightedData) {
// @ts-ignore
const { highlightedData = [] } = getPConnect().getRawMetadata().config;
// @ts-ignore
highlightedDataArr = highlightedData.map(field => {
return ;
});
}
return (
{showHighlightedData && highlightedDataArr.length > 0 && (
<>
{highlightedDataArr.map((child: ReactElement, i: number) => (
{child}
))}
>
)}
{children.map((child: ReactElement, i: number) => (
))}
);
}
export default withConfiguration(PegaDxilMyDetails);