import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import React from "react";
import { useCallback, useState } from "react";
import { TimeIntervalToolbar } from "./timeIntervalToolbar";
import { TradingView, ChartMode } from "@orderly.network/trading-view";
import { toast } from "../../toast";
import { Spinner } from "../../spinner";
export const TradingViewChart = (props)=>{
    const { intervals } = props;
    const [timeInterval, setTimeInterval] = useState(()=>{
        const tradingViewSDK_adapter = localStorage.getItem("TradingViewSDK_adapter");
        if (tradingViewSDK_adapter) {
            const data = JSON.parse(tradingViewSDK_adapter);
            const savedIntervals = data["chart.lastUsedTimeBasedResolution"];
            return savedIntervals || "1";
        }
        return "1";
    });
    const onIntervalChange = useCallback((interval)=>{
        setTimeInterval(interval);
    }, []);
    if (!props.scriptSRC) {
        return null;
    }
    return /*#__PURE__*/ _jsxs("div", {
        className: "orderly-h-[240px]",
        children: [
            /*#__PURE__*/ _jsx(TimeIntervalToolbar, {
                intervals: intervals,
                timeInterval: timeInterval,
                onIntervalChange: (timeInterval)=>{
                    onIntervalChange(timeInterval);
                }
            }),
            /*#__PURE__*/ _jsx(TradingView, {
                symbol: props.symbol,
                mode: ChartMode.MOBILE,
                interval: timeInterval,
                libraryPath: props.library_path,
                tradingViewScriptSrc: props?.scriptSRC,
                tradingViewCustomCssUrl: props?.customCssUrl,
                overrides: props.overrides,
                onToast: toast,
                loadingElement: /*#__PURE__*/ _jsx(Spinner, {})
            })
        ]
    });
};

//# sourceMappingURL=tradingView.js.map