import React, { useContext, useMemo } from 'react';
import { getAttributesListForReadMode, isEmptyValue } from '@reltio/mdm-sdk';
import classnames from 'classnames';
import i18n from 'ui-i18n';
import Box from '@mui/material/Box';
import Typography from '@mui/material/Typography';
import { PivotingAttributeContext } from '../contexts/PivotingAttributeContext';
import { useMdmMetadata, useMdmPivotingAttributes } from '../contexts/MdmModuleContext';
import { AlwaysVisibleAttributesContext } from '../contexts/AlwaysVisibleAttributesContext';
import { BasicView } from '../BasicView';
import { FacetViewHeader } from '../FacetViewHeader';
import { ReadOnlyAttributesList } from '../ReadOnlyAttributesList';
import { getFilteredAttrTypes } from '../helpers/attributesView';
import { useStyles } from './styles';
var DEFAULT_ATTRIBUTES_COUNT = 16;
export var ReadOnlyAttributesView = function (_a) {
    var _b;
    var className = _a.className, _c = _a.entity, entity = _c === void 0 ? {} : _c, _d = _a.caption, caption = _d === void 0 ? '' : _d, _e = _a.excludeUris, excludeUris = _e === void 0 ? [] : _e, _f = _a.includeUris, includeUris = _f === void 0 ? [] : _f, attributesCountProp = _a.attributesCount;
    var styles = useStyles();
    var metadata = useMdmMetadata();
    var pivotingAttributes = useMdmPivotingAttributes();
    var filteredAttrTypes = useMemo(function () { return getFilteredAttrTypes(metadata, entity.type, includeUris, excludeUris); }, [excludeUris, includeUris, metadata, entity]);
    var attributesCount = attributesCountProp || DEFAULT_ATTRIBUTES_COUNT;
    var attributesList = getAttributesListForReadMode(filteredAttrTypes, entity);
    var alwaysVisible = useContext(AlwaysVisibleAttributesContext);
    var isShowAttributeList = attributesList.filter(function (_a) {
        var values = _a.values;
        return !isEmptyValue(values);
    }).length > 0 || alwaysVisible.length > 0;
    return isShowAttributeList || !isEmptyValue(caption) ? (React.createElement(PivotingAttributeContext.Provider, { value: pivotingAttributes },
        React.createElement(BasicView, { className: className },
            caption && React.createElement(FacetViewHeader, { title: caption }),
            React.createElement(Box, { className: classnames(styles.attributesContainer, (_b = {}, _b[styles.noCaption] = !caption, _b)) }, isShowAttributeList ? (React.createElement(ReadOnlyAttributesList, { entity: entity, attrTypes: filteredAttrTypes, parentUri: entity.uri, drawLines: false, max: attributesCount })) : (React.createElement(Typography, { className: styles.noData }, i18n.text('No data found'))))))) : null;
};
