// Copyright 1999-2025. WebPros International GmbH. All rights reserved.

import { isValidElement, Children, cloneElement } from 'react';
import classNames from 'classnames';
import { CLS_PREFIX } from '../../constants';
import ResponsiveContext from '../ResponsiveContext';
import ToolbarGroup from './ToolbarGroup';
import ToolbarExpander from './ToolbarExpander';
import { useRegistryItem } from './RegistryContext';
import { jsx as _jsx } from "react/jsx-runtime";
const ToolbarItem = _ref => {
  let {
    children
  } = _ref;
  const [isCompact] = useRegistryItem();
  return /*#__PURE__*/_jsx(ResponsiveContext.Provider, {
    value: isCompact,
    children: children
  });
};
export const toToolbarItems = children => Children.map(children, child => {
  if (! /*#__PURE__*/isValidElement(child)) {
    return child;
  }
  if (child.type === ToolbarGroup || child.type === ToolbarExpander) {
    return child;
  }
  return /*#__PURE__*/_jsx(ToolbarItem, {
    children: /*#__PURE__*/cloneElement(child, {
      className: classNames(child.props.className, `${CLS_PREFIX}toolbar__group-item`)
    })
  });
});