/* eslint-disable react-hooks/exhaustive-deps */ // remove when ready to fix these.
import React from "react";
import { DiscreteColorLegend, ContinuousLegend, } from "@emerson-eps/color-tables";
/**
 * Type guard function that determines if the legend data is discrete or continuous.
 * Narrows the type of the data parameter to DiscreteLegendDataType when it returns true.
 *
 * @param data - The legend data to check, can be either discrete or continuous type
 * @returns True if the data is of discrete type, false otherwise
 */
function isDiscrete(data) {
    return data.discrete;
}
function toDiscreteCodes(data) {
    return data.metadata;
}
const ColorLegend = ({ horizontal, layer, colorTables, reverseRange, }) => {
    var _a;
    const [legendData, setLegendData] = React.useState();
    React.useEffect(() => {
        var _a, _b, _c;
        const legend_data = (_b = (_a = layer.getLegendData) === null || _a === void 0 ? void 0 : _a.call(layer)) !== null && _b !== void 0 ? _b : (_c = layer.state) === null || _c === void 0 ? void 0 : _c["legend"];
        setLegendData(legend_data);
    }, [layer.props, (_a = layer.state) === null || _a === void 0 ? void 0 : _a["legend"]]);
    if (!legendData || !layer.props.visible)
        return null;
    return (React.createElement("div", { style: { marginTop: 30 } },
        isDiscrete(legendData) && (React.createElement(DiscreteColorLegend, { discreteData: toDiscreteCodes(legendData), dataObjectName: legendData.title, colorName: legendData.colorName, horizontal: horizontal, colorTables: colorTables })),
        !isDiscrete(legendData) && (React.createElement(ContinuousLegend, { min: legendData.valueRange[0], max: legendData.valueRange[1], dataObjectName: legendData.title, colorName: legendData.colorName, horizontal: horizontal, id: layer.props.id, colorTables: colorTables, colorMapFunction: legendData.colorMapFunction, reverseRange: reverseRange }))));
};
export default ColorLegend;
//# sourceMappingURL=ColorLegend.js.map