import React, { useCallback } from "react";
import { useSelector } from "../../../store/redux-separate-context";
import { selectChartData } from "../selectors";
import { getNewSelectedDimensions } from "../utils/legend-utils";
import { ChartLegendRight } from "./chart-legend-right";
import { ChartLegendBottom } from "./chart-legend-bottom";
export const ChartLegend = ({ attributes, chartUuid, chartMetadata, chartLibrary, colors, hoveredRow, hoveredX, legendFormatValue, selectedDimensions, setSelectedDimensions, showLatestOnBlur, unitsCurrent, viewBefore, legendToolbox, resizeHandler, }) => {
    const dimension_names = useSelector(useCallback((state) => selectChartData(state, { id: chartUuid }).dimension_names, [
        chartUuid,
    ]));
    const onDimensionClick = (clickedDimensionName, event) => {
        event.preventDefault();
        const isModifierKeyPressed = event.shiftKey || event.ctrlKey;
        const newSelectedDimensions = getNewSelectedDimensions({
            allDimensions: dimension_names,
            selectedDimensions,
            clickedDimensionName,
            isModifierKeyPressed,
        });
        setSelectedDimensions(newSelectedDimensions);
    };
    if (attributes.legendPosition === "bottom") {
        return (React.createElement(ChartLegendBottom, { chartUuid: chartUuid, chartLibrary: chartLibrary, chartMetadata: chartMetadata, colors: colors, hoveredRow: hoveredRow, hoveredX: hoveredX, legendFormatValue: legendFormatValue, onDimensionClick: onDimensionClick, selectedDimensions: selectedDimensions, showLatestOnBlur: showLatestOnBlur, unitsCurrent: unitsCurrent, viewBefore: viewBefore, legendToolbox: legendToolbox, resizeHandler: resizeHandler }));
    }
    return (React.createElement(ChartLegendRight, { chartUuid: chartUuid, chartLibrary: chartLibrary, chartMetadata: chartMetadata, colors: colors, hoveredRow: hoveredRow, hoveredX: hoveredX, legendFormatValue: legendFormatValue, onDimensionClick: onDimensionClick, selectedDimensions: selectedDimensions, showLatestOnBlur: showLatestOnBlur, unitsCurrent: unitsCurrent, viewBefore: viewBefore }));
};
//# sourceMappingURL=chart-legend.js.map