"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.fromEditorValue = exports.toEditorValue = void 0;
var mdm_sdk_1 = require("@reltio/mdm-sdk");
var toEditorValue = function (dataType, _a) {
    var _b = _a === void 0 ? {} : _a, _c = _b.disableTimestampLocalization, disableTimestampLocalization = _c === void 0 ? false : _c;
    return function (value) {
        switch (dataType) {
            case mdm_sdk_1.DataTypes.TYPE_DATE:
                return (0, mdm_sdk_1.isDateRangeValue)(value) ? value : mdm_sdk_1.utils.dates.toLocalDate(value);
            case mdm_sdk_1.DataTypes.TYPE_TIMESTAMP:
                if ((0, mdm_sdk_1.isDateRangeValue)(value)) {
                    return value;
                }
                return disableTimestampLocalization ? mdm_sdk_1.utils.dates.toLocalDate(value) : new Date(value);
            case mdm_sdk_1.DataTypes.TYPE_LOCAL_DATE:
            case mdm_sdk_1.DataTypes.TYPE_ACTIVENESS_DATE:
                return (0, mdm_sdk_1.isDateRangeValue)(value) ? value : new Date(value);
            default:
                return value;
        }
    };
};
exports.toEditorValue = toEditorValue;
var fromEditorValue = function (dataType, _a) {
    var _b = _a === void 0 ? {} : _a, _c = _b.disableTimestampLocalization, disableTimestampLocalization = _c === void 0 ? false : _c;
    return function (value) {
        switch (dataType) {
            case mdm_sdk_1.DataTypes.TYPE_DATE:
                return (0, mdm_sdk_1.isDateRangeValue)(value)
                    ? value
                    : Date.UTC(value.getFullYear(), value.getMonth(), value.getDate());
            case mdm_sdk_1.DataTypes.TYPE_TIMESTAMP:
                if ((0, mdm_sdk_1.isDateRangeValue)(value)) {
                    return value;
                }
                return disableTimestampLocalization ? mdm_sdk_1.utils.dates.toUtcDate(value).getTime() : value.valueOf();
            case mdm_sdk_1.DataTypes.TYPE_LOCAL_DATE:
            case mdm_sdk_1.DataTypes.TYPE_ACTIVENESS_DATE:
                return (0, mdm_sdk_1.isDateRangeValue)(value) ? value : value.valueOf();
            default:
                return value;
        }
    };
};
exports.fromEditorValue = fromEditorValue;
