import React from "react";
import { DiscreteColorLegend, ContinuousLegend, } from "@emerson-eps/color-tables";
// Todo: Adapt it for other layers too
const ColorLegend = ({ cssStyle, horizontal, layers, }) => {
    const [legendProps, setLegendProps] = React.useState([
        {
            title: "",
            colorName: "string",
            discrete: false,
            metadata: { objects: {} },
            valueRange: [],
            visible: true,
        },
    ]);
    // Get color table for log curves.
    React.useEffect(() => {
        if (!layers)
            return;
        // eslint-disable-next-line @typescript-eslint/no-explicit-any
        const getLegendData = [];
        // eslint-disable-next-line @typescript-eslint/no-explicit-any
        layers.map((layer) => {
            var _a, _b, _c, _d, _e, _f, _g, _h, _j;
            if ((layer === null || layer === void 0 ? void 0 : layer.id) == "wells-layer" &&
                (layer === null || layer === void 0 ? void 0 : layer.isLoaded) &&
                Object.keys(layer === null || layer === void 0 ? void 0 : layer.state).length > 0) {
                getLegendData.push({
                    title: (_a = layer === null || layer === void 0 ? void 0 : layer.state) === null || _a === void 0 ? void 0 : _a.legend[0].title,
                    colorName: (_b = layer === null || layer === void 0 ? void 0 : layer.props) === null || _b === void 0 ? void 0 : _b.logColor,
                    discrete: (_c = layer === null || layer === void 0 ? void 0 : layer.state) === null || _c === void 0 ? void 0 : _c.legend[0].discrete,
                    metadata: (_d = layer === null || layer === void 0 ? void 0 : layer.state) === null || _d === void 0 ? void 0 : _d.legend[0].metadata,
                    valueRange: (_e = layer === null || layer === void 0 ? void 0 : layer.state) === null || _e === void 0 ? void 0 : _e.legend[0].valueRange,
                    visible: (_f = layer === null || layer === void 0 ? void 0 : layer.props) === null || _f === void 0 ? void 0 : _f.visible,
                });
            }
            if ((layer === null || layer === void 0 ? void 0 : layer.id) == "colormap-layer" &&
                (layer === null || layer === void 0 ? void 0 : layer.isLoaded) &&
                Object.keys(layer === null || layer === void 0 ? void 0 : layer.state).length > 0) {
                const min = layer === null || layer === void 0 ? void 0 : layer.state.model.uniforms.colorMapRangeMin;
                const max = layer === null || layer === void 0 ? void 0 : layer.state.model.uniforms.colorMapRangeMax;
                getLegendData.push({
                    title: (_g = layer === null || layer === void 0 ? void 0 : layer.props) === null || _g === void 0 ? void 0 : _g.name,
                    colorName: (_h = layer === null || layer === void 0 ? void 0 : layer.props) === null || _h === void 0 ? void 0 : _h.colorMapName,
                    discrete: false,
                    metadata: { objects: {} },
                    valueRange: [min, max],
                    visible: (_j = layer === null || layer === void 0 ? void 0 : layer.props) === null || _j === void 0 ? void 0 : _j.visible,
                });
            }
        });
        setLegendProps(getLegendData);
    }, [layers]);
    return (React.createElement("div", { style: Object.assign({ position: "absolute", display: "flex", zIndex: 999 }, cssStyle) }, legendProps.map((legend, index) => {
        var _a;
        return legend.visible && (React.createElement("div", { key: index },
            legend.discrete && (React.createElement(DiscreteColorLegend, { discreteData: legend.metadata, dataObjectName: legend.title, colorName: legend.colorName, horizontal: horizontal })),
            ((_a = legend.valueRange) === null || _a === void 0 ? void 0 : _a.length) > 0 && legend && (React.createElement(ContinuousLegend, { min: legend.valueRange[0], max: legend.valueRange[1], dataObjectName: legend.title, colorName: legend.colorName, horizontal: horizontal }))));
    })));
};
ColorLegend.defaultProps = {
    horizontal: false,
};
export default ColorLegend;
//# sourceMappingURL=ColorLegend.js.map