"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.SimpleAttribute = void 0;
var react_1 = __importStar(require("react"));
var mdm_sdk_1 = require("@reltio/mdm-sdk");
var classnames_1 = __importDefault(require("classnames"));
var useMaskedAttribute_1 = require("../hooks/useMaskedAttribute");
var useCssVariableStyles_1 = require("../hooks/useCssVariableStyles");
var classnames_2 = require("../constants/classnames");
var HistoryAppearanceContext_1 = require("../contexts/HistoryAppearanceContext");
var HighlightedValuesContext_1 = require("../contexts/HighlightedValuesContext");
var CommentsContainer_1 = require("../CommentsContainer");
var DataTypeValue_1 = require("../DataTypeValue");
var PivotingTooltip_1 = require("../PivotingTooltip");
var MaskingSwitcher_1 = require("../MaskingSwitcher");
var SimpleAttribute_module_css_1 = __importDefault(require("./SimpleAttribute.module.css"));
var SimpleAttribute = function (_a) {
    var _b, _c, _d, _e, _f;
    var className = _a.className, _g = _a.attributeType, attributeType = _g === void 0 ? null : _g, rawAttributeValue = _a.attributeValue, inlined = _a.inlined, FallbackSlot = _a.FallbackSlot;
    var _h = (0, useMaskedAttribute_1.useMaskedAttribute)({
        attributeType: attributeType,
        attributeValue: rawAttributeValue
    }), isUnmaskingNeeded = _h.isUnmaskingNeeded, isMasked = _h.isMasked, toggleMasking = _h.toggleMasking, attributeValue = _h.attributeValue, isUnmasking = _h.isUnmasking;
    var variableStyles = (0, useCssVariableStyles_1.useCssVariableStyles)({
        '--history-insert-color': mdm_sdk_1.historyPalettes[mdm_sdk_1.HistoryOperations.insertAttribute].color,
        '--history-update-backgroundColor': mdm_sdk_1.historyPalettes[mdm_sdk_1.HistoryOperations.updateAttribute].backgroundColor,
        '--history-update-color': mdm_sdk_1.historyPalettes[mdm_sdk_1.HistoryOperations.updateAttribute].color,
        '--history-delete-backgroundColor': mdm_sdk_1.historyPalettes[mdm_sdk_1.HistoryOperations.deleteAttribute].backgroundColor,
        '--history-delete-color': mdm_sdk_1.historyPalettes[mdm_sdk_1.HistoryOperations.deleteAttribute].color
    });
    var _j = (0, react_1.useContext)(HighlightedValuesContext_1.HighlightedValuesContext), _k = _j.highlightedValuesUris, highlightedValuesUris = _k === void 0 ? [] : _k, highlightedClassName = _j.highlightedClassName;
    var appearance = (0, react_1.useContext)(HistoryAppearanceContext_1.HistoryDiffContext).appearance;
    var attributeAppearance = (0, mdm_sdk_1.getHistoryAppearanceByUri)(attributeValue.uri, appearance);
    var historyClassName = (0, mdm_sdk_1.getHistoryAttributeClassName)(attributeAppearance);
    var dataTypeValue = (0, react_1.useMemo)(function () { return (react_1.default.createElement(DataTypeValue_1.DataTypeValue, { value: (0, mdm_sdk_1.getAttributeValue)(attributeValue), dataTypeDefinition: (0, mdm_sdk_1.getAttrDataTypeDefinition)(attributeType) })); }, [attributeValue, attributeType]);
    var objectType = (0, mdm_sdk_1.getObjectTypeByAttributeUri)(attributeValue.uri);
    var unmaskingControl = isUnmaskingNeeded && (react_1.default.createElement(MaskingSwitcher_1.MaskingSwitcher, { isMasked: isMasked, onToggleMasking: toggleMasking, isUnmasking: isUnmasking }));
    return inlined || historyClassName ? (react_1.default.createElement("div", { style: variableStyles, className: (0, classnames_1.default)(className, (_b = {},
            _b[highlightedClassName] = highlightedValuesUris.includes(attributeValue.uri),
            _b)) },
        react_1.default.createElement(PivotingTooltip_1.PivotingTooltip, { value: attributeValue, attributeType: attributeType, key: attributeValue.uri, className: (0, classnames_1.default)((_c = {}, _c[SimpleAttribute_module_css_1.default.multilineAttribute] = !inlined, _c)) },
            react_1.default.createElement("span", { className: (0, classnames_1.default)(SimpleAttribute_module_css_1.default.attributeValue, SimpleAttribute_module_css_1.default[historyClassName], (_d = {},
                    _d[SimpleAttribute_module_css_1.default.ovFalse] = !(0, mdm_sdk_1.isOv)(attributeValue),
                    _d)), "data-reltio-id": "reltio-attribute-value" },
                dataTypeValue,
                unmaskingControl,
                FallbackSlot && (attributeValue === null || attributeValue === void 0 ? void 0 : attributeValue.ovDetails) && react_1.default.createElement(FallbackSlot, { ovDetails: attributeValue.ovDetails }))))) : (react_1.default.createElement("div", { "data-reltio-id": "comments-container-visibility-area", style: variableStyles, className: (0, classnames_1.default)(className, SimpleAttribute_module_css_1.default.root, classnames_2.COMMENTS_CONTAINER_VISIBILITY_AREA, (_e = {},
            _e[highlightedClassName] = highlightedValuesUris.includes(attributeValue.uri),
            _e)) },
        react_1.default.createElement(PivotingTooltip_1.PivotingTooltip, { value: attributeValue, attributeType: attributeType, key: attributeValue.uri },
            react_1.default.createElement("span", { className: (0, classnames_1.default)(SimpleAttribute_module_css_1.default.attributeValue, (_f = {}, _f[SimpleAttribute_module_css_1.default.ovFalse] = !(0, mdm_sdk_1.isOv)(attributeValue), _f)), "data-reltio-id": "reltio-attribute-value" },
                dataTypeValue,
                unmaskingControl,
                FallbackSlot && (attributeValue === null || attributeValue === void 0 ? void 0 : attributeValue.ovDetails) && react_1.default.createElement(FallbackSlot, { ovDetails: attributeValue.ovDetails }))),
        react_1.default.createElement(CommentsContainer_1.CommentsContainer, { className: SimpleAttribute_module_css_1.default.commentsContainer, uri: attributeValue.uri, relatedObjectUris: (0, mdm_sdk_1.createRelatedObjectUris)(objectType, {
                uri: attributeValue.uri
            }), objectType: objectType })));
};
exports.SimpleAttribute = SimpleAttribute;
