import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { useEffect, useRef } from "react";
import { toast } from "../../../../toast";
import { getOrderExecutionReportMsg } from "../../../../block/orders/getOrderExecutionReportMsg";
import { useSymbolsInfo, useEventEmitter, useDebouncedCallback } from "@orderly.network/hooks";
export function useExecutionReport() {
    const ee = useEventEmitter();
    const symbolsInfo = useSymbolsInfo();
    const symbolsInfoRef = useRef({});
    useEffect(()=>{
        symbolsInfoRef.current = symbolsInfo;
    }, [
        symbolsInfo
    ]);
    const handler = useDebouncedCallback((data)=>{
        const showToast = (data)=>{
            const { title, msg } = getOrderExecutionReportMsg(data, symbolsInfoRef.current);
            if (title && msg) {
                toast.success(/*#__PURE__*/ _jsxs("div", {
                    children: [
                        title,
                        /*#__PURE__*/ _jsx("br", {}),
                        /*#__PURE__*/ _jsx("div", {
                            className: "orderly-text-white/[0.54]",
                            children: msg
                        })
                    ]
                }));
            }
        };
        showToast(data);
    }, 100);
    useEffect(()=>{
        ee.on("orders:changed", handler);
        return ()=>{
            ee.off("orders:changed", handler);
        };
    }, []);
}

//# sourceMappingURL=useExecutionReport.js.map