import webview from "@ohos:web.webview";
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 bjccovms5u83oh = new BjcCov({ version: "bjc v1.0.0", versionCode: 10000, path: "tencentqianwebview/src/main/ets/internal/CookieManagerHelper.ets", hash: "c99d14c39188a2a0a4e71a3dabebe775a6d2d9b6d040089a8b80031e7bedf46d", lineCnt: 56, count: 0, projectPath: "", functions: { 0: { name: "CookieManagerHelper.configure", count: 0, regions: { 0: { startLoc: { line: 12, col: 3 }, endLoc: { line: 22, col: 4 }, count: 0, ignored: 0 }, 1: { startLoc: { line: 13, col: 41 }, endLoc: { line: 15, col: 6 }, count: 0, ignored: 0 }, 2: { startLoc: { line: 16, col: 9 }, endLoc: { line: 18, col: 6 }, count: 0, ignored: 0 }, 3: { startLoc: { line: 18, col: 7 }, endLoc: { line: 20, col: 6 }, count: 0, ignored: 0 }, 4: { startLoc: { line: 21, col: 5 }, endLoc: { line: 22, col: 4 }, count: 0, ignored: 0 } }, branches: { 0: { startLoc: { line: 13, col: 9 }, endLoc: { line: 13, col: 39 }, trueCount: 0, falseCount: 0, group: {}, ignored: 0 } }, ignored: 0, index: 0 }, 1: { name: "CookieManagerHelper.fetchCookieFor", count: 0, regions: { 0: { startLoc: { line: 30, col: 3 }, endLoc: { line: 40, col: 4 }, count: 0, ignored: 0 }, 1: { startLoc: { line: 31, col: 64 }, endLoc: { line: 33, col: 6 }, count: 0, ignored: 0 }, 2: { startLoc: { line: 34, col: 9 }, endLoc: { line: 37, col: 6 }, count: 0, ignored: 0 }, 3: { startLoc: { line: 37, col: 7 }, endLoc: { line: 39, col: 6 }, count: 0, ignored: 0 } }, branches: { 0: { startLoc: { line: 31, col: 9 }, endLoc: { line: 31, col: 62 }, trueCount: 0, falseCount: 0, group: {}, ignored: 0 }, 1: { startLoc: { line: 36, col: 14 }, endLoc: { line: 36, col: 67 }, trueCount: 0, falseCount: 0, group: {}, ignored: 0 } }, ignored: 0, index: 1 }, 2: { name: "CookieManagerHelper.save", count: 0, regions: { 0: { startLoc: { line: 45, col: 3 }, endLoc: { line: 51, col: 4 }, count: 0, ignored: 0 }, 1: { startLoc: { line: 46, col: 9 }, endLoc: { line: 48, col: 6 }, count: 0, ignored: 0 }, 2: { startLoc: { line: 48, col: 7 }, endLoc: { line: 50, col: 6 }, count: 0, ignored: 0 } }, branches: {}, ignored: 0, index: 2 }, 3: { name: "CookieManagerHelper.constructor", count: 0, regions: { 0: { startLoc: { line: 54, col: 3 }, endLoc: { line: 54, col: 27 }, count: 0, ignored: 0 } }, branches: {}, ignored: 0, index: 3 } }, exeLine: { 0: 1, 1: 8, 2: 9, 3: 12, 4: 13, 5: 14, 6: 16, 7: 17, 8: 18, 9: 21, 10: 30, 11: 31, 12: 32, 13: 34, 14: 35, 15: 36, 16: 37, 17: 38, 18: 45, 19: 46, 20: 47, 21: 48, 22: 54 } });
/**
 * Cookie 管理辅助类。
 *
 * 在 SDK 加载第一个 Web 组件之前调用 `configure()` 一次以确保 Cookie 持久化能力开启。
 */
export class CookieManagerHelper {
    private static configured: boolean = false;
    /** 全局配置 Cookie 策略，多次调用幂等。 */
    public static configure(): void {
        bjccovms5u83oh.instrumentFunction(0);
        if (CookieManagerHelper.configured) {
            bjccovms5u83oh.instrumentBranch(0, 0, true);
            bjccovms5u83oh.instrumentRegion(0, 1);
            return;
        }
        else {
            bjccovms5u83oh.instrumentBranch(0, 0, false);
        }
        try {
            bjccovms5u83oh.instrumentRegion(0, 2);
            webview.WebCookieManager.putAcceptCookieEnabled(true);
        }
        catch (_e) {
            bjccovms5u83oh.instrumentRegion(0, 3);
        }
        bjccovms5u83oh.instrumentRegion(0, 4);
        CookieManagerHelper.configured = true;
    }
    /**
     * 拉取目标 URL 的 Cookie 字符串(用于下载请求头注入等场景)。
     *
     * @param url 目标 URL
     * @returns Cookie 字符串(`a=b; c=d` 形式),无 Cookie 返回空串
     */
    public static fetchCookieFor(url: string): string {
        bjccovms5u83oh.instrumentFunction(1);
        if (url === null || url === undefined || url.length === 0) {
            bjccovms5u83oh.instrumentBranch(1, 0, true);
            bjccovms5u83oh.instrumentRegion(1, 1);
            return '';
        }
        else {
            bjccovms5u83oh.instrumentBranch(1, 0, false);
        }
        try {
            bjccovms5u83oh.instrumentRegion(1, 2);
            const cookie: string = webview.WebCookieManager.fetchCookieSync(url);
            return cookie === null || cookie === undefined ? (bjccovms5u83oh.instrumentBranch(1, 1, true), '') : (bjccovms5u83oh.instrumentBranch(1, 1, false), cookie);
        }
        catch (_e) {
            bjccovms5u83oh.instrumentRegion(1, 3);
            return '';
        }
    }
    /**
     * 持久化所有内存中的 Cookie 到磁盘。建议在容器关闭前调用。
     */
    public static save(): void {
        bjccovms5u83oh.instrumentFunction(2);
        try {
            bjccovms5u83oh.instrumentRegion(2, 1);
            webview.WebCookieManager.saveCookieAsync();
        }
        catch (_e) {
            bjccovms5u83oh.instrumentRegion(2, 2);
        }
    }
    // ArkTS 类禁止实例化
    private constructor() { bjccovms5u83oh.instrumentFunction(3); }
}
