"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _react = require("react");
var _classnames = _interopRequireDefault(require("classnames"));
var _constants = require("../../constants");
var _RegistryContext = _interopRequireWildcard(require("./RegistryContext"));
var _DistractionFreeModeContext = _interopRequireDefault(require("../DistractionFreeModeContext"));
var _ToolbarItem = require("./ToolbarItem");
var _Squeezer = _interopRequireDefault(require("../Squeezer"));
var _jsxRuntime = require("react/jsx-runtime");
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
// Copyright 1999-2023. Plesk International GmbH. All rights reserved.

/**
 * `Toolbar` component is a panel containing various instruments used for managing the contents of a large content block.
 * Toolbar is located on top of the managed content block.
 * It typically consists of three main parts: controls that add new elements, controls that work with existing elements,
 * and controls for changing the way the content block looks.
 * @since 0.0.57
 */

class Toolbar extends _react.Component {
  constructor(props) {
    super(props);
    (0, _defineProperty2.default)(this, "state", {
      distractionFreeMode: {
        enabled: false,
        toggle: () => {
          this.setState(prevState => ({
            distractionFreeMode: {
              ...prevState.distractionFreeMode,
              enabled: !prevState.distractionFreeMode.enabled
            }
          }), () => {
            this.measure();
          });
        }
      }
    });
    (0, _defineProperty2.default)(this, "registry", void 0);
    (0, _defineProperty2.default)(this, "measure", void 0);
    this.registry = (0, _RegistryContext.createRegistry)();
    this.measure = () => {};
  }
  render() {
    const {
      baseClassName,
      className,
      children,
      ...props
    } = this.props;
    const toolbarItems = (0, _ToolbarItem.toToolbarItems)(children);
    return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Squeezer.default, {
      compact: () => this.registry.compact(),
      uncompact: () => this.registry.uncompact(),
      innerMeasure: measure => {
        this.measure = measure;
      },
      children: _ref => {
        let {
          ref
        } = _ref;
        return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
          ref: ref,
          className: (0, _classnames.default)(baseClassName, className),
          ...props,
          children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_RegistryContext.default.Provider, {
            value: this.registry,
            children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_DistractionFreeModeContext.default.Provider, {
              value: this.state.distractionFreeMode,
              children: toolbarItems
            })
          })
        });
      }
    });
  }
}
(0, _defineProperty2.default)(Toolbar, "defaultProps", {
  children: null,
  className: null,
  baseClassName: `${_constants.CLS_PREFIX}toolbar`
});
var _default = exports.default = Toolbar;