"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "default", {
    enumerable: true,
    get: function() {
        return MyTradingView;
    }
});
const _jsxruntime = require("react/jsx-runtime");
const _provider = require("../../../../../../provider");
const _toast = require("../../../../../../toast");
const _spinner = require("../../../../../../spinner");
const _react = require("react");
const _tradingview = require("@orderly.network/trading-view");
const _topBar = /*#__PURE__*/ _interop_require_default(require("./topBar"));
function _interop_require_default(obj) {
    return obj && obj.__esModule ? obj : {
        default: obj
    };
}
function MyTradingView({ symbol, tradingViewConfig }) {
    const [interval, setInterval] = (0, _react.useState)(()=>{
        const lastUsedInterval = localStorage.getItem(_tradingview.TradingViewSDKLocalstorageKey.interval);
        if (!lastUsedInterval) {
            return "1";
        }
        return lastUsedInterval;
    });
    const [displayControlState, setDisplayControlState] = (0, _react.useState)(()=>{
        const displaySettingInfo = localStorage.getItem(_tradingview.TradingViewSDKLocalstorageKey.displayControlSetting);
        if (displaySettingInfo) {
            return JSON.parse(displaySettingInfo);
        }
        return {
            position: true,
            buySell: true,
            limitOrders: true,
            stopOrders: true,
            tpsl: true,
            positionTpsl: true
        };
    });
    const changeInterval = (newInterval)=>{
        localStorage.setItem(_tradingview.TradingViewSDKLocalstorageKey.interval, newInterval);
        setInterval(newInterval);
    };
    const changeDisplaySetting = (newSetting)=>{
        localStorage.setItem(_tradingview.TradingViewSDKLocalstorageKey.displayControlSetting, JSON.stringify(newSetting));
        setDisplayControlState(newSetting);
    };
    return /*#__PURE__*/ (0, _jsxruntime.jsx)("div", {
        className: "orderly-flex orderly-flex-col orderly-h-[240px]",
        style: {
            position: "relative",
            width: "100%"
        },
        children: /*#__PURE__*/ (0, _jsxruntime.jsxs)(_provider.SymbolProvider, {
            symbol: symbol,
            children: [
                /*#__PURE__*/ (0, _jsxruntime.jsx)(_topBar.default, {
                    changeInterval: (interval)=>changeInterval(interval),
                    interval: interval,
                    displayControlState: displayControlState,
                    changeDisplaySetting: changeDisplaySetting
                }),
                /*#__PURE__*/ (0, _jsxruntime.jsx)("div", {
                    className: "orderly-flex-1",
                    children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_tradingview.TradingView, {
                        mode: _tradingview.ChartMode.MOBILE,
                        symbol: symbol,
                        interval: interval.toString(),
                        libraryPath: tradingViewConfig?.library_path,
                        tradingViewScriptSrc: tradingViewConfig?.scriptSRC,
                        tradingViewCustomCssUrl: tradingViewConfig?.customCssUrl,
                        overrides: tradingViewConfig?.overrides,
                        studiesOverrides: tradingViewConfig?.studiesOverrides,
                        onToast: _toast.toast,
                        loadingElement: /*#__PURE__*/ (0, _jsxruntime.jsx)(_spinner.Spinner, {}),
                        displayControlSetting: displayControlState,
                        colorConfig: tradingViewConfig?.colorConfig
                    })
                })
            ]
        })
    });
}

//# sourceMappingURL=index.js.map