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 bjccovms5u83ts = new BjcCov({ version: "bjc v1.0.0", versionCode: 10000, path: "tencentqianwebview/src/main/ets/internal/prewarm/LangUtil.ets", hash: "22424c0de8bcdf7a9d52110cd6cd6235bcb36f6ffce9a6befdc4610c1551bc2a", lineCnt: 65, count: 0, projectPath: "", functions: { 0: { name: "convertDetectedLanguage", count: 0, regions: { 0: { startLoc: { line: 10, col: 1 }, endLoc: { line: 24, col: 2 }, count: 0, ignored: 0 }, 1: { startLoc: { line: 11, col: 25 }, endLoc: { line: 13, col: 4 }, count: 0, ignored: 0 }, 2: { startLoc: { line: 14, col: 38 }, endLoc: { line: 16, col: 4 }, count: 0, ignored: 0 }, 3: { startLoc: { line: 18, col: 3 }, endLoc: { line: 22, col: 4 }, count: 0, ignored: 0 }, 4: { startLoc: { line: 19, col: 45 }, endLoc: { line: 21, col: 6 }, count: 0, ignored: 0 }, 5: { startLoc: { line: 23, col: 3 }, endLoc: { line: 24, col: 2 }, count: 0, ignored: 0 } }, branches: { 0: { startLoc: { line: 11, col: 7 }, endLoc: { line: 11, col: 23 }, trueCount: 0, falseCount: 0, group: {}, ignored: 0 }, 1: { startLoc: { line: 14, col: 7 }, endLoc: { line: 14, col: 36 }, trueCount: 0, falseCount: 0, group: {}, ignored: 0 }, 2: { startLoc: { line: 19, col: 9 }, endLoc: { line: 19, col: 43 }, trueCount: 0, falseCount: 0, group: {}, ignored: 0 } }, ignored: 0, index: 0 }, 1: { name: "resolveLang", count: 0, regions: { 0: { startLoc: { line: 39, col: 1 }, endLoc: { line: 51, col: 2 }, count: 0, ignored: 0 }, 1: { startLoc: { line: 46, col: 24 }, endLoc: { line: 48, col: 4 }, count: 0, ignored: 0 }, 2: { startLoc: { line: 49, col: 3 }, endLoc: { line: 51, col: 2 }, count: 0, ignored: 0 } }, branches: { 0: { startLoc: { line: 46, col: 7 }, endLoc: { line: 46, col: 22 }, trueCount: 0, falseCount: 0, group: {}, ignored: 0 }, 1: { startLoc: { line: 49, col: 23 }, endLoc: { line: 49, col: 92 }, trueCount: 0, falseCount: 0, group: {}, ignored: 0 } }, ignored: 0, index: 1 }, 2: { name: "pickLocaleAssets", count: 0, regions: { 0: { startLoc: { line: 54, col: 1 }, endLoc: { line: 64, col: 2 }, count: 0, ignored: 0 }, 1: { startLoc: { line: 55, col: 50 }, endLoc: { line: 57, col: 4 }, count: 0, ignored: 0 }, 2: { startLoc: { line: 59, col: 48 }, endLoc: { line: 61, col: 4 }, count: 0, ignored: 0 }, 3: { startLoc: { line: 62, col: 3 }, endLoc: { line: 64, col: 2 }, count: 0, ignored: 0 } }, branches: { 0: { startLoc: { line: 55, col: 7 }, endLoc: { line: 55, col: 48 }, trueCount: 0, falseCount: 0, group: {}, ignored: 0 }, 1: { startLoc: { line: 59, col: 7 }, endLoc: { line: 59, col: 46 }, trueCount: 0, falseCount: 0, group: {}, ignored: 0 }, 2: { startLoc: { line: 63, col: 10 }, endLoc: { line: 63, col: 69 }, trueCount: 0, falseCount: 0, group: {}, ignored: 0 } }, ignored: 0, index: 2 } }, exeLine: { 0: 10, 1: 11, 2: 12, 3: 14, 4: 15, 5: 17, 6: 18, 7: 19, 8: 20, 9: 23, 10: 39, 11: 40, 12: 41, 13: 42, 14: 43, 15: 44, 16: 46, 17: 47, 18: 49, 19: 50, 20: 54, 21: 55, 22: 56, 23: 58, 24: 59, 25: 60, 26: 62, 27: 63 } });
/**
 * 语言解析纯函数（与 `warmup.html` 的语言判定语义对齐，无副作用，便于单测）。
 *
 * warmup.html 逻辑：`i18nAutoDetect ? convertDetectedLanguage(?lang > localStorage > navigator) : 'zh-CN'`，
 * 再取 `locales[lang]`（回退 zh-CN）。native 侧 L3 无 WebView，`localStorage` 够不着，
 * 故语言来源为 `preferredLanguage`（显式）→ 系统语言（best-effort，等价 navigator.language）→ `zh-CN`。
 */
