"use strict";

exports.__esModule = true;
require("core-js/modules/es.error.cause.js");
var _clipboardData = require("./clipboardData");
var _copyableRanges = require("../copyableRanges");
var _parseTable = require("../../../utils/parseTable");
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
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); }
/**
 * Creates an object containing information about copy/cut action.
 *
 * @private
 */
class CopyClipboardData extends _clipboardData.ClipboardData {
  /**
   * @param {Core} instance Handsontable instance (used only while copying data).
   * @param {Array<{startRow: number, startCol: number, endRow: number, endCol: number}>} copyableRanges Cell
   * ranges related to instance of Handsontable (used only while copying data).
   */
  constructor(instance, copyableRanges) {
    super();
    /**
     * Sanitized data of "text/html" type inside the clipboard.
     *
     * @private
     * @type {string}
     */
    _defineProperty(this, "html", void 0);
    /**
     * Copied data stored as array of arrays.
     *
     * @private
     * @type {string[][]}
     */
    _defineProperty(this, "data", void 0);
    /**
     * Copied cell ranges related to instance of Handsontable.
     *
     * @private
     * @type {Array<{startRow: number, startCol: number, endRow: number, endCol: number}>}
     */
    _defineProperty(this, "copyableRanges", void 0);
    const {
      rows,
      columns
    } = (0, _copyableRanges.normalizeRanges)(copyableRanges);
    this.html = [_clipboardData.META_HEAD, (0, _parseTable.getHTMLByCoords)(instance, {
      rows,
      columns
    })].join('');
    this.data = (0, _parseTable.getDataByCoords)(instance, {
      rows,
      columns
    });
    this.copyableRanges = copyableRanges;
  }

  /**
   * Gets ranges related to copied part of Handsontable.
   *
   * @returns {Array<{startRow: number, startCol: number, endRow: number, endCol: number}>}
   */
  getRanges() {
    return this.copyableRanges;
  }
}
exports.CopyClipboardData = CopyClipboardData;