"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;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.SetsChart = void 0;
var react_1 = __importStar(require("react"));
var d3_scale_1 = require("d3-scale");
var SetsChartAxis_1 = require("../SetsChartAxis");
var constants_1 = require("../../constants");
var styles_1 = require("./styles");
var SetsChart = function (_a) {
    var sets = _a.sets, width = _a.width, yScale = _a.yScale, transform = _a.transform, labels = _a.labels, hoveredElements = _a.hoveredElements, hoverAreaWidth = _a.hoverAreaWidth, onSetHover = _a.onSetHover;
    var styles = (0, styles_1.useStyles)();
    var containerRef = react_1.default.useRef(null);
    var xScale = (0, react_1.useMemo)(function () {
        var maxSetSize = sets.length > 0 ? Math.max.apply(Math, sets.map(function (set) { return set.size; })) : 0;
        return (0, d3_scale_1.scaleLinear)().domain([0, maxSetSize]).range([0, width]);
    }, [width, sets]);
    return (react_1.default.createElement("g", { ref: containerRef, transform: transform },
        react_1.default.createElement(SetsChartAxis_1.SetsChartAxis, { width: width }),
        sets.map(function (set, i) {
            var name = set.name, size = set.size, elements = set.elements;
            var label = labels[i];
            var height = yScale.bandwidth();
            var y = yScale(name) + height / 2 - constants_1.SET_BAR_HEIGHT / 2;
            var lineY = yScale(name) + height;
            var barSize = hoveredElements ? elements.filter(function (el) { return hoveredElements.includes(el); }).length : size;
            return (react_1.default.createElement("g", { key: "set-group-".concat(i) },
                react_1.default.createElement("rect", { className: styles.setsBarBackground, x: 0, y: y, width: width, height: constants_1.SET_BAR_HEIGHT }),
                react_1.default.createElement("rect", { className: styles.setsBarDimmed, x: width - xScale(size), y: y, width: xScale(size), height: constants_1.SET_BAR_HEIGHT }),
                react_1.default.createElement("rect", { className: styles.setsBar, x: width - xScale(barSize), y: y, width: xScale(barSize), height: constants_1.SET_BAR_HEIGHT }),
                i !== sets.length - 1 && (react_1.default.createElement("line", { className: styles.gridLine, x1: 0, x2: hoverAreaWidth, y1: lineY, y2: lineY })),
                react_1.default.createElement("text", { className: styles.setsLabel, x: width + constants_1.TEXT_GAP, y: yScale(name) + height / 2 }, label),
                react_1.default.createElement("rect", { className: styles.hoverBar, "data-reltio-id": "set-hover-area", x: -constants_1.GAP_BEFORE_LEFT_BAR + 1, y: yScale(name), width: hoverAreaWidth - 2, height: height, onMouseEnter: function () { return onSetHover(set); }, onMouseLeave: function () { return onSetHover(null); } })));
        })));
};
exports.SetsChart = SetsChart;
