var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
var __rest = (this && this.__rest) || function (s, e) {
    var t = {};
    for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
        t[p] = s[p];
    if (s != null && typeof Object.getOwnPropertySymbols === "function")
        for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
            if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                t[p[i]] = s[p[i]];
        }
    return t;
};
import React, { memo } from 'react';
import ListItem from '@mui/material/ListItem';
import { AttributeListItem } from '../AttributeListItem';
import { VirtualGroupedList } from '../VirtualGroupedList';
import { Highlighter } from '../Highlighter';
import { AttributeGroupIcon } from '../AttributeGroupIcon';
import { useMdmMetadata } from '../contexts/MdmModuleContext';
import { checkAttributeIncludes } from '../helpers/attributesView';
import styles from './SelectAttributesList.module.css';
var ITEM_HEIGHT = 28;
var ITEM_GROUP_TITLE_HEIGHT = 40;
var SelectAttributesList = function (_a) {
    var selectedAttributes = _a.selectedAttributes, onItemClick = _a.onItemClick, focusIndex = _a.focusIndex, hideCheckBox = _a.hideCheckBox, otherProps = __rest(_a, ["selectedAttributes", "onItemClick", "focusIndex", "hideCheckBox"]);
    var metadata = useMdmMetadata();
    var getItemSize = function (i, item) {
        return item.items ? ITEM_GROUP_TITLE_HEIGHT : ITEM_HEIGHT;
    };
    var renderGroupTitle = function (style, item) { return (React.createElement(ListItem, { component: 'div', className: styles.subHeader, style: style, key: "group-".concat(item.item.id) },
        item.item.needGroupIcon && React.createElement(AttributeGroupIcon, { group: item.item, metadata: metadata }),
        React.createElement("div", { className: styles.subHeaderTitle }, item.item.title))); };
    var renderItem = function (style, _a, index) {
        var item = _a.item, level = _a.level, groupId = _a.groupId, groupName = _a.groupName;
        var checked = checkAttributeIncludes(item, selectedAttributes);
        var isFocused = index === focusIndex;
        return (React.createElement(AttributeListItem, { key: "item-".concat(groupId, "-").concat(item.fieldName), onClick: onItemClick, checked: checked, data: __assign(__assign({}, item), { groupName: groupName }), notSelectable: item.notSelectable, hideCheckBox: hideCheckBox, label: React.createElement(Highlighter, { text: item.title, highlight: item.filterText }), labelInText: item.title, level: level, style: style, isFocused: isFocused, groupId: groupId, LogoIcon: item.LogoIcon }));
    };
    return (React.createElement(VirtualGroupedList, __assign({ getItemSize: getItemSize, renderItem: renderItem, renderGroupTitle: renderGroupTitle, focusIndex: focusIndex }, otherProps)));
};
var typedMemo = memo;
export default typedMemo(SelectAttributesList);
