"use strict";

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

class ToolbarItem extends _react.Component {
  constructor() {
    super(...arguments);
    (0, _defineProperty2.default)(this, "state", {
      compact: false
    });
  }
  componentDidMount() {
    const registry = this.context;
    registry.register(this);
  }
  componentWillUnmount() {
    const registry = this.context;
    registry.unregister(this);
  }
  isCompact() {
    return this.state.compact;
  }
  setCompact(compact) {
    this.setState({
      compact
    });
  }
  render() {
    const {
      children
    } = this.props;
    const {
      compact
    } = this.state;
    return /*#__PURE__*/(0, _jsxRuntime.jsx)(_ResponsiveContext.default.Provider, {
      value: compact,
      children: children
    });
  }
}
ToolbarItem.contextType = _RegistryContext.default;
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;