import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { useMemo, useState } from "react";
import { usePositionsRowContext } from "./positionRowContext";
import { Popover, PopoverContent, PopoverTrigger } from "../../../popover";
import { OrderType } from "@orderly.network/types";
import { useSymbolContext } from "../../../provider/symbolProvider";
import { cn } from "../../../utils/css";
import { toast } from "../../../toast";
import { TPSLEditor } from "../../../block/tp_sl/tp_sl_editor";
export const TPSLButton = ()=>{
    const [open, setOpen] = useState(false);
    const { onSubmit, price, quantity, closeOrderData, type, submitting, position, tpslOrder } = usePositionsRowContext();
    const { base, quote, symbol, quote_dp: priceDp } = useSymbolContext();
    const onConfirm = ()=>{
        return onSubmit().then((res)=>{
            setOpen(false);
        }, (error)=>{
            toast.error(error.message);
        });
    };
    const onClose = ()=>{
        setOpen(false);
    };
    const disabled = useMemo(()=>{
        if (type === OrderType.MARKET) {
            if (!quantity) {
                return true;
            }
            return false;
        }
        return !price || !quantity;
    }, [
        price,
        quantity,
        type
    ]);
    return /*#__PURE__*/ _jsxs(Popover, {
        onOpenChange: setOpen,
        open: open,
        children: [
            /*#__PURE__*/ _jsx(PopoverTrigger, {
                asChild: true,
                children: /*#__PURE__*/ _jsx("button", {
                    // disabled={disabled}
                    className: 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__*/ _jsx(PopoverContent, {
                align: "end",
                side: "top",
                className: "orderly-w-[375px] orderly-ui-tp_sl-poper",
                onOpenAutoFocus: (e)=>{
                    e.preventDefault();
                },
                children: /*#__PURE__*/ _jsx(TPSLEditor, {
                    maxQty: Number(quantity),
                    symbol: symbol,
                    onCancel: onClose,
                    position: position,
                    onSuccess: onClose,
                    order: tpslOrder,
                    quoteDp: priceDp
                })
            })
        ]
    });
};

//# sourceMappingURL=tpslButton.js.map