"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "StatusGuardButton", {
    enumerable: true,
    get: function() {
        return StatusGuardButton;
    }
});
const _jsxruntime = require("react/jsx-runtime");
const _react = require("react");
const _button = require("../../button/button");
const _hooks = require("@orderly.network/hooks");
const _types = require("@orderly.network/types");
const _provider = require("../../provider");
const _walletModal = require("../../block/walletConnect/walletModal");
const StatusGuardButton = (props)=>{
    const { state } = (0, _hooks.useAccount)();
    const { onWalletConnect } = (0, _react.useContext)(_provider.OrderlyAppContext);
    const onClick = (0, _react.useCallback)(async ()=>{
        if (state.status === _types.AccountStatusEnum.NotConnected) {
            try {
                const result = await onWalletConnect();
                if (result && result.status < _types.AccountStatusEnum.EnableTrading) {
                    return await (0, _walletModal.showAccountConnectorModal)({
                        status: result.status
                    });
                } else {
                    return result;
                }
            } catch (e) {}
        } else if (state.status < _types.AccountStatusEnum.EnableTrading) {
            try {
                return await (0, _walletModal.showAccountConnectorModal)({
                    status: state.status
                });
            } catch (err) {}
        }
    }, [
        state
    ]);
    const buttonLabel = (0, _react.useMemo)(()=>{
        if (state.status === _types.AccountStatusEnum.NotConnected) {
            return "Connect wallet";
        }
        if (state.status < _types.AccountStatusEnum.SignedIn) {
            return "Sign in";
        }
        if (state.status < _types.AccountStatusEnum.EnableTrading) {
            return "Enable Trading";
        }
        return "-";
    }, [
        state.status
    ]);
    if (state.status < _types.AccountStatusEnum.EnableTrading) {
        if (typeof props.placeholder === "undefined") {
            return /*#__PURE__*/ (0, _jsxruntime.jsx)(_button.Button, {
                id: props.id,
                type: "button",
                fullWidth: true,
                onClick: ()=>onClick(),
                className: "desktop:orderly-font-bold desktop:orderly-text-sm",
                children: buttonLabel
            });
        }
        return /*#__PURE__*/ (0, _jsxruntime.jsx)(_jsxruntime.Fragment, {
            children: props.placeholder
        });
    }
    return /*#__PURE__*/ (0, _jsxruntime.jsx)(_jsxruntime.Fragment, {
        children: props.children
    });
};

//# sourceMappingURL=statusGuardButton.js.map