"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.EntityChangesGroup = void 0;
var react_1 = __importDefault(require("react"));
var Accordion_1 = __importDefault(require("@mui/material/Accordion"));
var AccordionSummary_1 = __importDefault(require("@mui/material/AccordionSummary"));
var AccordionDetails_1 = __importDefault(require("@mui/material/AccordionDetails"));
var ExpandMore_1 = __importDefault(require("@mui/icons-material/ExpandMore"));
var useChangesList_1 = require("../../../hooks/useChangesList");
var DCREntityUriLink_1 = require("../../../DCREntityUriLink/DCREntityUriLink");
var ChangeItemRow_1 = require("../ChangeItemRow/ChangeItemRow");
var AttributesChangesContext_1 = require("../../../AttributesChanges/AttributesChangesContext");
var common_1 = require("../../../helpers/common");
var helpers_1 = require("../../helpers/helpers");
var EntityChangesGroup_module_css_1 = __importDefault(require("./EntityChangesGroup.module.css"));
var EntityChangesGroup = function (_a) {
    var task = _a.task, dcr = _a.dcr, entityInfo = _a.entityInfo, relationsInfo = _a.relationsInfo;
    var dcrUri = (0, common_1.getDCRUri)(task.objectURIs);
    var _b = dcr || {}, changes = _b.changes, objectsInfo = _b.objectsInfo;
    var changesList = (0, useChangesList_1.useChangesList)({
        changes: changes,
        entityInfo: entityInfo,
        relationsInfo: relationsInfo
    });
    return (react_1.default.createElement(AttributesChangesContext_1.AttributesChangesContext.Provider, { value: objectsInfo },
        react_1.default.createElement(Accordion_1.default, { className: EntityChangesGroup_module_css_1.default.entityGroup, defaultExpanded: true, "data-reltio-id": "entity-changes-group" },
            react_1.default.createElement(AccordionSummary_1.default, { expandIcon: react_1.default.createElement(ExpandMore_1.default, null), className: EntityChangesGroup_module_css_1.default.entityHeader, classes: {
                    content: EntityChangesGroup_module_css_1.default.accordionContent
                } },
                react_1.default.createElement(DCREntityUriLink_1.DCREntityUriLink, { entityInfo: entityInfo, changes: changes, dcrUri: dcrUri, className: EntityChangesGroup_module_css_1.default.entityTitle })),
            react_1.default.createElement(AccordionDetails_1.default, { className: EntityChangesGroup_module_css_1.default.attributesList }, changesList.map(function (item, index) {
                return (0, helpers_1.isDiffChange)(item) ? (react_1.default.createElement(ChangeItemRow_1.ChangeItemRow, { key: "change-".concat(index), change: item, entityInfo: entityInfo })) : (react_1.default.createElement("div", { key: "title-".concat(index), className: EntityChangesGroup_module_css_1.default.titleChangeItem }, item.label));
            })))));
};
exports.EntityChangesGroup = EntityChangesGroup;
