"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.EntityTypesList = void 0;
var react_1 = __importStar(require("react"));
var ui_i18n_1 = __importDefault(require("ui-i18n"));
var classnames_1 = __importDefault(require("classnames"));
var ramda_1 = require("ramda");
var Checkbox_1 = __importDefault(require("@mui/material/Checkbox"));
var ColorBar_1 = require("../../../ColorBar");
var EntityTypesList_module_css_1 = __importDefault(require("./EntityTypesList.module.css"));
var EntityTypesList = function (_a) {
    var _b = _a.data, data = _b === void 0 ? [] : _b, _c = _a.values, values = _c === void 0 ? [] : _c, _d = _a.onChange, onChange = _d === void 0 ? ramda_1.identity : _d, countFormatter = _a.countFormatter;
    var shouldShowCount = !!countFormatter;
    var handleItemClick = function (name) { return function () {
        var newValues = values.includes(name) ? values.filter(function (val) { return val !== name; }) : values.concat(name);
        onChange(newValues);
    }; };
    var maxNumber = Math.max.apply(Math, data.map(function (item) { return item.number; }));
    var createControl = function (item) {
        var _a;
        return (react_1.default.createElement(Checkbox_1.default, { className: (0, classnames_1.default)(EntityTypesList_module_css_1.default.checkbox, (_a = {}, _a[EntityTypesList_module_css_1.default.checked] = values.includes(item.value), _a)), checked: values.includes(item.value), onChange: handleItemClick(item.value), value: item.value, color: "primary" }));
    };
    var createColorBar = function (item) {
        var _a;
        return (react_1.default.createElement(ColorBar_1.ColorBar, { className: (0, classnames_1.default)((_a = {}, _a[EntityTypesList_module_css_1.default.checkedBar] = values.includes(item.value), _a)), width: item.number, maxWidth: maxNumber }));
    };
    var shouldDisableItem = (0, react_1.useCallback)(function (item) {
        return shouldShowCount && !item.number && !values.includes(item.value);
    }, [shouldShowCount, values]);
    return (react_1.default.createElement("div", { className: EntityTypesList_module_css_1.default.listContainer }, data.map(function (item) {
        var _a;
        return (react_1.default.createElement("div", { key: item.value, className: (0, classnames_1.default)(EntityTypesList_module_css_1.default.item, (_a = {},
                _a[EntityTypesList_module_css_1.default.disabled] = shouldDisableItem(item),
                _a)), "data-reltio-id": "search-facets-list-row" },
            createControl(item),
            react_1.default.createElement("div", { className: EntityTypesList_module_css_1.default.info, onClick: handleItemClick(item.value) },
                shouldShowCount && createColorBar(item),
                react_1.default.createElement("div", { className: (0, classnames_1.default)(EntityTypesList_module_css_1.default.textInfo) },
                    react_1.default.createElement("div", { className: EntityTypesList_module_css_1.default.text }, item.label),
                    shouldShowCount && (react_1.default.createElement("div", { className: EntityTypesList_module_css_1.default.count }, item.number === undefined ? ui_i18n_1.default.text('N/A') : countFormatter(item.number)))))));
    })));
};
exports.EntityTypesList = EntityTypesList;
