import type { TencentQianWebViewConfig } from '../model/TencentQianWebViewConfig';
import type { OnSignResult, OnSdkEvent } from '../model/SignCallback';
import { SignResult } from "@normalized:N&&&tencentqianwebview/src/main/ets/model/SignResult&1.0.0";
class BjcCov {
    coverage: {
        [key: string]: string | number;
    };
    constructor(covData: object) {
        const gcv = "__coverage__";
        let coverage = globalThis[gcv] || (globalThis[gcv] = {
        /**
         * 携带的容器入参集合。
         */
        });
        if (!coverage[covData.path] && true) {
            coverage[covData.path] = covData;
        }
        this.coverage = coverage[covData.path];
    }
    instrumentFunction(func: number) {
        this.coverage.functions[func].count++;
        this.coverage.functions[func].regions[0].count++;
    }
    instrumentRegion(func: number, region: number) {
        this.coverage.functions[func].regions[region].count++;
    }
    instrumentReturn(func: number, retIdx: number) {
        this.coverage.functions[func].returnes[retIdx].count++;
    }
    instrumentBranch(func: number, branch: number, trueOrFalse: boolean) {
        if (trueOrFalse) {
            this.coverage.functions[func].branches[branch].trueCount++;
            for (let r of Object.values(this.coverage.functions[func].branches[branch].group)) {
                if (r !== branch) {
                    this.coverage.functions[func].branches[r as number].falseCount++;
                }
            }
        }
        else {
            this.coverage.functions[func].branches[branch].falseCount++;
        }
    }
}
let bjccovms5u83px = new BjcCov({ version: "bjc v1.0.0", versionCode: 10000, path: "tencentqianwebview/src/main/ets/internal/IntentBridge.ets", hash: "5057ef82c5f5a829c644d516e068531f5e29d4f6b3fa77fc4e6e282357991c1e", lineCnt: 59, count: 0, projectPath: "", functions: { 0: { name: "IntentBridge.set", count: 0, regions: { 0: { startLoc: { line: 29, col: 3 }, endLoc: { line: 39, col: 4 }, count: 0, ignored: 0 }, 1: { startLoc: { line: 31, col: 28 }, endLoc: { line: 37, col: 6 }, count: 0, ignored: 0 }, 2: { startLoc: { line: 32, col: 11 }, endLoc: { line: 34, col: 8 }, count: 0, ignored: 0 }, 3: { startLoc: { line: 34, col: 9 }, endLoc: { line: 36, col: 8 }, count: 0, ignored: 0 }, 4: { startLoc: { line: 38, col: 5 }, endLoc: { line: 39, col: 4 }, count: 0, ignored: 0 } }, branches: { 0: { startLoc: { line: 31, col: 9 }, endLoc: { line: 31, col: 26 }, trueCount: 0, falseCount: 0, group: {}, ignored: 0 } }, ignored: 0, index: 0 }, 1: { name: "IntentBridge.peek", count: 0, regions: { 0: { startLoc: { line: 45, col: 3 }, endLoc: { line: 47, col: 4 }, count: 0, ignored: 0 }, 1: { startLoc: { line: 46, col: 5 }, endLoc: { line: 47, col: 4 }, count: 0, ignored: 0 } }, branches: {}, ignored: 0, index: 1 }, 2: { name: "IntentBridge.clear", count: 0, regions: { 0: { startLoc: { line: 52, col: 3 }, endLoc: { line: 54, col: 4 }, count: 0, ignored: 0 }, 1: { startLoc: { line: 53, col: 5 }, endLoc: { line: 54, col: 4 }, count: 0, ignored: 0 } }, branches: {}, ignored: 0, index: 2 }, 3: { name: "IntentBridge.constructor", count: 0, regions: { 0: { startLoc: { line: 57, col: 3 }, endLoc: { line: 57, col: 27 }, count: 0, ignored: 0 } }, branches: {}, ignored: 0, index: 3 } }, exeLine: { 0: 1, 1: 2, 2: 3, 3: 8, 4: 9, 5: 10, 6: 11, 7: 12, 8: 21, 9: 22, 10: 29, 11: 30, 12: 31, 13: 32, 14: 33, 15: 34, 16: 38, 17: 45, 18: 46, 19: 52, 20: 53, 21: 57 } });
/**
 * 携带的容器入参集合。
 */
export interface IntentBridgePayload {
    url: string;
    config: TencentQianWebViewConfig;
    onSignResult: OnSignResult;
    onSdkEvent?: OnSdkEvent;
}
/**
 * 全局单例，暂存 `TencentQianWebView.open()` 调用时的 callback / config / url。
 *
 * 容器页面 `aboutToAppear` 阶段从中拉取参数；二次 open 时旧 payload 会先收到
 * `SignResult.EMPTY` 再被覆盖，避免上一次回调丢失。
 */
export class IntentBridge {
    private static current: IntentBridgePayload | null = null;
    /**
     * 设置当前要进入容器页面的 payload。
     *
     * 如果已有未消费的 payload,先用 `SignResult.EMPTY` 通知旧 callback,再覆盖。
     */
    public static set(payload: IntentBridgePayload): void {
        bjccovms5u83px.instrumentFunction(0);
        const previous: IntentBridgePayload | null = IntentBridge.current;
        if (previous !== null) {
            bjccovms5u83px.instrumentBranch(0, 0, true);
            bjccovms5u83px.instrumentRegion(0, 1);
            try {
                bjccovms5u83px.instrumentRegion(0, 2);
                previous.onSignResult(SignResult.EMPTY);
            }
            catch (_e) {
                bjccovms5u83px.instrumentRegion(0, 3);
            }
        }
        else {
            bjccovms5u83px.instrumentBranch(0, 0, false);
        }
        bjccovms5u83px.instrumentRegion(0, 4);
        IntentBridge.current = payload;
    }
    /**
     * 取出 payload(消费式)。容器页面拿到后,本桥保留引用直到容器主动 clear,
     * 以便后续在同一个容器实例中多次取用。
     */
    public static peek(): IntentBridgePayload | null {
        bjccovms5u83px.instrumentFunction(1);
        bjccovms5u83px.instrumentRegion(1, 1);
        return IntentBridge.current;
    }
    /**
     * 清空当前 payload。容器页面 `onPageHide`/`onBackPress` 完成后调用,释放引用。
     */
    public static clear(): void {
        bjccovms5u83px.instrumentFunction(2);
        bjccovms5u83px.instrumentRegion(2, 1);
        IntentBridge.current = null;
    }
    // ArkTS 类禁止实例化
    private constructor() { bjccovms5u83px.instrumentFunction(3); }
}
