"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 __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
    if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
        if (ar || !(i in from)) {
            if (!ar) ar = Array.prototype.slice.call(from, 0, i);
            ar[i] = from[i];
        }
    }
    return to.concat(ar || Array.prototype.slice.call(from));
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.TableWithBars = void 0;
var react_1 = __importStar(require("react"));
var ui_i18n_1 = __importDefault(require("ui-i18n"));
var BasicTable_1 = require("../BasicTable");
var HeadCellRenderer_1 = require("./components/HeadCellRenderer");
var AttributeCellRenderer_1 = require("./components/AttributeCellRenderer");
var NumberCellValueRenderer_1 = require("./components/NumberCellValueRenderer");
var styles_1 = require("./styles");
var TableWithBars = function (_a) {
    var width = _a.width, height = _a.height, data = _a.data, _b = _a.options, options = _b === void 0 ? {} : _b, basicTableRef = _a.basicTableRef, onItemClick = _a.onItemClick;
    var styles = (0, styles_1.useStyles)({ width: width, height: height });
    var _c = options.headers, _d = _c === void 0 ? [] : _c, labelHeader = _d[0], valueHeader = _d[1], _e = options.showValues, showValues = _e === void 0 ? true : _e;
    var tableClasses = (0, react_1.useMemo)(function () { return ({ cellBorder: styles.cellBorder }); }, [styles]);
    var maxValue = (0, react_1.useMemo)(function () { return Math.max.apply(Math, data.map(function (item) { return item.value; })); }, [data]);
    var headData = (0, react_1.useMemo)(function () { return __spreadArray([
        {
            id: 'label',
            label: labelHeader || ui_i18n_1.default.text('Attributes'),
            resizable: false,
            headCellRenderer: HeadCellRenderer_1.HeadCellRenderer,
            rowCellValueRenderer: AttributeCellRenderer_1.AttributeCellRenderer,
            initialWidth: width * 0.4
        }
    ], (showValues
        ? [
            {
                id: 'value',
                label: valueHeader || ui_i18n_1.default.text('No of Profiles'),
                resizable: false,
                headCellRenderer: HeadCellRenderer_1.HeadCellRenderer,
                rowCellValueRenderer: NumberCellValueRenderer_1.NumberCellValueRenderer,
                maxValue: maxValue,
                initialWidth: width * 0.6
            }
        ]
        : []), true); }, [maxValue, width, valueHeader, labelHeader, showValues]);
    var context = (0, react_1.useMemo)(function () { return ({
        onItemClick: onItemClick
    }); }, [onItemClick]);
    return (react_1.default.createElement("div", { className: styles.tableContainer },
        react_1.default.createElement(BasicTable_1.BasicTable, { columnsData: headData, rowsData: data, headRowHeight: 48, getRowCellHeight: null, classes: tableClasses, defaultColumnWidth: 100, defaultColumnMinWidth: 100, ref: basicTableRef, context: context })));
};
exports.TableWithBars = TableWithBars;
