var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
import React, { useContext } from 'react';
import i18n from 'ui-i18n';
import classnames from 'classnames';
import { startsWith } from 'ramda';
import { CollaborationObjectTypes, findAttributeTypeByUri, getLabel, getEntityUriForLink, getEntityId, getAttributeTypeUriByValueUri } from '@reltio/mdm-sdk';
import Typography from '@mui/material/Typography';
import Box from '@mui/material/Box';
import { EntitiesMapContext } from '../../../contexts/EntitiesMapContext';
import { useMdmEntity, useMdmMetadata } from '../../../contexts/MdmModuleContext';
import { EntityUriLink } from '../../../EntityUriLink';
import { getRelatedEntityUri } from '../../helpers';
import { useStyles } from './styles';
export var CommentTarget = function (_a) {
    var comment = _a.comment, className = _a.className;
    var styles = useStyles();
    var entitiesMap = useContext(EntitiesMapContext);
    var metadata = useMdmMetadata();
    var entity = useMdmEntity();
    var getContent = function () {
        var _a;
        switch (comment.objectType) {
            case CollaborationObjectTypes.ENTITY_ATTRIBUTE: {
                var attributeTypeUri = getAttributeTypeUriByValueUri(comment.objectId, entity.type);
                var attributeType = findAttributeTypeByUri(metadata, attributeTypeUri);
                return (React.createElement(React.Fragment, null,
                    React.createElement(Typography, { className: styles.title }, i18n.text('Selected attribute:')),
                    React.createElement(Typography, { className: styles.label }, attributeType === null || attributeType === void 0 ? void 0 : attributeType.label)));
            }
            case CollaborationObjectTypes.RELATION_ATTRIBUTE: {
                var relationTypeUri = comment.relatedObjectUris.find(startsWith('configuration/relationTypes'));
                var attributeTypeUri = relationTypeUri && getAttributeTypeUriByValueUri(comment.objectId, relationTypeUri);
                var attributeType = attributeTypeUri && findAttributeTypeByUri(metadata, attributeTypeUri);
                return (React.createElement(React.Fragment, null,
                    React.createElement(Typography, { className: styles.title }, i18n.text('Selected attribute:')),
                    React.createElement(Typography, { className: styles.label }, attributeType === null || attributeType === void 0 ? void 0 : attributeType.label)));
            }
            case CollaborationObjectTypes.ENTITY: {
                return (React.createElement(React.Fragment, null,
                    React.createElement(Typography, { className: styles.title }, i18n.text('Selected profile:')),
                    React.createElement(EntityUriLink, { className: classnames(styles.label, styles.link), value: getEntityUriForLink(entity) }, getLabel(entity.label))));
            }
            case CollaborationObjectTypes.RELATION: {
                var relatedEntityUri = getRelatedEntityUri(comment, entity.uri);
                var relatedEntity = __assign(__assign({}, (entitiesMap[relatedEntityUri] || {})), { uri: relatedEntityUri });
                return (React.createElement(React.Fragment, null,
                    React.createElement(Typography, { className: styles.title }, i18n.text('Selected relation:')),
                    React.createElement(Typography, { className: styles.label },
                        React.createElement(EntityUriLink, { className: styles.link, value: getEntityUriForLink(entity) }, getLabel(entity.label)),
                        relatedEntityUri && (React.createElement(React.Fragment, null, " ".concat(i18n.text('to'), " "),
                            React.createElement(EntityUriLink, { className: styles.link, value: getEntityUriForLink(relatedEntity) }, relatedEntity.label
                                ? getLabel(relatedEntity.label)
                                : getEntityId(relatedEntity)))))));
            }
            case CollaborationObjectTypes.POTENTIAL_MATCH: {
                var relatedEntityUri = getRelatedEntityUri(comment, entity.uri);
                var relatedEntity = {
                    uri: relatedEntityUri,
                    label: (_a = entitiesMap[relatedEntityUri]) === null || _a === void 0 ? void 0 : _a.label
                };
                return (React.createElement(React.Fragment, null,
                    React.createElement(Typography, { className: styles.title }, i18n.text('Selected potential match:')),
                    React.createElement(Typography, { className: styles.label },
                        React.createElement(EntityUriLink, { className: styles.link, value: getEntityUriForLink(entity) }, getLabel(entity.label)),
                        relatedEntityUri && (React.createElement(React.Fragment, null, " ".concat(i18n.text('and'), " "),
                            React.createElement(EntityUriLink, { className: styles.link, value: getEntityUriForLink(relatedEntity) }, relatedEntity.label
                                ? getLabel(relatedEntity.label)
                                : getEntityId(relatedEntity)))))));
            }
            default: {
                return null;
            }
        }
    };
    return React.createElement(Box, { className: className }, getContent());
};
