"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.createRegistry = exports.default = void 0;

var _react = require("react");

// Copyright 1999-2020. Plesk International GmbH. All rights reserved.
const RegistryContext = /*#__PURE__*/(0, _react.createContext)(undefined);
RegistryContext.displayName = 'RegistryContext';
var _default = RegistryContext;
exports.default = _default;

const createRegistry = () => ({
  stack: [],

  register(item) {
    this.stack.push(item);
  },

  unregister(item) {
    this.stack = this.stack.filter(i => i !== item);
  },

  uncompact() {
    let changed = false;
    this.stack.every(item => {
      if (item.isCompact(true)) {
        item.setCompact(false);
        changed = true;
        return false;
      }

      return true;
    });
    return changed;
  },

  compact() {
    let changed = false;
    [...this.stack].reverse().every(item => {
      if (!item.isCompact(false)) {
        item.setCompact(true);
        changed = true;
        return false;
      }

      return true;
    });
    return changed;
  },

  isCompact(one = false) {
    if (one) {
      return this.stack.some(item => item.isCompact(one));
    }

    return this.stack.every(item => item.isCompact(one));
  }

});

exports.createRegistry = createRegistry;