import _extends from "@babel/runtime/helpers/esm/extends";
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
const _excluded = ["ownerState"];
import * as React from 'react';
import useSlotProps from '@mui/utils/useSlotProps';
import { TreeItem } from "../../TreeItem/index.js";
import { jsx as _jsx } from "react/jsx-runtime";
function WrappedTreeItem({
  slots,
  slotProps,
  label,
  id,
  itemId,
  itemsToRender
}) {
  const Item = slots?.item ?? TreeItem;
  const _useSlotProps = useSlotProps({
      elementType: Item,
      externalSlotProps: slotProps?.item,
      additionalProps: {
        itemId,
        id,
        label
      },
      ownerState: {
        itemId,
        label
      }
    }),
    itemProps = _objectWithoutPropertiesLoose(_useSlotProps, _excluded);
  const children = React.useMemo(() => itemsToRender ? /*#__PURE__*/_jsx(RichTreeViewItems, {
    itemsToRender: itemsToRender,
    slots: slots,
    slotProps: slotProps
  }) : null, [itemsToRender, slots, slotProps]);
  return /*#__PURE__*/_jsx(Item, _extends({}, itemProps, {
    children: children
  }));
}
export function RichTreeViewItems(props) {
  const {
    itemsToRender,
    slots,
    slotProps
  } = props;
  return /*#__PURE__*/_jsx(React.Fragment, {
    children: itemsToRender.map(item => /*#__PURE__*/_jsx(WrappedTreeItem, {
      slots: slots,
      slotProps: slotProps,
      label: item.label,
      id: item.id,
      itemId: item.itemId,
      itemsToRender: item.children
    }, item.itemId))
  });
}