import "core-js/modules/es.error.cause.js";
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); }
import { ClipboardData } from "./clipboardData.mjs";
import { getDataWithHeadersByConfig } from "../../../utils/parseTable.mjs";
import { parse } from "../../../3rdparty/SheetClip/index.mjs";
import { isDefined } from "../../../helpers/mixed.mjs";
/**
 * Creates an object containing information about paste action.
 *
 * @private
 */
export class PasteClipboardData extends ClipboardData {
  /**
   * @param {string} data Data of "text/plain" type inside the clipboard.
   * @param {string} html Sanitized data of "text/html" type inside the clipboard.
   */
  constructor(data, html) {
    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);
    this.html = html;
    if (this.isSerializedTable()) {
      this.data = getDataWithHeadersByConfig(this.getMetaInfo());
    } else {
      this.data = parse(data);
    }
  }

  /**
   * Checks whether pasted data is an array.
   *
   * @private
   * @returns {boolean}
   */
  isSerializedTable() {
    return isDefined(this.html) && /(<table)|(<TABLE)/g.test(this.html);
  }

  /**
   * Checks whether pasted data is a Handsontable.
   *
   * @private
   * @returns {boolean}
   */
  isSerializedHandsontable() {
    return this.isSerializedTable() && /<meta (.*?)content="Handsontable"/.test(this.html);
  }

  /**
   * Gets type of the copied data.
   *
   * @returns {'table' | 'handsontable' | 'unrecognizable'}
   */
  getType() {
    if (this.isSerializedHandsontable()) {
      return 'handsontable';
    }
    if (this.isSerializedTable()) {
      return 'table';
    }
    return 'unrecognizable';
  }
}