"use strict";

require("core-js/modules/es.symbol.js");

require("core-js/modules/es.symbol.description.js");

require("core-js/modules/es.symbol.iterator.js");

require("core-js/modules/es.array.from.js");

require("core-js/modules/es.array.slice.js");

require("core-js/modules/es.function.name.js");

exports.__esModule = true;
exports.Config = void 0;

require("core-js/modules/es.array.iterator.js");

require("core-js/modules/es.object.to-string.js");

require("core-js/modules/es.string.iterator.js");

require("core-js/modules/es.weak-map.js");

require("core-js/modules/web.dom-collections.iterator.js");

require("core-js/modules/web.dom-collections.for-each.js");

require("core-js/modules/es.object.assign.js");

require("core-js/modules/es.array.concat.js");

var _ArgumentSanitization = require("./ArgumentSanitization");

var _DateTimeDefault = require("./DateTimeDefault");

var _DateTimeHelper = require("./DateTimeHelper");

var _ChooseAddressMappingPolicy = require("./DependencyGraph/AddressMapping/ChooseAddressMappingPolicy");

var _errors = require("./errors");

var _format = require("./format/format");

var _licenseKeyValidator = require("./helpers/licenseKeyValidator");

var _HyperFormula = require("./HyperFormula");

function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }

function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }

function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }

function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }

function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }

function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }

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, descriptor.key, descriptor); } }

function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }

var PossibleGPUModeString = ['gpu', 'cpu', 'dev'];
var privatePool = new WeakMap();

