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.object.to-string.js";
import "core-js/modules/es.array.includes.js";
import "core-js/modules/es.string.includes.js";
import "core-js/modules/es.symbol.iterator.js";
import "core-js/modules/es.array.iterator.js";
import "core-js/modules/es.string.iterator.js";
import "core-js/modules/web.dom-collections.iterator.js";
import "core-js/modules/es.symbol.js";
import "core-js/modules/es.symbol.description.js";
import "core-js/modules/es.symbol.to-primitive.js";
import "core-js/modules/es.date.to-primitive.js";
import "core-js/modules/es.number.constructor.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); }
/**
 * The SelectionRange class is a simple CellRanges collection designed for easy manipulation of the multiple
 * consecutive and non-consecutive selections.
 *
 * @class SelectionRange
 * @util
 */
var SelectionRange = /*#__PURE__*/function (_Symbol$iterator) {
  function SelectionRange(createCellRange) {
    _classCallCheck(this, SelectionRange);
    /**
     * List of all CellRanges added to the class instance.
     *
     * @type {CellRange[]}
     */
    this.ranges = [];
    this.createCellRange = createCellRange;
  }

  /**
   * Check if selected range is empty.
   *
   * @returns {boolean}
   */
  _createClass(SelectionRange, [{
    key: "isEmpty",
    value: function isEmpty() {
      return this.size() === 0;
    }

    /**
     * Set coordinates to the class instance. It clears all previously added coordinates and push `coords`
     * to the collection.
     *
     * @param {CellCoords} coords The CellCoords instance with defined visual coordinates.
     * @returns {SelectionRange}
     */
  }, {
    key: "set",
    value: function set(coords) {
      this.clear();
      this.ranges.push(this.createCellRange(coords));
      return this;
    }

    /**
     * Add coordinates to the class instance. The new coordinates are added to the end of the range collection.
     *
     * @param {CellCoords} coords The CellCoords instance with defined visual coordinates.
     * @returns {SelectionRange}
     */
  }, {
    key: "add",
    value: function add(coords) {
      this.ranges.push(this.createCellRange(coords));
      return this;
    }

    /**
     * Removes from the stack the last added coordinates.
     *
     * @returns {SelectionRange}
     */
  }, {
    key: "pop",
    value: function pop() {
      this.ranges.pop();
      return this;
    }

    /**
     * Get last added coordinates from ranges, it returns a CellRange instance.
     *
     * @returns {CellRange|undefined}
     */
  }, {
    key: "current",
    value: function current() {
      return this.peekByIndex(this.size() - 1);
    }

    /**
     * Get previously added coordinates from ranges, it returns a CellRange instance.
     *
     * @returns {CellRange|undefined}
     */
  }, {
    key: "previous",
    value: function previous() {
      return this.peekByIndex(this.size() - 2);
    }

    /**
     * Returns `true` if coords is within selection coords. This method iterates through all selection layers to check if
     * the coords object is within selection range.
     *
     * @param {CellCoords} coords The CellCoords instance with defined visual coordinates.
     * @returns {boolean}
     */
  }, {
    key: "includes",
    value: function includes(coords) {
      return this.ranges.some(function (cellRange) {
        return cellRange.includes(coords);
      });
    }

    /**
     * Clear collection.
     *
     * @returns {SelectionRange}
     */
  }, {
    key: "clear",
    value: function clear() {
      this.ranges.length = 0;
      return this;
    }

    /**
     * Get count of added all coordinates added to the selection.
     *
     * @returns {number}
     */
  }, {
    key: "size",
    value: function size() {
      return this.ranges.length;
    }

    /**
     * Peek the coordinates based on the index where that coordinate resides in the collection.
     *
     * @param {number} [index=0] An index where the coordinate will be retrieved from. The index '0' gets the
     * latest range.
     * @returns {CellRange|undefined}
     */
  }, {
    key: "peekByIndex",
    value: function peekByIndex() {
      var index = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
      var cellRange;
      if (index >= 0 && index < this.size()) {
        cellRange = this.ranges[index];
      }
      return cellRange;
    }
  }, {
    key: _Symbol$iterator,
    value: function value() {
      return this.ranges[Symbol.iterator]();
    }
  }]);
  return SelectionRange;
}(Symbol.iterator);
export default SelectionRange;