/*
* Copyright 2025 Commonwealth Scientific and Industrial Research
* Organisation (CSIRO) ABN 41 687 119 230.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import React from 'react';
import type { QuestionnaireItem, QuestionnaireResponseItem } from 'fhir/r4';
import type {
PropsWithFeedbackFromParentAttribute,
PropsWithIsRepeatedAttribute,
PropsWithIsTabledAttribute,
PropsWithParentIsReadOnlyAttribute,
PropsWithParentStylesAttribute,
PropsWithQrItemChangeHandler
} from '../../../interfaces/renderProps.interface';
import SingleItemSwitcher from './SingleItemSwitcher';
import SingleNestedItems from './SingleNestedItems';
import { GroupCard } from '../GroupItem/GroupItem.styles';
import { QGroupContainerBox } from '../../Box.styles';
import { getGroupCollapsible } from '../../../utils/qItem';
import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
import AccordionDetails from '@mui/material/AccordionDetails';
import StopPropagationWrapper from './StopPropagationWrapper';
import {
NestedSingleItemAccordion,
NestedSingleItemAccordionSummary,
NestedSingleItemAccordionWrapper
} from './NestedSingleItemAccordion.styles';
import useReadOnly from '../../../hooks/useReadOnly';
import Box from '@mui/material/Box';
import useRenderingExtensions from '../../../hooks/useRenderingExtensions';
import { useRendererConfigStore } from '../../../stores';
interface SingleItemViewProps
extends PropsWithQrItemChangeHandler,
PropsWithIsRepeatedAttribute,
PropsWithIsTabledAttribute,
PropsWithParentIsReadOnlyAttribute,
PropsWithFeedbackFromParentAttribute,
PropsWithParentStylesAttribute {
qItem: QuestionnaireItem;
qrItem: QuestionnaireResponseItem | null;
itemIsHidden: boolean;
itemHasNestedItems: boolean;
groupCardElevation: number;
onQrItemChangeWithNestedItems: (qrItem: QuestionnaireResponseItem) => void;
}
function SingleItemView(props: SingleItemViewProps) {
const {
qItem,
qrItem,
itemIsHidden,
itemHasNestedItems,
isRepeated,
isTabled,
groupCardElevation,
parentIsReadOnly,
feedbackFromParent,
parentStyles,
onQrItemChange,
onQrItemChangeWithNestedItems
} = props;
const readOnly = useReadOnly(qItem, parentIsReadOnly);
const renderingExtensions = useRenderingExtensions(qItem);
const groupCollapsibleValue = getGroupCollapsible(qItem);
const rendererStrings = useRendererConfigStore.use.rendererStrings();
// Item hidden, do not render
if (itemIsHidden) {
return null;
}
// Item has nested items and is collapsible
if (itemHasNestedItems && groupCollapsibleValue) {
const isDefaultOpen = groupCollapsibleValue === 'default-open';
return (
}>
{/* This box with marginRight:"24px" below is to align the parent item with the nested child items (due to space taken by the expand button */}
);
}
// Item has nested items but is not collapsible
if (itemHasNestedItems) {
return (
);
}
return (
);
}
export default SingleItemView;