var Config = /*#__PURE__*/function () {
  function Config() {
    var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
        accentSensitive = _ref.accentSensitive,
        binarySearchThreshold = _ref.binarySearchThreshold,
        caseSensitive = _ref.caseSensitive,
        caseFirst = _ref.caseFirst,
        chooseAddressMappingPolicy = _ref.chooseAddressMappingPolicy,
        currencySymbol = _ref.currencySymbol,
        dateFormats = _ref.dateFormats,
        decimalSeparator = _ref.decimalSeparator,
        evaluateNullToZero = _ref.evaluateNullToZero,
        functionArgSeparator = _ref.functionArgSeparator,
        functionPlugins = _ref.functionPlugins,
        gpujs = _ref.gpujs,
        gpuMode = _ref.gpuMode,
        ignorePunctuation = _ref.ignorePunctuation,
        leapYear1900 = _ref.leapYear1900,
        localeLang = _ref.localeLang,
        language = _ref.language,
        licenseKey = _ref.licenseKey,
        matchWholeCell = _ref.matchWholeCell,
        arrayColumnSeparator = _ref.arrayColumnSeparator,
        arrayRowSeparator = _ref.arrayRowSeparator,
        maxRows = _ref.maxRows,
        maxColumns = _ref.maxColumns,
        nullYear = _ref.nullYear,
        nullDate = _ref.nullDate,
        parseDateTime = _ref.parseDateTime,
        precisionEpsilon = _ref.precisionEpsilon,
        precisionRounding = _ref.precisionRounding,
        stringifyDateTime = _ref.stringifyDateTime,
        stringifyDuration = _ref.stringifyDuration,
        smartRounding = _ref.smartRounding,
        timeFormats = _ref.timeFormats,
        thousandSeparator = _ref.thousandSeparator,
        useArrayArithmetic = _ref.useArrayArithmetic,
        useStats = _ref.useStats,
        undoLimit = _ref.undoLimit,
        useColumnIndex = _ref.useColumnIndex,
        useRegularExpressions = _ref.useRegularExpressions,
        useWildcards = _ref.useWildcards;

    _classCallCheck(this, Config);

    this.useArrayArithmetic = (0, _ArgumentSanitization.configValueFromParam)(useArrayArithmetic, 'boolean', 'useArrayArithmetic');
    this.accentSensitive = (0, _ArgumentSanitization.configValueFromParam)(accentSensitive, 'boolean', 'accentSensitive');
    this.caseSensitive = (0, _ArgumentSanitization.configValueFromParam)(caseSensitive, 'boolean', 'caseSensitive');
    this.caseFirst = (0, _ArgumentSanitization.configValueFromParam)(caseFirst, ['upper', 'lower', 'false'], 'caseFirst');
    this.ignorePunctuation = (0, _ArgumentSanitization.configValueFromParam)(ignorePunctuation, 'boolean', 'ignorePunctuation');
    this.chooseAddressMappingPolicy = chooseAddressMappingPolicy !== null && chooseAddressMappingPolicy !== void 0 ? chooseAddressMappingPolicy : Config.defaultConfig.chooseAddressMappingPolicy;
    this.dateFormats = _toConsumableArray((0, _ArgumentSanitization.configValueFromParamCheck)(dateFormats, Array.isArray, 'array', 'dateFormats'));
    this.timeFormats = _toConsumableArray((0, _ArgumentSanitization.configValueFromParamCheck)(timeFormats, Array.isArray, 'array', 'timeFormats'));
    this.functionArgSeparator = (0, _ArgumentSanitization.configValueFromParam)(functionArgSeparator, 'string', 'functionArgSeparator');
    this.decimalSeparator = (0, _ArgumentSanitization.configValueFromParam)(decimalSeparator, ['.', ','], 'decimalSeparator');
    this.language = (0, _ArgumentSanitization.configValueFromParam)(language, 'string', 'language');
    this.licenseKey = (0, _ArgumentSanitization.configValueFromParam)(licenseKey, 'string', 'licenseKey');
    this.thousandSeparator = (0, _ArgumentSanitization.configValueFromParam)(thousandSeparator, ['', ',', ' ', '.'], 'thousandSeparator');
    this.arrayColumnSeparator = (0, _ArgumentSanitization.configValueFromParam)(arrayColumnSeparator, [',', ';'], 'arrayColumnSeparator');
    this.arrayRowSeparator = (0, _ArgumentSanitization.configValueFromParam)(arrayRowSeparator, [';', '|'], 'arrayRowSeparator');
    this.localeLang = (0, _ArgumentSanitization.configValueFromParam)(localeLang, 'string', 'localeLang');
    this.functionPlugins = _toConsumableArray(functionPlugins !== null && functionPlugins !== void 0 ? functionPlugins : Config.defaultConfig.functionPlugins);
    this.gpujs = gpujs !== null && gpujs !== void 0 ? gpujs : Config.defaultConfig.gpujs;
    this.gpuMode = (0, _ArgumentSanitization.configValueFromParam)(gpuMode, PossibleGPUModeString, 'gpuMode');
    this.smartRounding = (0, _ArgumentSanitization.configValueFromParam)(smartRounding, 'boolean', 'smartRounding');
    this.evaluateNullToZero = (0, _ArgumentSanitization.configValueFromParam)(evaluateNullToZero, 'boolean', 'evaluateNullToZero');
    this.nullYear = (0, _ArgumentSanitization.configValueFromParam)(nullYear, 'number', 'nullYear');
    (0, _ArgumentSanitization.validateNumberToBeAtLeast)(this.nullYear, 'nullYear', 0);
    (0, _ArgumentSanitization.validateNumberToBeAtMost)(this.nullYear, 'nullYear', 100);
    this.precisionRounding = (0, _ArgumentSanitization.configValueFromParam)(precisionRounding, 'number', 'precisionRounding');
    (0, _ArgumentSanitization.validateNumberToBeAtLeast)(this.precisionRounding, 'precisionRounding', 0);
    this.precisionEpsilon = (0, _ArgumentSanitization.configValueFromParam)(precisionEpsilon, 'number', 'precisionEpsilon');
    (0, _ArgumentSanitization.validateNumberToBeAtLeast)(this.precisionEpsilon, 'precisionEpsilon', 0);
    this.useColumnIndex = (0, _ArgumentSanitization.configValueFromParam)(useColumnIndex, 'boolean', 'useColumnIndex');
    this.useStats = (0, _ArgumentSanitization.configValueFromParam)(useStats, 'boolean', 'useStats');
    this.binarySearchThreshold = (0, _ArgumentSanitization.configValueFromParam)(binarySearchThreshold, 'number', 'binarySearchThreshold');
    (0, _ArgumentSanitization.validateNumberToBeAtLeast)(this.binarySearchThreshold, 'binarySearchThreshold', 1);
    this.parseDateTime = (0, _ArgumentSanitization.configValueFromParam)(parseDateTime, 'function', 'parseDateTime');
    this.stringifyDateTime = (0, _ArgumentSanitization.configValueFromParam)(stringifyDateTime, 'function', 'stringifyDateTime');
    this.stringifyDuration = (0, _ArgumentSanitization.configValueFromParam)(stringifyDuration, 'function', 'stringifyDuration');
    this.translationPackage = _HyperFormula.HyperFormula.getLanguage(this.language);
    this.errorMapping = this.translationPackage.buildErrorMapping();
    this.nullDate = (0, _ArgumentSanitization.configValueFromParamCheck)(nullDate, _DateTimeHelper.instanceOfSimpleDate, 'IDate', 'nullDate');
    this.leapYear1900 = (0, _ArgumentSanitization.configValueFromParam)(leapYear1900, 'boolean', 'leapYear1900');
    this.undoLimit = (0, _ArgumentSanitization.configValueFromParam)(undoLimit, 'number', 'undoLimit');
    this.useRegularExpressions = (0, _ArgumentSanitization.configValueFromParam)(useRegularExpressions, 'boolean', 'useRegularExpressions');
    this.useWildcards = (0, _ArgumentSanitization.configValueFromParam)(useWildcards, 'boolean', 'useWildcards');
    this.matchWholeCell = (0, _ArgumentSanitization.configValueFromParam)(matchWholeCell, 'boolean', 'matchWholeCell');
    (0, _ArgumentSanitization.validateNumberToBeAtLeast)(this.undoLimit, 'undoLimit', 0);
    this.maxRows = (0, _ArgumentSanitization.configValueFromParam)(maxRows, 'number', 'maxRows');
    (0, _ArgumentSanitization.validateNumberToBeAtLeast)(this.maxRows, 'maxRows', 1);
    this.maxColumns = (0, _ArgumentSanitization.configValueFromParam)(maxColumns, 'number', 'maxColumns');
    this.currencySymbol = _toConsumableArray((0, _ArgumentSanitization.configValueFromParamCheck)(currencySymbol, Array.isArray, 'array', 'currencySymbol'));
    this.currencySymbol.forEach(function (val) {
      if (typeof val !== 'string') {
        throw new _errors.ExpectedValueOfTypeError('string[]', 'currencySymbol');
      }

      if (val === '') {
        throw new _errors.ConfigValueEmpty('currencySymbol');
      }
    });
    (0, _ArgumentSanitization.validateNumberToBeAtLeast)(this.maxColumns, 'maxColumns', 1);
    this.warnDeprecatedIfUsed(binarySearchThreshold, 'binarySearchThreshold', '1.1');
    privatePool.set(this, {
      licenseKeyValidityState: (0, _licenseKeyValidator.checkLicenseKeyValidity)(this.licenseKey)
    });
    (0, _ArgumentSanitization.configCheckIfParametersNotInConflict)({
      value: this.decimalSeparator,
      name: 'decimalSeparator'
    }, {
      value: this.functionArgSeparator,
      name: 'functionArgSeparator'
    }, {
      value: this.thousandSeparator,
      name: 'thousandSeparator'
    });
    (0, _ArgumentSanitization.configCheckIfParametersNotInConflict)({
      value: this.arrayRowSeparator,
      name: 'arrayRowSeparator'
    }, {
      value: this.arrayColumnSeparator,
      name: 'arrayColumnSeparator'
    });
  }
  /**
   * Proxied property to its private counterpart. This makes the property
   * as accessible as the other Config options but without ability to change the value.
   *
   * @internal
   */


  _createClass(Config, [{
    key: "licenseKeyValidityState",
    get: function get() {
      return privatePool.get(this).licenseKeyValidityState;
    }
  }, {
    key: "getConfig",
    value: function getConfig() {
      var ret = {};

      for (var key in Config.defaultConfig) {
        var val = this[key];

        if (Array.isArray(val)) {
          ret[key] = _toConsumableArray(val);
        } else {
          ret[key] = val;
        }
      }

      return ret;
    }
  }, {
    key: "mergeConfig",
    value: function mergeConfig(init) {
      var mergedConfig = Object.assign({}, this.getConfig(), init);
      return new Config(mergedConfig);
    }
  }, {
    key: "warnDeprecatedIfUsed",
    value: function warnDeprecatedIfUsed(inputValue, paramName, fromVersion, replacementName) {
      if (inputValue !== undefined) {
        if (replacementName === undefined) {
          console.warn("".concat(paramName, " option is deprecated since ").concat(fromVersion));
        } else {
          console.warn("".concat(paramName, " option is deprecated since ").concat(fromVersion, ", please use ").concat(replacementName));
        }
      }
    }
  }]);

  return Config;
}();

