"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
function _export(target, all) {
    for(var name in all)Object.defineProperty(target, name, {
        enumerable: true,
        get: Object.getOwnPropertyDescriptor(all, name).get
    });
}
_export(exports, {
    get DEFAULT_LICENSE_KEY () {
        return DEFAULT_LICENSE_KEY;
    },
    get DEFAULT_SETTINGS () {
        return DEFAULT_SETTINGS;
    },
    get getEngineSettingsOverrides () {
        return getEngineSettingsOverrides;
    },
    get getEngineSettingsWithDefaultsAndOverrides () {
        return getEngineSettingsWithDefaultsAndOverrides;
    },
    get getEngineSettingsWithOverrides () {
        return getEngineSettingsWithOverrides;
    },
    get haveEngineSettingsChanged () {
        return haveEngineSettingsChanged;
    }
});
const _formulas = require("../formulas");
const DEFAULT_LICENSE_KEY = 'internal-use-in-handsontable';
const DEFAULT_SETTINGS = {
    licenseKey: DEFAULT_LICENSE_KEY,
    useArrayArithmetic: true,
    useColumnIndex: false,
    useStats: false,
    evaluateNullToZero: true,
    precisionEpsilon: 1e-13,
    precisionRounding: 14,
    smartRounding: true,
    leapYear1900: false,
    nullDate: {
        year: 1899,
        month: 12,
        day: 30
    },
    nullYear: 30,
    dateFormats: [
        'DD/MM/YYYY',
        'DD/MM/YY'
    ],
    timeFormats: [
        'hh:mm',
        'hh:mm:ss.sss'
    ],
    matchWholeCell: true,
    useRegularExpressions: false,
    useWildcards: true,
    functionArgSeparator: ',',
    thousandSeparator: '',
    decimalSeparator: '.',
    language: 'enGB'
};
function getEngineSettingsOverrides(hotSettings) {
    return {
        maxColumns: hotSettings.maxColumns,
        maxRows: hotSettings.maxRows,
        language: hotSettings[_formulas.PLUGIN_KEY]?.language?.langCode
    };
}
/**
 * Drop `hyperformula` key from object if it exists.
 *
 * @param {object} pluginSettings Formulas plugin settings.
 * @returns {object}
 */ function cleanEngineSettings(pluginSettings) {
    return Object.keys(pluginSettings).reduce((obj, key)=>{
        if (key !== 'hyperformula') {
            obj[key] = pluginSettings[key];
        }
        return obj;
    }, {});
}
function getEngineSettingsWithDefaultsAndOverrides(hotSettings) {
    const pluginSettings = hotSettings[_formulas.PLUGIN_KEY];
    const userSettings = cleanEngineSettings(pluginSettings?.engine?.hyperformula ? pluginSettings.engine : {});
    const overrides = getEngineSettingsOverrides(hotSettings);
    return {
        ...DEFAULT_SETTINGS,
        ...userSettings,
        ...overrides
    };
}
function getEngineSettingsWithOverrides(hotSettings) {
    const pluginSettings = hotSettings[_formulas.PLUGIN_KEY];
    const userSettings = cleanEngineSettings(pluginSettings?.engine?.hyperformula ? pluginSettings.engine : {});
    const overrides = getEngineSettingsOverrides(hotSettings);
    return {
        ...userSettings,
        ...overrides
    };
}
function haveEngineSettingsChanged(currentEngineSettings, newEngineSettings) {
    return Object.keys(newEngineSettings).some((settingOption)=>{
        return newEngineSettings[settingOption] !== undefined && newEngineSettings[settingOption] !== currentEngineSettings[settingOption];
    });
}
