"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "TradingViewChart", {
    enumerable: true,
    get: function() {
        return TradingViewChart;
    }
});
const _jsxruntime = require("react/jsx-runtime");
const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
const _timeIntervalToolbar = require("./timeIntervalToolbar");
const _tradingview = require("@orderly.network/trading-view");
const _toast = require("../../toast");
const _spinner = require("../../spinner");
function _getRequireWildcardCache(nodeInterop) {
    if (typeof WeakMap !== "function") return null;
    var cacheBabelInterop = new WeakMap();
    var cacheNodeInterop = new WeakMap();
    return (_getRequireWildcardCache = function(nodeInterop) {
        return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
    })(nodeInterop);
}
function _interop_require_wildcard(obj, nodeInterop) {
    if (!nodeInterop && obj && obj.__esModule) {
        return obj;
    }
    if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
        return {
            default: obj
        };
    }
    var cache = _getRequireWildcardCache(nodeInterop);
    if (cache && cache.has(obj)) {
        return cache.get(obj);
    }
    var newObj = {
        __proto__: null
    };
    var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
    for(var key in obj){
        if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
            var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
            if (desc && (desc.get || desc.set)) {
                Object.defineProperty(newObj, key, desc);
            } else {
                newObj[key] = obj[key];
            }
        }
    }
    newObj.default = obj;
    if (cache) {
        cache.set(obj, newObj);
    }
    return newObj;
}
const TradingViewChart = (props)=>{
    const { intervals } = props;
    const [timeInterval, setTimeInterval] = (0, _react.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 = (0, _react.useCallback)((interval)=>{
        setTimeInterval(interval);
    }, []);
    if (!props.scriptSRC) {
        return null;
    }
    return /*#__PURE__*/ (0, _jsxruntime.jsxs)("div", {
        className: "orderly-h-[240px]",
        children: [
            /*#__PURE__*/ (0, _jsxruntime.jsx)(_timeIntervalToolbar.TimeIntervalToolbar, {
                intervals: intervals,
                timeInterval: timeInterval,
                onIntervalChange: (timeInterval)=>{
                    onIntervalChange(timeInterval);
                }
            }),
            /*#__PURE__*/ (0, _jsxruntime.jsx)(_tradingview.TradingView, {
                symbol: props.symbol,
                mode: _tradingview.ChartMode.MOBILE,
                interval: timeInterval,
                libraryPath: props.library_path,
                tradingViewScriptSrc: props?.scriptSRC,
                tradingViewCustomCssUrl: props?.customCssUrl,
                overrides: props.overrides,
                onToast: _toast.toast,
                loadingElement: /*#__PURE__*/ (0, _jsxruntime.jsx)(_spinner.Spinner, {})
            })
        ]
    });
};

//# sourceMappingURL=tradingView.js.map