"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.debuggerMiddleWareManager = exports.getLastScriptEval = void 0;
const tslib_1 = require("tslib");
const types_1 = require("tdf-devtools-protocol/dist/types");
const global_id_1 = require("@/utils/global-id");
const default_middleware_1 = require("../default-middleware");
let lastScriptEval;
const getLastScriptEval = () => lastScriptEval;
exports.getLastScriptEval = getLastScriptEval;
exports.debuggerMiddleWareManager = {
    downwardMiddleWareListMap: {
        [types_1.ChromeEvent.DebuggerScriptParsed]: ({ msg, sendToDevtools }) => {
            const eventRes = msg;
            delete eventRes.params.module;
            eventRes.params = Object.assign(Object.assign({}, eventRes.params), { hasSourceURL: !!eventRes.params.sourceURL, isModule: eventRes.params.module, scriptLanguage: types_1.ScriptLanguage.JavaScript, url: eventRes.params.url || eventRes.params.sourceURL });
            lastScriptEval = eventRes.params.scriptId;
            return sendToDevtools(eventRes);
        },
        [types_1.IOS90Command.DebuggerEnable]: default_middleware_1.sendEmptyResultToDevtools,
        [types_1.ChromeCommand.DebuggerSetBlackboxPatterns]: default_middleware_1.sendEmptyResultToDevtools,
        // TODO ios 支持
        [types_1.IOS90Command.DebuggerSetPauseOnExceptions]: default_middleware_1.sendEmptyResultToDevtools,
    },
    upwardMiddleWareListMap: {
        [types_1.ChromeCommand.DebuggerEnable]: ({ sendToApp, msg }) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
            sendToApp({
                id: global_id_1.requestId.create(),
                method: types_1.ChromeCommand.DebuggerSetBreakpointsActive,
                params: { active: true },
            });
            return sendToApp(msg);
        }),
        [types_1.ChromeCommand.DebuggerSetBlackboxPatterns]: ({ msg, sendToDevtools }) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
            const res = {
                id: msg.id,
                method: msg.method,
                result: {},
            };
            sendToDevtools(res);
            return res;
        }),
        [types_1.ChromeCommand.RuntimeSetAsyncCallStackDepth]: ({ msg, sendToDevtools }) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
            const res = {
                id: msg.id,
                method: msg.method,
                result: true,
            };
            sendToDevtools(res);
            return res;
        }),
        [types_1.ChromeCommand.DebuggerSetAsyncCallStackDepth]: default_middleware_1.sendEmptyResultToDevtools,
    },
};
