import React, { useMemo } from 'react';
import { identity } from 'ramda';
import { getGroupedEntityTypes } from '@reltio/mdm-sdk';
import { ViewMoreToggle } from '../ViewMoreToggle';
import { EmptySearchResult } from '../EmptySearchResult';
import { EntityTypesFacetGroups } from './components/EntityTypesFacetGroups';
import styles from './QuickFiltersEntityTypeFacet.module.css';
var DEFAULT_ROW_COUNT = 7;
export var QuickFiltersEntityTypeFacet = function (_a) {
    var items = _a.items, _b = _a.maxRowCount, maxRowCount = _b === void 0 ? DEFAULT_ROW_COUNT : _b, showAllItems = _a.showAllItems, _c = _a.values, values = _c === void 0 ? [] : _c, _d = _a.onChange, onChange = _d === void 0 ? identity : _d, onViewMoreLess = _a.onViewMoreLess, countFormatter = _a.countFormatter;
    var groups = useMemo(function () { return getGroupedEntityTypes(items); }, [items]);
    var totalItems = groups.reduce(function (sum, group) { return sum + group.items.length; }, 0);
    var needShowViewMoreButton = totalItems > maxRowCount;
    return (React.createElement("div", { className: styles.container }, groups.length > 0 ? (React.createElement(React.Fragment, null,
        React.createElement(EntityTypesFacetGroups, { groups: groups, values: values, maxRowCount: maxRowCount, onChange: onChange, showAll: showAllItems, countFormatter: countFormatter }),
        needShowViewMoreButton && (React.createElement(ViewMoreToggle, { active: showAllItems, onClick: onViewMoreLess, className: styles.viewMoreLess })))) : (React.createElement(EmptySearchResult, { variant: "noData", className: styles.noData }))));
};
