"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.DataTypeValue = void 0;
var react_1 = __importDefault(require("react"));
var prop_types_1 = __importDefault(require("prop-types"));
var moment_1 = __importDefault(require("moment"));
var mdm_sdk_1 = require("@reltio/mdm-sdk");
var Link_1 = __importDefault(require("@mui/material/Link"));
var SearchHighlighter_1 = require("../SearchHighlighter");
var MdmModuleContext_1 = require("../contexts/MdmModuleContext");
var DataTypeValue = function (_a) {
    var _b = _a.value, value = _b === void 0 ? null : _b, dataTypeDefinition = _a.dataTypeDefinition, _c = _a.rich, rich = _c === void 0 ? true : _c;
    var localeDateFormat = moment_1.default.localeData().longDateFormat('L');
    var localeTimeFormat = moment_1.default.localeData().longDateFormat('LTS');
    var attributesPresentation = (0, MdmModuleContext_1.useMdmAttributesPresentation)();
    var dateMask = (0, MdmModuleContext_1.useMdmDateMask)() || localeDateFormat;
    var dateTimeMask = (0, MdmModuleContext_1.useMdmDateTimeMask)() || localeDateFormat + ' ' + localeTimeFormat;
    var disableTimestampLocalizationFlag = (0, MdmModuleContext_1.useMdmDisableTimestampLocalization)();
    var disableTimestampLocalization = (0, mdm_sdk_1.shouldDisableTimestampLocalizationForAttribute)(dataTypeDefinition, {
        disableTimestampLocalization: disableTimestampLocalizationFlag
    });
    var formattedValue = (0, mdm_sdk_1.formatDataTypeValue)({ attributesPresentation: attributesPresentation, dataTypeDefinition: dataTypeDefinition, dateMask: dateMask, dateTimeMask: dateTimeMask, disableTimestampLocalization: disableTimestampLocalization }, value);
    return rich && (0, mdm_sdk_1.isAttributeValueLink)(dataTypeDefinition, value) ? (react_1.default.createElement(Link_1.default, { target: "_blank", href: (0, mdm_sdk_1.addProtocolToLink)(formattedValue), underline: "none" },
        react_1.default.createElement(SearchHighlighter_1.SearchHighlighter, { text: formattedValue }))) : (react_1.default.createElement(SearchHighlighter_1.SearchHighlighter, { text: formattedValue }));
};
exports.DataTypeValue = DataTypeValue;
exports.DataTypeValue.propTypes = {
    value: prop_types_1.default.any,
    dataTypeDefinition: prop_types_1.default.object,
    rich: prop_types_1.default.bool
};
