"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 getDateFromExcelDate () {
        return getDateFromExcelDate;
    },
    get getDateInHfFormat () {
        return getDateInHfFormat;
    },
    get getDateInHotFormat () {
        return getDateInHotFormat;
    },
    get isDate () {
        return isDate;
    },
    get isDateValid () {
        return isDateValid;
    },
    get isEscapedFormulaExpression () {
        return isEscapedFormulaExpression;
    },
    get isFormula () {
        return isFormula;
    },
    get normalizeValueForFormulaEngine () {
        return normalizeValueForFormulaEngine;
    },
    get unescapeFormulaExpression () {
        return unescapeFormulaExpression;
    }
});
const _moment = /*#__PURE__*/ _interop_require_default(require("moment"));
const _valueGetter = require("../../cellTypes/multiSelectType/accessors/valueGetter");
function _interop_require_default(obj) {
    return obj && obj.__esModule ? obj : {
        default: obj
    };
}
const DEFAULT_DATE_FORMAT_HYPERFORMULA = 'DD/MM/YYYY';
function isEscapedFormulaExpression(expression) {
    return typeof expression === 'string' && expression.charAt(0) === '\'' && expression.charAt(1) === '=';
}
function unescapeFormulaExpression(expression) {
    return isEscapedFormulaExpression(expression) ? expression.substr(1) : expression;
}
function isFormula(value) {
    return typeof value === 'string' && value.startsWith('=');
}
function isDate(value, cellType) {
    return typeof value === 'string' && cellType === 'date';
}
function isDateValid(date, dateFormat) {
    return (0, _moment.default)(date, dateFormat, true).isValid();
}
function getDateInHfFormat(date, dateFormat) {
    return (0, _moment.default)(date, dateFormat, true).format(DEFAULT_DATE_FORMAT_HYPERFORMULA);
}
function getDateInHotFormat(date, dateFormat) {
    return (0, _moment.default)(date, DEFAULT_DATE_FORMAT_HYPERFORMULA, true).format(dateFormat);
}
function getDateFromExcelDate(numericDate, dateFormat) {
    // To replicate the behavior from the HyperFormula. UTC starts from 31/12/1899, while HF from 30/12/1899.
    const dateOffset = -1;
    // Based on solution from: https://stackoverflow.com/a/67130235.
    const dateForFormatting = new Date(Date.UTC(0, 0, numericDate + dateOffset));
    return (0, _moment.default)(dateForFormatting).format(dateFormat);
}
function normalizeValueForFormulaEngine(value) {
    if (Array.isArray(value)) {
        return (0, _valueGetter.valueGetter)(value);
    }
    return value;
}
