import React from 'react';
import PropTypes from 'prop-types';
import moment from 'moment';
import { formatDataTypeValue, isAttributeValueLink, addProtocolToLink } from '@reltio/mdm-sdk';
import Link from '@mui/material/Link';
import { SearchHighlighter } from '../SearchHighlighter';
import { useMdmAttributesPresentation, useMdmDateMask, useMdmDateTimeMask } from '../contexts/MdmModuleContext';
export 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.localeData().longDateFormat('L');
    var localeTimeFormat = moment.localeData().longDateFormat('LTS');
    var attributesPresentation = useMdmAttributesPresentation();
    var dateMask = useMdmDateMask() || localeDateFormat;
    var dateTimeMask = useMdmDateTimeMask() || localeDateFormat + ' ' + localeTimeFormat;
    var formattedValue = formatDataTypeValue({ attributesPresentation: attributesPresentation, dataTypeDefinition: dataTypeDefinition, dateMask: dateMask, dateTimeMask: dateTimeMask }, value);
    return rich && isAttributeValueLink(dataTypeDefinition, value) ? (React.createElement(Link, { target: "_blank", href: addProtocolToLink(formattedValue), underline: "none" },
        React.createElement(SearchHighlighter, { text: formattedValue }))) : (React.createElement(SearchHighlighter, { text: formattedValue }));
};
DataTypeValue.propTypes = {
    value: PropTypes.any,
    dataTypeDefinition: PropTypes.object,
    rich: PropTypes.bool
};
