"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.QuickFiltersEntityTypeFacet = void 0;
var react_1 = __importStar(require("react"));
var ramda_1 = require("ramda");
var mdm_sdk_1 = require("@reltio/mdm-sdk");
var ViewMoreToggle_1 = require("../ViewMoreToggle");
var EmptySearchResult_1 = require("../EmptySearchResult");
var EntityTypesFacetGroups_1 = require("./components/EntityTypesFacetGroups");
var QuickFiltersEntityTypeFacet_module_css_1 = __importDefault(require("./QuickFiltersEntityTypeFacet.module.css"));
var DEFAULT_ROW_COUNT = 7;
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 ? ramda_1.identity : _d, onViewMoreLess = _a.onViewMoreLess, countFormatter = _a.countFormatter;
    var groups = (0, react_1.useMemo)(function () { return (0, mdm_sdk_1.getGroupedEntityTypes)(items); }, [items]);
    var totalItems = groups.reduce(function (sum, group) { return sum + group.items.length; }, 0);
    var needShowViewMoreButton = totalItems > maxRowCount;
    return (react_1.default.createElement("div", { className: QuickFiltersEntityTypeFacet_module_css_1.default.container }, groups.length > 0 ? (react_1.default.createElement(react_1.default.Fragment, null,
        react_1.default.createElement(EntityTypesFacetGroups_1.EntityTypesFacetGroups, { groups: groups, values: values, maxRowCount: maxRowCount, onChange: onChange, showAll: showAllItems, countFormatter: countFormatter }),
        needShowViewMoreButton && (react_1.default.createElement(ViewMoreToggle_1.ViewMoreToggle, { active: showAllItems, onClick: onViewMoreLess, className: QuickFiltersEntityTypeFacet_module_css_1.default.viewMoreLess })))) : (react_1.default.createElement(EmptySearchResult_1.EmptySearchResult, { variant: "noData", className: QuickFiltersEntityTypeFacet_module_css_1.default.noData }))));
};
exports.QuickFiltersEntityTypeFacet = QuickFiltersEntityTypeFacet;
