"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "default", {
    enumerable: true,
    get: function() {
        return TopTips;
    }
});
const _jsxruntime = require("react/jsx-runtime");
const _react = require("react");
const _provider = require("../../../provider");
const _hooks = require("@orderly.network/hooks");
const _WsStatus = require("../../../block/accountStatus/sections/WsStatus");
const _chainIdSwitch = require("../../../block/accountStatus/sections/chainIdSwitch");
const _maintenanceStatusTips = require("../../../block/accountStatus/sections/maintenanceStatusTips");
const _maintenanceDialog = require("../../../block/accountStatus/sections/maintenanceDialog");
const oneDay = 1000 * 60 * 60 * 24;
function TopTips() {
    const [showMaintenanceTips, setShowMaintenanceTips] = (0, _react.useState)(false);
    const [showMaintenanceDialog, setShowMaintenanceDialog] = (0, _react.useState)(false);
    const { errors } = (0, _react.useContext)(_provider.OrderlyAppContext);
    const { status, startTime, endTime, brokerName } = (0, _hooks.useMaintenanceStatus)();
    const { ws: wsStatus } = (0, _react.useContext)(_hooks.StatusContext);
    const { onSetChain } = (0, _react.useContext)(_provider.OrderlyAppContext);
    (0, _react.useEffect)(()=>{
        if (status === 2) {
            setShowMaintenanceTips(false);
            setShowMaintenanceDialog(true);
            return;
        }
        setShowMaintenanceDialog(false);
        if (startTime) {
            if (startTime < new Date().getTime() + oneDay) {
                // check localstorage
                if (!window.localStorage.getItem(`Maintenance_${startTime}`)) {
                    setShowMaintenanceTips(true);
                }
            }
        }
    }, [
        startTime,
        status
    ]);
    if (showMaintenanceTips) {
        return /*#__PURE__*/ (0, _jsxruntime.jsx)(_maintenanceStatusTips.MaintenanceStatusTips, {
            brokerName: brokerName,
            startTime: startTime ?? 0,
            endTime: endTime ?? 0,
            onClose: ()=>setShowMaintenanceTips(false)
        });
    }
    if (showMaintenanceDialog) {
        return /*#__PURE__*/ (0, _jsxruntime.jsx)(_maintenanceDialog.MaintenanceDialog, {
            open: showMaintenanceDialog,
            onOpenChange: setShowMaintenanceDialog,
            brokerName: brokerName,
            startTime: startTime ?? 0,
            endTime: endTime ?? 0
        });
    }
    if (wsStatus === _hooks.WsNetworkStatus.Unstable) {
        return /*#__PURE__*/ (0, _jsxruntime.jsx)(_WsStatus.WsStatus, {});
    }
    if (errors.ChainNetworkNotSupport) {
        return /*#__PURE__*/ (0, _jsxruntime.jsx)(_chainIdSwitch.ChainIdSwtich, {
            onSetChain: onSetChain
        });
    }
    return /*#__PURE__*/ (0, _jsxruntime.jsx)(_jsxruntime.Fragment, {});
}

//# sourceMappingURL=topTips.js.map