"use strict";
var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
var __rest = (this && this.__rest) || function (s, e) {
    var t = {};
    for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
        t[p] = s[p];
    if (s != null && typeof Object.getOwnPropertySymbols === "function")
        for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
            if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                t[p[i]] = s[p[i]];
        }
    return t;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.BarChart = void 0;
var react_1 = __importDefault(require("react"));
var recharts_1 = require("recharts");
var ChartTooltip_1 = require("../ChartTooltip");
var useClickableChartStyle_1 = require("../hooks/useClickableChartStyle");
var useDynamicYAxisWidth_1 = require("../hooks/useDynamicYAxisWidth");
var helpers_1 = require("./helpers");
var BarChart = function (_a) {
    var width = _a.width, height = _a.height, data = _a.data, _b = _a.options, options = _b === void 0 ? {} : _b, onItemClick = _a.onItemClick;
    var _c = (0, helpers_1.getBarChartSettings)(options), barChart = _c.barChart, cartesianGrid = _c.cartesianGrid, bar = _c.bar, tooltip = _c.tooltip, xAxis = _c.xAxis, yAxis = _c.yAxis;
    var _d = (0, useDynamicYAxisWidth_1.useDynamicYAxisWidth)({ chartYAxisProps: yAxis }), chartRef = _d.chartRef, dynamicYAxisWidth = __rest(_d, ["chartRef"]);
    var onBarClick = onItemClick && (function (_a) {
        var group = _a.group;
        return onItemClick(group);
    });
    var clickable = (0, useClickableChartStyle_1.useClickableChartStyle)(onBarClick);
    return (react_1.default.createElement(recharts_1.BarChart, __assign({ width: width, height: height, data: data }, barChart, { ref: chartRef }),
        react_1.default.createElement(recharts_1.CartesianGrid, __assign({}, cartesianGrid)),
        react_1.default.createElement(recharts_1.Tooltip, __assign({ content: react_1.default.createElement(ChartTooltip_1.ChartTooltip, null) }, tooltip)),
        react_1.default.createElement(recharts_1.Bar, __assign({}, bar, { shape: react_1.default.createElement(recharts_1.Rectangle, { className: clickable }), onClick: onBarClick })),
        react_1.default.createElement(recharts_1.XAxis, __assign({}, xAxis)),
        react_1.default.createElement(recharts_1.YAxis, __assign({}, yAxis, dynamicYAxisWidth))));
};
exports.BarChart = BarChart;
