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