"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.RichTreeViewItems = RichTreeViewItems;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
var React = _interopRequireWildcard(require("react"));
var _useSlotProps2 = _interopRequireDefault(require("@mui/utils/useSlotProps"));
var _TreeItem = require("../../TreeItem");
var _jsxRuntime = require("react/jsx-runtime");
const _excluded = ["ownerState"];
function WrappedTreeItem({
  slots,
  slotProps,
  label,
  id,
  itemId,
  itemsToRender
}) {
  const Item = slots?.item ?? _TreeItem.TreeItem;
  const _useSlotProps = (0, _useSlotProps2.default)({
      elementType: Item,
      externalSlotProps: slotProps?.item,
      additionalProps: {
        itemId,
        id,
        label
      },
      ownerState: {
        itemId,
        label
      }
    }),
    itemProps = (0, _objectWithoutPropertiesLoose2.default)(_useSlotProps, _excluded);
  const children = React.useMemo(() => itemsToRender ? /*#__PURE__*/(0, _jsxRuntime.jsx)(RichTreeViewItems, {
    itemsToRender: itemsToRender,
    slots: slots,
    slotProps: slotProps
  }) : null, [itemsToRender, slots, slotProps]);
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(Item, (0, _extends2.default)({}, itemProps, {
    children: children
  }));
}
function RichTreeViewItems(props) {
  const {
    itemsToRender,
    slots,
    slotProps
  } = props;
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(React.Fragment, {
    children: itemsToRender.map(item => /*#__PURE__*/(0, _jsxRuntime.jsx)(WrappedTreeItem, {
      slots: slots,
      slotProps: slotProps,
      label: item.label,
      id: item.id,
      itemId: item.itemId,
      itemsToRender: item.children
    }, item.itemId))
  });
}