/** 语言归一化：精确匹配 → 前缀匹配（en-GB→en-US / zh-TW→zh-CN）→ 回退 `zh-CN`。 */
export function convertDetectedLanguage(lng: string, supported: string[]): string {
    bjccovms5u83ts.instrumentFunction(0);
    if (lng.length === 0) {
        bjccovms5u83ts.instrumentBranch(0, 0, true);
        bjccovms5u83ts.instrumentRegion(0, 1);
        return 'zh-CN';
    }
    else {
        bjccovms5u83ts.instrumentBranch(0, 0, false);
    }
    if (supported.indexOf(lng) !== -1) {
        bjccovms5u83ts.instrumentBranch(0, 1, true);
        bjccovms5u83ts.instrumentRegion(0, 2);
        return lng;
    }
    else {
        bjccovms5u83ts.instrumentBranch(0, 1, false);
    }
    const prefix: string = lng.split('-')[0];
    for (let i = 0; i < supported.length; i++) {
        bjccovms5u83ts.instrumentRegion(0, 3);
        if (supported[i].indexOf(prefix) === 0) {
            bjccovms5u83ts.instrumentBranch(0, 2, true);
            bjccovms5u83ts.instrumentRegion(0, 4);
            return supported[i];
        }
        else {
            bjccovms5u83ts.instrumentBranch(0, 2, false);
        }
    }
    bjccovms5u83ts.instrumentRegion(0, 5);
    return 'zh-CN';
}
/**
 * 解析当前应预取的语言（与 warmup.html 逐行对齐）。
 *
 * warmup.html: `lang = i18nAutoDetect ? convertDetectedLanguage(langParam || localStorage || navigator) : 'zh-CN'`
 * ——即 `i18nAutoDetect=false` 时**无视任何语言偏好，恒 `zh-CN`**（真实页此时也恒渲染 zh-CN，
 * 预热其他语言纯属缓存 miss）。故 `preferredLanguage` 仅在 `i18nAutoDetect=true` 时生效，
 * 扮演 warmup.html 中 `langParam`（最高优先级）的角色；系统语言扮演 `localStorage || navigator`。
 *
 * @param preferred `config.preferredLanguage`，仅 `i18nAutoDetect=true` 时非空优先
 * @param i18nAutoDetect manifest 的 `i18nAutoDetect`
 * @param systemLang 系统语言（best-effort，由调用方注入以保持本函数纯净）
 * @param supported manifest 的 `supportedLngs`
 */
export function resolveLang(preferred: string | null, i18nAutoDetect: boolean, systemLang: string, supported: string[]): string {
    bjccovms5u83ts.instrumentFunction(1);
    // i18nAutoDetect=false → 恒 zh-CN（与 warmup.html / 真实页一致）
    if (!i18nAutoDetect) {
        bjccovms5u83ts.instrumentBranch(1, 0, true);
        bjccovms5u83ts.instrumentRegion(1, 1);
        return 'zh-CN';
    }
    else {
        bjccovms5u83ts.instrumentBranch(1, 0, false);
    }
    bjccovms5u83ts.instrumentRegion(1, 2);
    const raw: string = (preferred !== null && preferred.length > 0) ? (bjccovms5u83ts.instrumentBranch(1, 1, true), preferred) : (bjccovms5u83ts.instrumentBranch(1, 1, false), systemLang);
    return convertDetectedLanguage(raw, supported);
}
/** 取语言资源列表；`locales[lang]` 缺失时回退 `locales['zh-CN']`，再缺失返回空数组。 */
export function pickLocaleAssets(locales: Record<string, string[]> | undefined, lang: string): string[] {
    bjccovms5u83ts.instrumentFunction(2);
    if (locales === undefined || locales === null) {
        bjccovms5u83ts.instrumentBranch(2, 0, true);
        bjccovms5u83ts.instrumentRegion(2, 1);
        return [];
    }
    else {
        bjccovms5u83ts.instrumentBranch(2, 0, false);
    }
    const picked: string[] | undefined = locales[lang];
    if (picked !== undefined && picked !== null) {
        bjccovms5u83ts.instrumentBranch(2, 1, true);
        bjccovms5u83ts.instrumentRegion(2, 2);
        return picked;
    }
    else {
        bjccovms5u83ts.instrumentBranch(2, 1, false);
    }
    bjccovms5u83ts.instrumentRegion(2, 3);
    const fallback: string[] | undefined = locales['zh-CN'];
    return fallback !== undefined && fallback !== null ? (bjccovms5u83ts.instrumentBranch(2, 2, true), fallback) : (bjccovms5u83ts.instrumentBranch(2, 2, false), []);
}
