import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
import { memo } from 'react';
import { useAtomValue } from 'jotai';
import { joinWithSeparator } from '../../services/index.js';
import { TagItem } from '../TagItem/index.js';
import { OperationItem } from '../OperationItem/index.js';
import { Section } from '../common/index.js';
import { useIsExpanded } from './useIsExpanded.js';
import { SectionItem } from '../SectionItem/index.js';
import useScrollOnRender from '../ContentItems/useScrollOnRender.js';
import { isRootItem } from '../ContentItems/helpers.js';
import { ApiInfo } from '../ApiInfo/index.js';
import { layoutAtom } from '../../jotai/app.js';
const ContentComponentMap = {
    group: null,
    tag: TagItem,
    section: SectionItem,
    schema: TagItem,
    operation: OperationItem,
    root: ApiInfo,
};
function ContentItemComponent({ item, routingBasePath, children, layout: contentLayout, }) {
    const ContentComponent = ContentComponentMap[isRootItem(item) ? 'root' : item.type];
    const expandable = item.type === 'tag' && item.items.length > 0;
    const isExpanded = useIsExpanded({ item, routingBasePath });
    let ref = useScrollOnRender(item, routingBasePath);
    const layout = useAtomValue(layoutAtom);
    return (_jsxs(_Fragment, { children: [ContentComponent && (_jsx(Section, { id: item.id, ref: ref, sectionId: joinWithSeparator(routingBasePath, item.id), underlined: item.type === 'operation' || item.type === 'schema', expanded: expandable && !isExpanded, children: _jsx(ContentComponent, { item: item, routingBasePath: routingBasePath, isExpanded: isExpanded, layout: contentLayout || layout }) })), (isExpanded || item.type !== 'tag') && Boolean(item.items?.length) && _jsx(_Fragment, { children: children })] }));
}
export const ContentItem = memo(ContentItemComponent);
//# sourceMappingURL=ContentItem.js.map