exports.Config = Config;
Config.defaultConfig = {
  accentSensitive: false,
  binarySearchThreshold: 20,
  currencySymbol: ['$'],
  caseSensitive: false,
  caseFirst: 'lower',
  chooseAddressMappingPolicy: new _ChooseAddressMappingPolicy.AlwaysDense(),
  dateFormats: ['DD/MM/YYYY', 'DD/MM/YY'],
  decimalSeparator: '.',
  evaluateNullToZero: false,
  functionArgSeparator: ',',
  functionPlugins: [],
  gpujs: undefined,
  gpuMode: 'gpu',
  ignorePunctuation: false,
  language: 'enGB',
  licenseKey: '',
  leapYear1900: false,
  localeLang: 'en',
  matchWholeCell: true,
  arrayColumnSeparator: ',',
  arrayRowSeparator: ';',
  maxRows: 40000,
  maxColumns: 18278,
  nullYear: 30,
  nullDate: {
    year: 1899,
    month: 12,
    day: 30
  },
  parseDateTime: _DateTimeDefault.defaultParseToDateTime,
  precisionEpsilon: 1e-13,
  precisionRounding: 14,
  smartRounding: true,
  stringifyDateTime: _format.defaultStringifyDateTime,
  stringifyDuration: _format.defaultStringifyDuration,
  timeFormats: ['hh:mm', 'hh:mm:ss.sss'],
  thousandSeparator: '',
  undoLimit: 20,
  useRegularExpressions: false,
  useWildcards: true,
  useColumnIndex: false,
  useStats: false,
  useArrayArithmetic: false
};