"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "TPSLButton", {
    enumerable: true,
    get: function() {
        return TPSLButton;
    }
});
const _jsxruntime = require("react/jsx-runtime");
const _react = require("react");
const _positionRowContext = require("./positionRowContext");
const _popover = require("../../../popover");
const _types = require("@orderly.network/types");
const _symbolProvider = require("../../../provider/symbolProvider");
const _css = require("../../../utils/css");
const _toast = require("../../../toast");
const _tp_sl_editor = require("../../../block/tp_sl/tp_sl_editor");
const TPSLButton = ()=>{
    const [open, setOpen] = (0, _react.useState)(false);
    const { onSubmit, price, quantity, closeOrderData, type, submitting, position, tpslOrder } = (0, _positionRowContext.usePositionsRowContext)();
    const { base, quote, symbol, quote_dp: priceDp } = (0, _symbolProvider.useSymbolContext)();
    const onConfirm = ()=>{
        return onSubmit().then((res)=>{
            setOpen(false);
        }, (error)=>{
            _toast.toast.error(error.message);
        });
    };
    const onClose = ()=>{
        setOpen(false);
    };
    const disabled = (0, _react.useMemo)(()=>{
        if (type === _types.OrderType.MARKET) {
            if (!quantity) {
                return true;
            }
            return false;
        }
        return !price || !quantity;
    }, [
        price,
        quantity,
        type
    ]);
    return /*#__PURE__*/ (0, _jsxruntime.jsxs)(_popover.Popover, {
        onOpenChange: setOpen,
        open: open,
        children: [
            /*#__PURE__*/ (0, _jsxruntime.jsx)(_popover.PopoverTrigger, {
                asChild: true,
                children: /*#__PURE__*/ (0, _jsxruntime.jsx)("button", {
                    // disabled={disabled}
                    className: (0, _css.cn)("orderly-border orderly-border-base-contrast-36 orderly-text-base-contrast-54 orderly-rounded orderly-w-full orderly-h-[28px] hover:orderly-bg-base-contrast/10 disabled:orderly-opacity-50 disabled:orderly-cursor-not-allowed", {
                        "orderly-text-base-contrast-80 orderly-border-base-contrast-80": open
                    }),
                    children: "TP/SL"
                })
            }),
            /*#__PURE__*/ (0, _jsxruntime.jsx)(_popover.PopoverContent, {
                align: "end",
                side: "top",
                className: "orderly-w-[375px] orderly-ui-tp_sl-poper",
                onOpenAutoFocus: (e)=>{
                    e.preventDefault();
                },
                children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_tp_sl_editor.TPSLEditor, {
                    maxQty: Number(quantity),
                    symbol: symbol,
                    onCancel: onClose,
                    position: position,
                    onSuccess: onClose,
                    order: tpslOrder,
                    quoteDp: priceDp
                })
            })
        ]
    });
};

//# sourceMappingURL=tpslButton.js.map