import { jsx as _jsx } from "react/jsx-runtime";
import HighchartsReact from "highcharts-react-official";
import Highcharts from "highcharts/highstock";
import cloneDeep from "lodash/cloneDeep";
import React from "react";
import { Wrapper } from "./styled";
const defaultOptions = {
    series: [
        {
            type: "line",
            data: [],
        },
    ],
};
class Chart extends React.Component {
    state = {
        options: defaultOptions,
        dataAttached: false,
        chartRef: React.createRef(),
    };
    attachSeriesToOptions(series, options) {
        if (!this.state.dataAttached &&
            Array.isArray(options.series) &&
            options.series.length === series.length &&
            series[0] &&
            series[0].length > 0) {
            const res = cloneDeep(options);
            for (let i = 0; i < res.series.length; i++) {
                // @ts-ignore
                res.series[i] = { ...res.series[i], data: [...series[i]] };
            }
            this.setState({ options: res, dataAttached: true });
        }
    }
    componentDidMount() {
        const { options, series } = this.props;
        if (options && series && series[0] && series[0].length > 0) {
            this.attachSeriesToOptions(series, options);
        }
    }
    render() {
        return (_jsx(Wrapper, { className: "ui-stockchart", children: this.state.dataAttached && _jsx(HighchartsReact, { highcharts: Highcharts, constructorType: "stockChart", options: this.state.options, ref: this.state.chartRef }) }));
    }
}
export default Chart;
//# sourceMappingURL=index.js.map