import React from 'react';
import Accordion from '@mui/material/Accordion';
import AccordionSummary from '@mui/material/AccordionSummary';
import AccordionDetails from '@mui/material/AccordionDetails';
import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
import { useChangesList } from '../../../hooks/useChangesList';
import { DCREntityUriLink } from '../../../DCREntityUriLink/DCREntityUriLink';
import { ChangeItemRow } from '../ChangeItemRow/ChangeItemRow';
import { AttributesChangesContext } from '../../../AttributesChanges/AttributesChangesContext';
import { getDCRUri } from '../../../helpers/common';
import { isDiffChange } from '../../helpers/helpers';
import styles from './EntityChangesGroup.module.css';
export var EntityChangesGroup = function (_a) {
    var task = _a.task, dcr = _a.dcr, entityInfo = _a.entityInfo, relationsInfo = _a.relationsInfo;
    var dcrUri = getDCRUri(task.objectURIs);
    var _b = dcr || {}, changes = _b.changes, objectsInfo = _b.objectsInfo;
    var changesList = useChangesList({
        changes: changes,
        entityInfo: entityInfo,
        relationsInfo: relationsInfo
    });
    return (React.createElement(AttributesChangesContext.Provider, { value: objectsInfo },
        React.createElement(Accordion, { className: styles.entityGroup, defaultExpanded: true, "data-reltio-id": "entity-changes-group" },
            React.createElement(AccordionSummary, { expandIcon: React.createElement(ExpandMoreIcon, null), className: styles.entityHeader, classes: {
                    content: styles.accordionContent
                } },
                React.createElement(DCREntityUriLink, { entityInfo: entityInfo, changes: changes, dcrUri: dcrUri, className: styles.entityTitle })),
            React.createElement(AccordionDetails, { className: styles.attributesList }, changesList.map(function (item, index) {
                return isDiffChange(item) ? (React.createElement(ChangeItemRow, { key: "change-".concat(index), change: item, entityInfo: entityInfo })) : (React.createElement("div", { key: "title-".concat(index), className: styles.titleChangeItem }, item.label));
            })))));
};
