import { Radio, Checkbox, FormControlLabel, Card, CardContent, Typography } from '@mui/material'; import { resolveReferenceFields } from './utils'; export default function SelectableCard(props) { const { getPConnect, type, image: { imagePosition, imageSize, showImageDescription, imageField = '', imageDescription = '' }, dataSource, recordKey = '', className, cardLabel, hideFieldLabels = false, readOnly, disabled, readOnlyList = [], displayMode, radioBtnValue, onChange, onBlur, onClick, onKeyDown, additionalProps, testId, setIsRadioCardSelected, showNoValue = false } = props; const pConn = getPConnect(); if (showNoValue) return No Value; const cardDataSource = readOnly || displayMode === 'DISPLAY_ONLY' ? readOnlyList || [] : dataSource?.source; const imageDescriptionKey = showImageDescription ? imageDescription : undefined; let radioItemSelected = false; return ( <> {(cardDataSource || []).map(item => { const resolvedFields = resolveReferenceFields(item, hideFieldLabels, recordKey, pConn); const commonProps = { id: item[recordKey], key: item[recordKey], fields: resolvedFields, label: item[cardLabel] }; const image = item[imageField] ? { src: item[imageField], alt: showImageDescription && imageDescriptionKey ? item[imageDescriptionKey] : '', style: { width: imageSize, objectPosition: imagePosition } } : undefined; const cardContent = ( {image && {image.alt}} {item[cardLabel]} {commonProps.fields.map((field, index) => ( {field.value} ))} ); if (displayMode === 'DISPLAY_ONLY') { return cardContent; } const component = (
{image && ( {image.alt} )}
{type === 'radio' ? ( } label={{item[cardLabel]}} /> ) : ( data[recordKey] === item[recordKey])} onChange={onChange} onBlur={onBlur} onClick={onClick} onKeyDown={onKeyDown} disabled={disabled} {...additionalProps} /> } label={{item[cardLabel]}} /> )} {commonProps.fields.map((field, index) => (
{field.name &&
{field.name}
}
{field?.value?.props.value}
))}
); if (type === 'radio' && radioBtnValue === item[recordKey]) { radioItemSelected = true; } return component; })} {type === 'radio' && setIsRadioCardSelected && setIsRadioCardSelected(radioItemSelected)} ); }