import React, { useMemo } from 'react';
import classnames from 'classnames';
import { isTempUri, getPinnedAttributesForUser } from '@reltio/mdm-sdk';
import Box from '@mui/material/Box';
import { BasicView } from '../BasicView';
import { FacetViewHeader } from '../FacetViewHeader';
import { useMdmAction, useMdmMetadata, useMdmModifiedEntity, useMdmUserRoles } from '../contexts/MdmModuleContext';
import { getFilteredAttrTypes } from '../helpers/attributesView';
import { PinnedAttributesContext } from '../contexts/PinnedAttributesContext';
import { EditModeAttributesList } from '../EditModeAttributesList';
import { useStyles } from './styles';
export var EditModeAttributesView = function (_a) {
    var _b;
    var className = _a.className, mode = _a.mode, entity = _a.entity, _c = _a.caption, caption = _c === void 0 ? '' : _c, _d = _a.excludeUris, excludeUris = _d === void 0 ? [] : _d, _e = _a.includeUris, includeUris = _e === void 0 ? [] : _e, pinnedAttributes = _a.pinnedAttributes;
    var styles = useStyles();
    var addAttributes = useMdmAction('addAttributes');
    var modifyAttribute = useMdmAction('modifyAttribute');
    var removeAttribute = useMdmAction('removeAttribute');
    var metadata = useMdmMetadata();
    var userRoles = useMdmUserRoles();
    var modifiedEntity = useMdmModifiedEntity(entity.uri) || {};
    var pinnedAttributeUris = useMemo(function () { return getPinnedAttributesForUser(pinnedAttributes, userRoles); }, [pinnedAttributes, userRoles]);
    var filteredAttrTypes = useMemo(function () { return getFilteredAttrTypes(metadata, modifiedEntity.type, includeUris, excludeUris); }, [excludeUris, includeUris, metadata, modifiedEntity.type]);
    return (React.createElement(BasicView, { className: className },
        caption && React.createElement(FacetViewHeader, { title: caption }),
        React.createElement(Box, { className: classnames(styles.attributesContainer, (_b = {}, _b[styles.noCaption] = !caption, _b)) },
            React.createElement(PinnedAttributesContext.Provider, { value: pinnedAttributeUris },
                React.createElement(EditModeAttributesList, { entity: modifiedEntity, attrTypes: filteredAttrTypes, parentUri: modifiedEntity.uri, drawLines: false, mode: mode, showEmptyEditors: isTempUri(modifiedEntity.uri), crosswalks: modifiedEntity.crosswalks, onAddAttributes: addAttributes, onChangeAttribute: modifyAttribute, onDeleteAttribute: removeAttribute })))));
};
