"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 RENDERER_TYPE () {
        return RENDERER_TYPE;
    },
    get intlDateRenderer () {
        return intlDateRenderer;
    },
    get valueFormatter () {
        return valueFormatter;
    }
});
const _textRenderer = require("../textRenderer");
const _dateTime = require("../../helpers/dateTime");
const _mixed = require("../../helpers/mixed");
const _object = require("../../helpers/object");
const _constants = require("../../helpers/constants");
const RENDERER_TYPE = 'intl-date';
const DEFAULT_INTL_FORMAT = {
    year: 'numeric',
    month: '2-digit',
    day: '2-digit'
};
function valueFormatter(value, cellProperties) {
    const { dateFormat, locale, allowEmpty } = cellProperties;
    if ((0, _mixed.isEmpty)(value)) {
        return allowEmpty ? value : _constants.BAD_VALUE_TEXT;
    }
    const date = (0, _dateTime.parseToLocalDate)(value);
    if (date === null) {
        return _constants.BAD_VALUE_TEXT;
    }
    const intlFormat = (0, _object.isObject)(dateFormat) ? dateFormat : DEFAULT_INTL_FORMAT;
    return new Intl.DateTimeFormat(locale, intlFormat).format(date);
}
function intlDateRenderer(hotInstance, TD, row, col, prop, value, cellProperties) {
    _textRenderer.textRenderer.apply(this, [
        hotInstance,
        TD,
        row,
        col,
        prop,
        value,
        cellProperties
    ]);
}
intlDateRenderer.valueFormatter = valueFormatter;
intlDateRenderer.RENDERER_TYPE = RENDERER_TYPE;
