"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.ComplexRule = void 0;
var react_1 = __importStar(require("react"));
var mdm_sdk_1 = require("@reltio/mdm-sdk");
var ArrowExpandButton_1 = require("../../../../../ArrowExpandButton");
var BranchDecorator_1 = require("../../../../../BranchDecorator");
var SyncedExpandedAttributesContext_1 = require("../../../../../contexts/SyncedExpandedAttributesContext");
var MdmModuleContext_1 = require("../../../../../contexts/MdmModuleContext");
var SimpleRule_1 = require("../SimpleRule");
var AttributeRule_1 = require("../AttributeRule");
var ComplexRule_module_css_1 = __importDefault(require("./ComplexRule.module.css"));
var ComplexRule = function (_a) {
    var attributeType = _a.attributeType, attributeValue = _a.attributeValue, getRuleTypeData = _a.getRuleTypeData;
    var metadata = (0, MdmModuleContext_1.useMdmMetadata)();
    var expandedContext = (0, SyncedExpandedAttributesContext_1.useSyncedExpandedAttributes)();
    var attributeUri = attributeValue.uri;
    var expanded = expandedContext ? expandedContext.isExpanded(attributeUri) : false;
    var toggle = (0, react_1.useCallback)(function () {
        if (expandedContext && attributeUri) {
            expandedContext.toggle(attributeUri);
        }
    }, [expandedContext, attributeUri]);
    var subAttributes = (0, mdm_sdk_1.getAttributeTypeSubAttributes)(metadata, attributeType);
    var entity = { attributes: attributeValue.value };
    var attributesList = (0, mdm_sdk_1.getAttributesListForReadMode)(subAttributes, entity, false, []);
    return (react_1.default.createElement("div", null,
        react_1.default.createElement("div", { className: ComplexRule_module_css_1.default.expandableRule },
            react_1.default.createElement(ArrowExpandButton_1.ArrowExpandButton, { expanded: expanded, onClick: toggle }),
            react_1.default.createElement(SimpleRule_1.SimpleRule, { attributeValue: attributeValue, attributeType: attributeType, getRuleTypeData: getRuleTypeData })),
        expanded && (react_1.default.createElement("div", null, attributesList.map(function (item) { return (react_1.default.createElement(BranchDecorator_1.BranchDecorator, { key: item.attrType.uri, enabled: true, className: ComplexRule_module_css_1.default.rulePaddingWrapper },
            react_1.default.createElement(AttributeRule_1.AttributeRule, { attributeType: item.attrType, values: item.values, getRuleTypeData: getRuleTypeData, parentUri: attributeUri }))); })))));
};
exports.ComplexRule = ComplexRule;
