"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
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 _hooks = require("../../hooks");
var _jsxRuntime = require("react/jsx-runtime");
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
// Copyright 1999-2025. WebPros 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
 */
const Toolbar = _ref => {
  let {
    children,
    className,
    baseClassName = `${_constants.CLS_PREFIX}toolbar`,
    ...props
  } = _ref;
  const containerRef = (0, _react.useRef)(null);
  const [isDistractionFreeModeEnabled, setIsDistractionFreeModeEnabled] = (0, _react.useState)(false);
  const distractionFreeModeContextValue = (0, _react.useMemo)(() => ({
    enabled: isDistractionFreeModeEnabled,
    toggle: () => setIsDistractionFreeModeEnabled(current => !current)
  }), [isDistractionFreeModeEnabled]);
  const registry = (0, _RegistryContext.useRegistry)();
  (0, _hooks.useSqueeze)({
    ref: containerRef,
    compact: () => registry.compact(),
    expand: () => registry.expand()
  });
  const toolbarItems = (0, _ToolbarItem.toToolbarItems)(children);
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
    ref: containerRef,
    className: (0, _classnames.default)(baseClassName, className),
    ...props,
    children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_RegistryContext.default.Provider, {
      value: registry,
      children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_DistractionFreeModeContext.default.Provider, {
        value: distractionFreeModeContextValue,
        children: toolbarItems
      })
    })
  });
};
var _default = exports.default = Toolbar;