"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "Header", {
    enumerable: true,
    get: function() {
        return Header;
    }
});
const _jsxruntime = require("react/jsx-runtime");
const _react = require("react");
const _select = require("../../../select");
const _modal = require("../../../modal");
const _types = require("@orderly.network/types");
const _button = /*#__PURE__*/ _interop_require_default(require("../../../button"));
const _hooks = require("@orderly.network/hooks");
const _reacthottoast = /*#__PURE__*/ _interop_require_default(require("react-hot-toast"));
function _interop_require_default(obj) {
    return obj && obj.__esModule ? obj : {
        default: obj
    };
}
const Header = (props)=>{
    // const {orderType} = props;
    // const [cancelAll, { error: cancelOrderError, isMutating: cancelMutating }] =
    //   useMutation("/v1/orders", "DELETE");
    const [_, { cancelAllOrders, cancelAllTPSLOrders }] = (0, _hooks.useOrderStream)({});
    function cancelAllOrder() {
        _modal.modal.confirm({
            title: "Cancel all orders",
            content: /*#__PURE__*/ (0, _jsxruntime.jsx)("div", {
                className: "orderly-text-base-contrast-54 orderly-text-2xs desktop:orderly-text-sm",
                children: props.orderType === _types.AlgoOrderRootType.TP_SL ? "Are you sure you want to cancel all of your TP/SL orders?" : "Are you sure you want to cancel all of your pending order?"
            }),
            contentClassName: "desktop:orderly-w-[364px]",
            onOk: async ()=>{
                // do cancel all orders
                try {
                    // await cancelAll(null, { source_type: "ALL" });
                    if (props.orderType === _types.AlgoOrderRootType.TP_SL) {
                        await cancelAllTPSLOrders();
                    } else {
                        await cancelAllOrders();
                    }
                } catch (error) {
                    // @ts-ignore
                    if (error?.message !== undefined) {
                        // @ts-ignore
                        _reacthottoast.default.error(error.message);
                    }
                } finally{
                    Promise.resolve();
                }
            },
            onCancel: ()=>{
                return Promise.reject();
            }
        }).then((r)=>{}, (e)=>{});
    }
    const options = (0, _react.useMemo)(()=>{
        return [
            {
                label: "All sides",
                value: ""
            },
            {
                label: "Buy",
                value: _types.OrderSide.BUY
            },
            {
                label: "Sell",
                value: _types.OrderSide.SELL
            }
        ];
    }, []);
    return /*#__PURE__*/ (0, _jsxruntime.jsxs)("div", {
        className: "orderly-flex orderly-justify-between orderly-items-center orderly-py-3 orderly-font-semibold",
        children: [
            /*#__PURE__*/ (0, _jsxruntime.jsx)(_select.Select, {
                size: "small",
                options: options,
                value: props.side || "",
                onChange: (value)=>{
                    // console.log(value);
                    // setSide(value as OrderSide);
                    props.onSideChange(value);
                // props.onSearch?.({ side: value as OrderSide });
                }
            }),
            (props.status === "INCOMPLETE" || props.orderType === _types.AlgoOrderRootType.TP_SL) && /*#__PURE__*/ (0, _jsxruntime.jsx)(_button.default, {
                size: "small",
                variant: "outlined",
                disabled: props.count <= 0,
                color: "tertiary",
                onClick: cancelAllOrder,
                children: "Cancel all"
            })
        ]
    });
};

//# sourceMappingURL=header.js.map