"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "useExecutionReport", {
    enumerable: true,
    get: function() {
        return useExecutionReport;
    }
});
const _jsxruntime = require("react/jsx-runtime");
const _react = require("react");
const _toast = require("../../../../toast");
const _getOrderExecutionReportMsg = require("../../../../block/orders/getOrderExecutionReportMsg");
const _hooks = require("@orderly.network/hooks");
function useExecutionReport() {
    const ee = (0, _hooks.useEventEmitter)();
    const symbolsInfo = (0, _hooks.useSymbolsInfo)();
    const symbolsInfoRef = (0, _react.useRef)({});
    (0, _react.useEffect)(()=>{
        symbolsInfoRef.current = symbolsInfo;
    }, [
        symbolsInfo
    ]);
    const handler = (0, _hooks.useDebouncedCallback)((data)=>{
        const showToast = (data)=>{
            const { title, msg } = (0, _getOrderExecutionReportMsg.getOrderExecutionReportMsg)(data, symbolsInfoRef.current);
            if (title && msg) {
                _toast.toast.success(/*#__PURE__*/ (0, _jsxruntime.jsxs)("div", {
                    children: [
                        title,
                        /*#__PURE__*/ (0, _jsxruntime.jsx)("br", {}),
                        /*#__PURE__*/ (0, _jsxruntime.jsx)("div", {
                            className: "orderly-text-white/[0.54]",
                            children: msg
                        })
                    ]
                }));
            }
        };
        showToast(data);
    }, 100);
    (0, _react.useEffect)(()=>{
        ee.on("orders:changed", handler);
        return ()=>{
            ee.off("orders:changed", handler);
        };
    }, []);
}

//# sourceMappingURL=useExecutionReport.js.map