"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));
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.IntersectionsChart = void 0;
var react_1 = __importStar(require("react"));
var d3_scale_1 = require("d3-scale");
var IntersectionsChartAxis_1 = require("../IntersectionsChartAxis");
var constants_1 = require("../../constants");
var styles_1 = require("./styles");
var IntersectionsChart = function (_a) {
    var xScale = _a.xScale, width = _a.width, height = _a.height, transform = _a.transform, matrixHeight = _a.matrixHeight, intersections = _a.intersections, highlightedElements = _a.highlightedElements, onIntersectionHover = _a.onIntersectionHover;
    var styles = (0, styles_1.useStyles)();
    var yScale = (0, react_1.useMemo)(function () {
        var intersectionsSizes = intersections.map(function (intersection) { return intersection.size; });
        var domain = [0, Math.max.apply(Math, __spreadArray([0], intersectionsSizes, false))];
        return (0, d3_scale_1.scaleLinear)([height, 0]).domain(domain);
    }, [intersections, height]);
    return (react_1.default.createElement("g", { transform: transform },
        react_1.default.createElement(IntersectionsChartAxis_1.IntersectionsChartAxis, { xScale: xScale, yScale: yScale, width: width, height: height }),
        intersections.map(function (intersection, i) {
            var elements = intersection.elements, size = intersection.size;
            var x = xScale(String(i));
            var y = yScale(size);
            var width = xScale.bandwidth();
            var barY = highlightedElements
                ? yScale(elements.filter(function (el) { return highlightedElements.includes(el); }).length)
                : y;
            return (react_1.default.createElement("g", { key: "intersection-group-".concat(i) },
                react_1.default.createElement("rect", { className: styles.barBackground, x: x, y: y, width: width, height: height - y }),
                react_1.default.createElement("text", { className: styles.barLabel, x: x + width / 2, y: y - 4 }, size),
                react_1.default.createElement("rect", { className: styles.bar, x: x, y: barY, width: width, height: height - barY }),
                react_1.default.createElement("rect", { className: styles.hoverBar, "data-reltio-id": "intersection-hover-area", x: x, y: y, width: width, height: height - y + matrixHeight + constants_1.GAP_BETWEEN_TABLE_AND_CHART - 1, onMouseEnter: function () { return onIntersectionHover(intersection); }, onMouseLeave: function () { return onIntersectionHover(null); } })));
        })));
};
exports.IntersectionsChart = IntersectionsChart;
