"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.toToolbarItems = void 0;
var _react = require("react");
var _classnames = _interopRequireDefault(require("classnames"));
var _constants = require("../../constants");
var _ResponsiveContext = _interopRequireDefault(require("../ResponsiveContext"));
var _ToolbarGroup = _interopRequireDefault(require("./ToolbarGroup"));
var _ToolbarExpander = _interopRequireDefault(require("./ToolbarExpander"));
var _RegistryContext = require("./RegistryContext");
var _jsxRuntime = require("react/jsx-runtime");
// Copyright 1999-2023. Plesk International GmbH. All rights reserved.

const ToolbarItem = _ref => {
  let {
    children
  } = _ref;
  const [isCompact] = (0, _RegistryContext.useRegistryItem)();
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_ResponsiveContext.default.Provider, {
    value: isCompact,
    children: children
  });
};
const toToolbarItems = children => _react.Children.map(children, child => {
  if (! /*#__PURE__*/(0, _react.isValidElement)(child)) {
    return child;
  }
  if (child.type === _ToolbarGroup.default || child.type === _ToolbarExpander.default) {
    return child;
  }
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(ToolbarItem, {
    children: /*#__PURE__*/(0, _react.cloneElement)(child, {
      className: (0, _classnames.default)(child.props.className, `${_constants.CLS_PREFIX}toolbar__group-item`)
    })
  });
});
exports.toToolbarItems = toToolbarItems;