function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
import "core-js/modules/es.array.iterator.js";
import "core-js/modules/es.object.to-string.js";
import "core-js/modules/es.string.iterator.js";
import "core-js/modules/es.weak-map.js";
import "core-js/modules/web.dom-collections.iterator.js";
import "core-js/modules/es.symbol.to-primitive.js";
import "core-js/modules/es.date.to-primitive.js";
import "core-js/modules/es.symbol.js";
import "core-js/modules/es.symbol.description.js";
import "core-js/modules/es.number.constructor.js";
import "core-js/modules/es.symbol.iterator.js";
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
function _classPrivateFieldGet(receiver, privateMap) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "get"); return _classApplyDescriptorGet(receiver, descriptor); }
function _classApplyDescriptorGet(receiver, descriptor) { if (descriptor.get) { return descriptor.get.call(receiver); } return descriptor.value; }
function _classPrivateFieldSet(receiver, privateMap, value) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "set"); _classApplyDescriptorSet(receiver, descriptor, value); return value; }
function _classExtractFieldDescriptor(receiver, privateMap, action) { if (!privateMap.has(receiver)) { throw new TypeError("attempted to " + action + " private field on non-instance"); } return privateMap.get(receiver); }
function _classApplyDescriptorSet(receiver, descriptor, value) { if (descriptor.set) { descriptor.set.call(receiver, value); } else { if (!descriptor.writable) { throw new TypeError("attempted to set read only private field"); } descriptor.value = value; } }
import AxisSyncer from "./axisSyncer.mjs";
/**
 * @private
 * @class IndexSyncer
 * @description
 *
 * Indexes synchronizer responsible for providing logic for syncing actions done on indexes for HOT to actions performed
 * on HF's.
 *
 */
var _rowIndexSyncer = /*#__PURE__*/new WeakMap();
var _columnIndexSyncer = /*#__PURE__*/new WeakMap();
var _postponeAction = /*#__PURE__*/new WeakMap();
var _isPerformingUndo = /*#__PURE__*/new WeakMap();
var _isPerformingRedo = /*#__PURE__*/new WeakMap();
var _engine = /*#__PURE__*/new WeakMap();
var _sheetId = /*#__PURE__*/new WeakMap();
var IndexSyncer = /*#__PURE__*/function () {
  /**
   * Indexes synchronizer for the axis of the rows.
   *
   * @private
   * @type {AxisSyncer}
   */

  /**
   * Indexes synchronizer for the axis of the columns.
   *
   * @private
   * @type {AxisSyncer}
   */

  /**
   * Method which will postpone execution of some action (needed when synchronization endpoint isn't setup yet).
   *
   * @private
   * @type {Function}
   */

  /**
   * Flag informing whether undo is already performed (we don't perform synchronization in such case).
   *
   * @private
   * @type {boolean}
   */

  /**
   * Flag informing whether redo is already performed (we don't perform synchronization in such case).
   *
   * @private
   * @type {boolean}
   */

  /**
   * The HF's engine instance which will be synced.
   *
   * @private
   * @type {HyperFormula|null}
   */

  /**
   * HyperFormula's sheet name.
   *
   * @private
   * @type {string|null}
   */

  function IndexSyncer(rowIndexMapper, columnIndexMapper, postponeAction) {
    _classCallCheck(this, IndexSyncer);
    _classPrivateFieldInitSpec(this, _rowIndexSyncer, {
      writable: true,
      value: void 0
    });
    _classPrivateFieldInitSpec(this, _columnIndexSyncer, {
      writable: true,
      value: void 0
    });
    _classPrivateFieldInitSpec(this, _postponeAction, {
      writable: true,
      value: void 0
    });
    _classPrivateFieldInitSpec(this, _isPerformingUndo, {
      writable: true,
      value: false
    });
    _classPrivateFieldInitSpec(this, _isPerformingRedo, {
      writable: true,
      value: false
    });
    _classPrivateFieldInitSpec(this, _engine, {
      writable: true,
      value: null
    });
    _classPrivateFieldInitSpec(this, _sheetId, {
      writable: true,
      value: null
    });
    _classPrivateFieldSet(this, _rowIndexSyncer, new AxisSyncer('row', rowIndexMapper, this));
    _classPrivateFieldSet(this, _columnIndexSyncer, new AxisSyncer('column', columnIndexMapper, this));
    _classPrivateFieldSet(this, _postponeAction, postponeAction);
  }

  /**
   * Gets index synchronizer for a particular axis.
   *
   * @param {'row'|'column'} indexType Type of indexes.
   * @returns {AxisSyncer}
   */
  _createClass(IndexSyncer, [{
    key: "getForAxis",
    value: function getForAxis(indexType) {
      if (indexType === 'row') {
        return _classPrivateFieldGet(this, _rowIndexSyncer);
      }
      return _classPrivateFieldGet(this, _columnIndexSyncer);
    }

    /**
     * Sets flag informing whether an undo action is already performed (we don't execute synchronization in such case).
     *
     * @param {boolean} flagValue Boolean value for the flag.
     */
  }, {
    key: "setPerformUndo",
    value: function setPerformUndo(flagValue) {
      _classPrivateFieldSet(this, _isPerformingUndo, flagValue);
    }

    /**
     * Sets flag informing whether a redo action is already performed (we don't execute synchronization in such case).
     *
     * @param {boolean} flagValue Boolean value for the flag.
     */
  }, {
    key: "setPerformRedo",
    value: function setPerformRedo(flagValue) {
      _classPrivateFieldSet(this, _isPerformingRedo, flagValue);
    }

    /**
     * Gets information whether redo or undo action is already performed (we don't execute synchronization in such case).
     *
     * @private
     * @returns {boolean}
     */
  }, {
    key: "isPerformingUndoRedo",
    value: function isPerformingUndoRedo() {
      return _classPrivateFieldGet(this, _isPerformingUndo) || _classPrivateFieldGet(this, _isPerformingRedo);
    }

    /**
     * Gets HyperFormula's sheet id.
     *
     * @returns {string|null}
     */
  }, {
    key: "getSheetId",
    value: function getSheetId() {
      return _classPrivateFieldGet(this, _sheetId);
    }

    /**
     * Gets engine instance that will be used for handled instance of Handsontable.
     *
     * @type {HyperFormula|null}
     */
  }, {
    key: "getEngine",
    value: function getEngine() {
      return _classPrivateFieldGet(this, _engine);
    }

    /**
     * Gets method which will postpone execution of some action (needed when synchronization endpoint isn't setup yet).
     *
     * @returns {Function}
     */
  }, {
    key: "getPostponeAction",
    value: function getPostponeAction() {
      return _classPrivateFieldGet(this, _postponeAction);
    }

    /**
     * Setups a synchronization endpoint.
     *
     * @param {HyperFormula|null} engine The HF's engine instance which will be synced.
     * @param {string|null} sheetId HyperFormula's sheet name.
     */
  }, {
    key: "setupSyncEndpoint",
    value: function setupSyncEndpoint(engine, sheetId) {
      _classPrivateFieldSet(this, _engine, engine);
      _classPrivateFieldSet(this, _sheetId, sheetId);
      _classPrivateFieldGet(this, _rowIndexSyncer).init();
      _classPrivateFieldGet(this, _columnIndexSyncer).init();
    }
  }]);
  return IndexSyncer;
}();
export default IndexSyncer;