import promptAction from "@ohos:promptAction";
import window from "@ohos:window";
import type common from "@ohos:app.ability.common";
import { ComponentContent } from "@ohos:arkui.node";
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 bjccovms5u83q2 = new BjcCov({ version: "bjc v1.0.0", versionCode: 10000, path: "tencentqianwebview/src/main/ets/internal/JsDialogHandler.ets", hash: "5f8f7e11853808104f49f39dca9ca39b1e9de607efb83ada917e1267f6f95218", lineCnt: 246, count: 0, projectPath: "", functions: { 0: { name: "anonymous_0", count: 0, regions: { 0: { startLoc: { line: 16, col: 21 }, endLoc: { line: 16, col: 44 }, count: 0, ignored: 0 } }, branches: {}, ignored: 0, index: 0 }, 1: { name: "anonymous_1", count: 0, regions: { 0: { startLoc: { line: 16, col: 47 }, endLoc: { line: 16, col: 71 }, count: 0, ignored: 0 } }, branches: {}, ignored: 0, index: 1 }, 2: { name: "anonymous_2", count: 0, regions: { 0: { startLoc: { line: 17, col: 20 }, endLoc: { line: 17, col: 30 }, count: 0, ignored: 0 } }, branches: {}, ignored: 0, index: 2 }, 3: { name: "anonymous_3", count: 0, regions: { 0: { startLoc: { line: 17, col: 33 }, endLoc: { line: 17, col: 47 }, count: 0, ignored: 0 } }, branches: {}, ignored: 0, index: 3 }, 4: { name: "PromptDialogParams.constructor", count: 0, regions: { 0: { startLoc: { line: 19, col: 3 }, endLoc: { line: 30, col: 4 }, count: 0, ignored: 0 }, 1: { startLoc: { line: 25, col: 5 }, endLoc: { line: 30, col: 4 }, count: 0, ignored: 0 } }, branches: {}, ignored: 0, index: 4 }, 5: { name: "anonymous_4", count: 0, regions: { 0: { startLoc: { line: 22, col: 16 }, endLoc: { line: 22, col: 39 }, count: 0, ignored: 0 } }, branches: {}, ignored: 0, index: 5 }, 6: { name: "anonymous_5", count: 0, regions: { 0: { startLoc: { line: 23, col: 15 }, endLoc: { line: 23, col: 25 }, count: 0, ignored: 0 } }, branches: {}, ignored: 0, index: 6 }, 7: { name: "buildPromptDialog", count: 0, regions: { 0: { startLoc: { line: 33, col: 1 }, endLoc: { line: 100, col: 2 }, count: 0, ignored: 0 } }, branches: {}, ignored: 0, index: 7 }, 8: { name: "anonymous_6", count: 0, regions: { 0: { startLoc: { line: 34, col: 28 }, endLoc: { line: 99, col: 15 }, count: 0, ignored: 0 } }, branches: {}, ignored: 0, index: 8 }, 9: { name: "anonymous_7", count: 0, regions: { 0: { startLoc: { line: 34, col: 28 }, endLoc: { line: 42, col: 29 }, count: 0, ignored: 0 } }, branches: {}, ignored: 0, index: 9 }, 10: { name: "anonymous_8", count: 0, regions: { 0: { startLoc: { line: 34, col: 28 }, endLoc: { line: 49, col: 29 }, count: 0, ignored: 0 } }, branches: {}, ignored: 0, index: 10 }, 11: { name: "anonymous_9", count: 0, regions: { 0: { startLoc: { line: 34, col: 28 }, endLoc: { line: 64, col: 8 }, count: 0, ignored: 0 } }, branches: {}, ignored: 0, index: 11 }, 12: { name: "anonymous_10", count: 0, regions: { 0: { startLoc: { line: 62, col: 17 }, endLoc: { line: 64, col: 8 }, count: 0, ignored: 0 }, 1: { startLoc: { line: 63, col: 9 }, endLoc: { line: 64, col: 8 }, count: 0, ignored: 0 } }, branches: {}, ignored: 0, index: 12 }, 13: { name: "anonymous_11", count: 0, regions: { 0: { startLoc: { line: 34, col: 28 }, endLoc: { line: 94, col: 37 }, count: 0, ignored: 0 } }, branches: {}, ignored: 0, index: 13 }, 14: { name: "anonymous_12", count: 0, regions: { 0: { startLoc: { line: 34, col: 28 }, endLoc: { line: 75, col: 10 }, count: 0, ignored: 0 } }, branches: {}, ignored: 0, index: 14 }, 15: { name: "anonymous_13", count: 0, regions: { 0: { startLoc: { line: 73, col: 18 }, endLoc: { line: 75, col: 10 }, count: 0, ignored: 0 }, 1: { startLoc: { line: 74, col: 11 }, endLoc: { line: 75, col: 10 }, count: 0, ignored: 0 } }, branches: {}, ignored: 0, index: 15 }, 16: { name: "anonymous_14", count: 0, regions: { 0: { startLoc: { line: 34, col: 28 }, endLoc: { line: 80, col: 25 }, count: 0, ignored: 0 } }, branches: {}, ignored: 0, index: 16 }, 17: { name: "anonymous_15", count: 0, regions: { 0: { startLoc: { line: 34, col: 28 }, endLoc: { line: 91, col: 10 }, count: 0, ignored: 0 } }, branches: {}, ignored: 0, index: 17 }, 18: { name: "anonymous_16", count: 0, regions: { 0: { startLoc: { line: 89, col: 18 }, endLoc: { line: 91, col: 10 }, count: 0, ignored: 0 }, 1: { startLoc: { line: 90, col: 11 }, endLoc: { line: 91, col: 10 }, count: 0, ignored: 0 } }, branches: {}, ignored: 0, index: 18 }, 19: { name: "JsDialogHandler.showAlert", count: 0, regions: { 0: { startLoc: { line: 107, col: 3 }, endLoc: { line: 128, col: 4 }, count: 0, ignored: 0 }, 1: { startLoc: { line: 109, col: 9 }, endLoc: { line: 125, col: 6 }, count: 0, ignored: 0 }, 2: { startLoc: { line: 125, col: 7 }, endLoc: { line: 127, col: 6 }, count: 0, ignored: 0 }, 3: { startLoc: { line: 111, col: 24 }, endLoc: { line: 117, col: 8 }, count: 0, ignored: 0 }, 4: { startLoc: { line: 117, col: 14 }, endLoc: { line: 123, col: 8 }, count: 0, ignored: 0 }, 5: { startLoc: { line: 124, col: 7 }, endLoc: { line: 125, col: 6 }, count: 0, ignored: 0 } }, branches: { 0: { startLoc: { line: 111, col: 11 }, endLoc: { line: 111, col: 22 }, trueCount: 0, falseCount: 0, group: {}, ignored: 0 } }, ignored: 0, index: 19 }, 20: { name: "JsDialogHandler.showConfirm", count: 0, regions: { 0: { startLoc: { line: 131, col: 3 }, endLoc: { line: 159, col: 4 }, count: 0, ignored: 0 }, 1: { startLoc: { line: 133, col: 9 }, endLoc: { line: 156, col: 6 }, count: 0, ignored: 0 }, 2: { startLoc: { line: 156, col: 7 }, endLoc: { line: 158, col: 6 }, count: 0, ignored: 0 }, 3: { startLoc: { line: 136, col: 24 }, endLoc: { line: 145, col: 8 }, count: 0, ignored: 0 }, 4: { startLoc: { line: 145, col: 14 }, endLoc: { line: 154, col: 8 }, count: 0, ignored: 0 }, 5: { startLoc: { line: 155, col: 7 }, endLoc: { line: 156, col: 6 }, count: 0, ignored: 0 } }, branches: { 0: { startLoc: { line: 136, col: 11 }, endLoc: { line: 136, col: 22 }, trueCount: 0, falseCount: 0, group: {}, ignored: 0 } }, ignored: 0, index: 20 }, 21: { name: "JsDialogHandler.showPrompt", count: 0, regions: { 0: { startLoc: { line: 162, col: 3 }, endLoc: { line: 213, col: 4 }, count: 0, ignored: 0 }, 1: { startLoc: { line: 172, col: 25 }, endLoc: { line: 174, col: 6 }, count: 0, ignored: 0 }, 2: { startLoc: { line: 176, col: 5 }, endLoc: { line: 213, col: 4 }, count: 0, ignored: 0 }, 3: { startLoc: { line: 188, col: 9 }, endLoc: { line: 189, col: 8 }, count: 0, ignored: 0 }, 4: { startLoc: { line: 204, col: 9 }, endLoc: { line: 209, col: 8 }, count: 0, ignored: 0 } }, branches: { 0: { startLoc: { line: 172, col: 9 }, endLoc: { line: 172, col: 23 }, trueCount: 0, falseCount: 0, group: {}, ignored: 0 } }, ignored: 0, index: 21 }, 22: { name: "anonymous_17", count: 0, regions: { 0: { startLoc: { line: 176, col: 39 }, endLoc: { line: 212, col: 6 }, count: 0, ignored: 0 }, 1: { startLoc: { line: 198, col: 11 }, endLoc: { line: 209, col: 8 }, count: 0, ignored: 0 }, 2: { startLoc: { line: 209, col: 9 }, endLoc: { line: 211, col: 8 }, count: 0, ignored: 0 } }, branches: {}, ignored: 0, index: 22 }, 23: { name: "anonymous_18", count: 0, regions: { 0: { startLoc: { line: 176, col: 49 }, endLoc: { line: 176, col: 75 }, count: 0, ignored: 0 } }, branches: {}, ignored: 0, index: 23 }, 24: { name: "anonymous_19", count: 0, regions: { 0: { startLoc: { line: 180, col: 31 }, endLoc: { line: 189, col: 8 }, count: 0, ignored: 0 }, 1: { startLoc: { line: 181, col: 13 }, endLoc: { line: 185, col: 10 }, count: 0, ignored: 0 }, 2: { startLoc: { line: 185, col: 11 }, endLoc: { line: 187, col: 10 }, count: 0, ignored: 0 }, 3: { startLoc: { line: 182, col: 37 }, endLoc: { line: 184, col: 12 }, count: 0, ignored: 0 } }, branches: { 0: { startLoc: { line: 182, col: 15 }, endLoc: { line: 182, col: 35 }, trueCount: 0, falseCount: 0, group: {}, ignored: 0 } }, ignored: 0, index: 24 }, 25: { name: "anonymous_20", count: 0, regions: { 0: { startLoc: { line: 194, col: 9 }, endLoc: { line: 194, col: 61 }, count: 0, ignored: 0 }, 1: { startLoc: { line: 194, col: 36 }, endLoc: { line: 194, col: 61 }, count: 0, ignored: 0 } }, branches: {}, ignored: 0, index: 25 }, 26: { name: "anonymous_21", count: 0, regions: { 0: { startLoc: { line: 195, col: 9 }, endLoc: { line: 195, col: 47 }, count: 0, ignored: 0 }, 1: { startLoc: { line: 195, col: 23 }, endLoc: { line: 195, col: 47 }, count: 0, ignored: 0 } }, branches: {}, ignored: 0, index: 26 }, 27: { name: "anonymous_22", count: 0, regions: { 0: { startLoc: { line: 208, col: 18 }, endLoc: { line: 208, col: 58 }, count: 0, ignored: 0 }, 1: { startLoc: { line: 208, col: 42 }, endLoc: { line: 208, col: 58 }, count: 0, ignored: 0 } }, branches: {}, ignored: 0, index: 27 }, 28: { name: "JsDialogHandler.showPromptFallback", count: 0, regions: { 0: { startLoc: { line: 216, col: 3 }, endLoc: { line: 232, col: 4 }, count: 0, ignored: 0 }, 1: { startLoc: { line: 219, col: 9 }, endLoc: { line: 229, col: 6 }, count: 0, ignored: 0 }, 2: { startLoc: { line: 229, col: 7 }, endLoc: { line: 231, col: 6 }, count: 0, ignored: 0 } }, branches: { 0: { startLoc: { line: 218, col: 10 }, endLoc: { line: 218, col: 69 }, trueCount: 0, falseCount: 0, group: {}, ignored: 0 }, 1: { startLoc: { line: 228, col: 14 }, endLoc: { line: 228, col: 54 }, trueCount: 0, falseCount: 0, group: {}, ignored: 0 } }, ignored: 0, index: 28 }, 29: { name: "JsDialogHandler.getUIContext", count: 0, regions: { 0: { startLoc: { line: 235, col: 3 }, endLoc: { line: 242, col: 4 }, count: 0, ignored: 0 }, 1: { startLoc: { line: 236, col: 9 }, endLoc: { line: 239, col: 6 }, count: 0, ignored: 0 }, 2: { startLoc: { line: 239, col: 7 }, endLoc: { line: 241, col: 6 }, count: 0, ignored: 0 } }, branches: {}, ignored: 0, index: 29 }, 30: { name: "JsDialogHandler.constructor", count: 0, regions: { 0: { startLoc: { line: 244, col: 3 }, endLoc: { line: 244, col: 27 }, count: 0, ignored: 0 } }, branches: {}, ignored: 0, index: 30 } }, exeLine: { 0: 1, 1: 2, 2: 3, 3: 4, 4: 7, 5: 8, 6: 12, 7: 13, 8: 14, 9: 15, 10: 16, 11: 17, 12: 20, 13: 21, 14: 22, 15: 23, 16: 24, 17: 25, 18: 26, 19: 27, 20: 28, 21: 29, 22: 34, 23: 35, 24: 36, 25: 37, 26: 38, 27: 39, 28: 40, 29: 41, 30: 42, 31: 44, 32: 45, 33: 46, 34: 47, 35: 48, 36: 49, 37: 51, 38: 52, 39: 53, 40: 54, 41: 55, 42: 56, 43: 57, 44: 58, 45: 59, 46: 60, 47: 61, 48: 62, 49: 63, 50: 66, 51: 67, 52: 68, 53: 69, 54: 70, 55: 71, 56: 72, 57: 73, 58: 74, 59: 77, 60: 78, 61: 79, 62: 80, 63: 82, 64: 83, 65: 84, 66: 85, 67: 86, 68: 87, 69: 88, 70: 89, 71: 90, 72: 93, 73: 94, 74: 96, 75: 97, 76: 98, 77: 99, 78: 105, 79: 107, 80: 108, 81: 109, 82: 110, 83: 111, 84: 112, 85: 113, 86: 114, 87: 115, 88: 117, 89: 118, 90: 119, 91: 120, 92: 121, 93: 124, 94: 125, 95: 126, 96: 131, 97: 132, 98: 133, 99: 134, 100: 135, 101: 136, 102: 137, 103: 138, 104: 139, 105: 140, 106: 141, 107: 142, 108: 144, 109: 145, 110: 146, 111: 147, 112: 148, 113: 149, 114: 150, 115: 151, 116: 153, 117: 155, 118: 156, 119: 157, 120: 162, 121: 163, 122: 164, 123: 165, 124: 166, 125: 167, 126: 168, 127: 169, 128: 171, 129: 172, 130: 173, 131: 176, 132: 177, 133: 178, 134: 180, 135: 181, 136: 182, 137: 183, 138: 185, 139: 188, 140: 191, 141: 192, 142: 193, 143: 194, 144: 195, 145: 198, 146: 199, 147: 200, 148: 201, 149: 202, 150: 204, 151: 205, 152: 206, 153: 207, 154: 208, 155: 209, 156: 210, 157: 216, 158: 217, 159: 218, 160: 219, 161: 220, 162: 221, 163: 222, 164: 223, 165: 224, 166: 225, 167: 227, 168: 228, 169: 229, 170: 230, 171: 235, 172: 236, 173: 237, 174: 238, 175: 239, 176: 240, 177: 244 } });
/** 弹窗交互结果。 */
interface DialogResult {
    index: number;
}
/** `prompt` 弹窗参数。 */
class PromptDialogParams {
    public message: string = '';
    public defaultValue: string = '';
    public inputValue: string = '';
    public onConfirm: (value: string) => void = (_v: string): void => { bjccovms5u83q2.instrumentFunction(1); };
    public onCancel: () => void = (): void => { bjccovms5u83q2.instrumentFunction(3); };
    constructor(message: string, defaultValue: string, onConfirm: (value: string) => void, onCancel: () => void) {
        bjccovms5u83q2.instrumentFunction(4);
        bjccovms5u83q2.instrumentRegion(4, 1);
        this.message = message;
        this.defaultValue = defaultValue;
        this.inputValue = defaultValue;
        this.onConfirm = onConfirm;
        this.onCancel = onCancel;
    }
}
function buildPromptDialog(params: PromptDialogParams, parent = null): void {
    bjccovms5u83q2.instrumentFunction(7);
    const __params__ = params;
    (parent ? parent : this).observeComponentCreation2((elmtId, isInitialRender, params = __params__) => {
        bjccovms5u83q2.instrumentFunction(8);
        Column.create();
        Column.padding({ top: 20, left: 20, right: 20, bottom: 4 });
        Column.backgroundColor('#FFFFFF');
        Column.borderRadius(14);
        Column.width('80%');
    }, Column);
    (parent ? parent : this).observeComponentCreation2((elmtId, isInitialRender, params = __params__) => {
        bjccovms5u83q2.instrumentFunction(9);
        Text.create('提示');
        Text.fontSize(18);
        Text.fontWeight(FontWeight.Bold);
        Text.fontColor('#000000');
        Text.width('100%');
        Text.textAlign(TextAlign.Start);
        Text.margin({ bottom: 12 });
    }, Text);
    Text.pop();
    (parent ? parent : this).observeComponentCreation2((elmtId, isInitialRender, params = __params__) => {
        bjccovms5u83q2.instrumentFunction(10);
        Text.create(params.message);
        Text.fontSize(14);
        Text.fontColor('#333333');
        Text.width('100%');
        Text.textAlign(TextAlign.Start);
        Text.margin({ bottom: 12 });
    }, Text);
    Text.pop();
    (parent ? parent : this).observeComponentCreation2((elmtId, isInitialRender, params = __params__) => {
        bjccovms5u83q2.instrumentFunction(11);
        TextInput.create({ text: params.defaultValue, placeholder: '请输入' });
        TextInput.width('100%');
        TextInput.height(40);
        TextInput.fontSize(14);
        TextInput.fontColor('#222222');
        TextInput.placeholderColor('#999999');
        TextInput.caretColor('#1989FA');
        TextInput.backgroundColor('#F5F5F5');
        TextInput.borderRadius(6);
        TextInput.padding({ left: 12, right: 12 });
        TextInput.margin({ bottom: 16 });
        TextInput.onChange((value: string): void => {
            bjccovms5u83q2.instrumentFunction(12);
            bjccovms5u83q2.instrumentRegion(12, 1);
            params.inputValue = value;
        });
    }, TextInput);
    (parent ? parent : this).observeComponentCreation2((elmtId, isInitialRender, params = __params__) => {
        bjccovms5u83q2.instrumentFunction(13);
        Row.create();
        Row.width('100%');
        Row.alignItems(VerticalAlign.Center);
    }, Row);
    (parent ? parent : this).observeComponentCreation2((elmtId, isInitialRender, params = __params__) => {
        bjccovms5u83q2.instrumentFunction(14);
        Button.createWithLabel('取消');
        Button.type(ButtonType.Normal);
        Button.backgroundColor(Color.Transparent);
        Button.fontColor('#999999');
        Button.layoutWeight(1);
        Button.height(44);
        Button.onClick((): void => {
            bjccovms5u83q2.instrumentFunction(15);
            bjccovms5u83q2.instrumentRegion(15, 1);
            params.onCancel();
        });
    }, Button);
    Button.pop();
    (parent ? parent : this).observeComponentCreation2((elmtId, isInitialRender, params = __params__) => {
        bjccovms5u83q2.instrumentFunction(16);
        Divider.create();
        Divider.vertical(true);
        Divider.height(20);
        Divider.color('#E5E5E5');
    }, Divider);
    (parent ? parent : this).observeComponentCreation2((elmtId, isInitialRender, params = __params__) => {
        bjccovms5u83q2.instrumentFunction(17);
        Button.createWithLabel('确定');
        Button.type(ButtonType.Normal);
        Button.backgroundColor(Color.Transparent);
        Button.fontColor('#000000');
        Button.fontWeight(FontWeight.Medium);
        Button.layoutWeight(1);
        Button.height(44);
        Button.onClick((): void => {
            bjccovms5u83q2.instrumentFunction(18);
            bjccovms5u83q2.instrumentRegion(18, 1);
            params.onConfirm(params.inputValue);
        });
    }, Button);
    Button.pop();
    Row.pop();
    Column.pop();
}
/**
 * 处理 WebView 中 JS `alert` / `confirm` / `prompt` 弹窗。
 */
export class JsDialogHandler {
    /** 弹出 alert 对话框。 */
    public static async showAlert(context: common.UIAbilityContext, url: string, message: string): Promise<boolean> {
        bjccovms5u83q2.instrumentFunction(19);
        const safeMsg: string = message ?? '';
        try {
            bjccovms5u83q2.instrumentRegion(19, 1);
            const uc: UIContext | null = await JsDialogHandler.getUIContext(context);
            if (uc !== null) {
                bjccovms5u83q2.instrumentBranch(19, 0, true);
                bjccovms5u83q2.instrumentRegion(19, 3);
                await uc.getPromptAction().showDialog({
                    title: '提示',
                    message: safeMsg,
                    buttons: [{ text: '确定', color: '#1989FA' }]
                });
            }
            else {
                bjccovms5u83q2.instrumentBranch(19, 0, false);
                bjccovms5u83q2.instrumentRegion(19, 4);
                await promptAction.showDialog({
                    title: '提示',
                    message: safeMsg,
                    buttons: [{ text: '确定', color: '#1989FA' }]
                });
            }
            bjccovms5u83q2.instrumentRegion(19, 5);
            return true;
        }
        catch (_e) {
            bjccovms5u83q2.instrumentRegion(19, 2);
            return false;
        }
    }
    /** 弹出 confirm 对话框。 */
    public static async showConfirm(context: common.UIAbilityContext, url: string, message: string): Promise<boolean> {
        bjccovms5u83q2.instrumentFunction(20);
        const safeMsg: string = message ?? '';
        try {
            bjccovms5u83q2.instrumentRegion(20, 1);
            const uc: UIContext | null = await JsDialogHandler.getUIContext(context);
            let result: DialogResult;
            if (uc !== null) {
                bjccovms5u83q2.instrumentBranch(20, 0, true);
                bjccovms5u83q2.instrumentRegion(20, 3);
                result = await uc.getPromptAction().showDialog({
                    title: '提示',
                    message: safeMsg,
                    buttons: [
                        { text: '取消', color: '#999999' },
                        { text: '确定', color: '#1989FA' }
                    ]
                }) as DialogResult;
            }
            else {
                bjccovms5u83q2.instrumentBranch(20, 0, false);
                bjccovms5u83q2.instrumentRegion(20, 4);
                result = await promptAction.showDialog({
                    title: '提示',
                    message: safeMsg,
                    buttons: [
                        { text: '取消', color: '#999999' },
                        { text: '确定', color: '#1989FA' }
                    ]
                }) as DialogResult;
            }
            bjccovms5u83q2.instrumentRegion(20, 5);
            return result.index === 1;
        }
        catch (_e) {
            bjccovms5u83q2.instrumentRegion(20, 2);
            return false;
        }
    }
    /** 弹出 prompt 对话框（含文本输入）。 */
    public static async showPrompt(context: common.UIAbilityContext, url: string, message: string, defaultValue: string): Promise<string | null> {
        bjccovms5u83q2.instrumentFunction(21);
        const safeMsg: string = message ?? '';
        const safeDefault: string = defaultValue ?? '';
        let uiCtx: UIContext | null = await JsDialogHandler.getUIContext(context);
        if (uiCtx === null) {
            bjccovms5u83q2.instrumentBranch(21, 0, true);
            bjccovms5u83q2.instrumentRegion(21, 1);
            return JsDialogHandler.showPromptFallback(safeMsg, safeDefault);
        }
        else {
            bjccovms5u83q2.instrumentBranch(21, 0, false);
        }
        bjccovms5u83q2.instrumentRegion(21, 2);
        return new Promise<string | null>((resolve: (v: string | null) => void): void => {
            bjccovms5u83q2.instrumentFunction(22);
            const finalUiCtx: UIContext = uiCtx as UIContext;
            let contentNode: ComponentContent<PromptDialogParams> | null = null;
            const closeAndResolve = (value: string | null): void => {
                bjccovms5u83q2.instrumentFunction(24);
                try {
                    bjccovms5u83q2.instrumentRegion(24, 1);
                    if (contentNode !== null) {
                        bjccovms5u83q2.instrumentBranch(24, 0, true);
                        bjccovms5u83q2.instrumentRegion(24, 3);
                        finalUiCtx.getPromptAction().closeCustomDialog(contentNode);
                    }
                    else {
                        bjccovms5u83q2.instrumentBranch(24, 0, false);
                    }
                }
                catch (_e) {
                    bjccovms5u83q2.instrumentRegion(24, 2);
                }
                bjccovms5u83q2.instrumentRegion(21, 3);
                resolve(value);
            };
            const params: PromptDialogParams = new PromptDialogParams(safeMsg, safeDefault, (value: string): void => { bjccovms5u83q2.instrumentFunction(25); bjccovms5u83q2.instrumentRegion(25, 1); closeAndResolve(value); }, (): void => { bjccovms5u83q2.instrumentFunction(26); bjccovms5u83q2.instrumentRegion(26, 1); closeAndResolve(null); });
            try {
                bjccovms5u83q2.instrumentRegion(22, 1);
                contentNode = new ComponentContent<PromptDialogParams>(finalUiCtx, wrapBuilder<[
                    PromptDialogParams
                ]>(buildPromptDialog), params);
                bjccovms5u83q2.instrumentRegion(21, 4);
                finalUiCtx.getPromptAction().openCustomDialog(contentNode, {
                    alignment: DialogAlignment.Center,
                    autoCancel: false,
                    maskColor: '#80000000'
                }).catch((_e: Object): void => { bjccovms5u83q2.instrumentFunction(27); bjccovms5u83q2.instrumentRegion(27, 1); resolve(null); });
            }
            catch (_e) {
                bjccovms5u83q2.instrumentRegion(22, 2);
                resolve(null);
            }
        });
    }
    /** prompt 对话框的简化实现（不含自定义输入控件）。 */
    private static async showPromptFallback(message: string, defaultValue: string): Promise<string | null> {
        bjccovms5u83q2.instrumentFunction(28);
        const composedMessage: string = message
            + (defaultValue.length > 0 ? (bjccovms5u83q2.instrumentBranch(28, 0, true), ('\n\n默认值: ' + defaultValue)) : (bjccovms5u83q2.instrumentBranch(28, 0, false), ''));
        try {
            bjccovms5u83q2.instrumentRegion(28, 1);
            const result = await promptAction.showDialog({
                title: '提示',
                message: composedMessage,
                buttons: [
                    { text: '取消', color: '#999999' },
                    { text: '确定', color: '#1989FA' }
                ]
            }) as DialogResult;
            return result.index === 1 ? (bjccovms5u83q2.instrumentBranch(28, 1, true), defaultValue) : (bjccovms5u83q2.instrumentBranch(28, 1, false), null);
        }
        catch (_e) {
            bjccovms5u83q2.instrumentRegion(28, 2);
            return null;
        }
    }
    /** 获取当前窗口的 UIContext。 */
    private static async getUIContext(context: common.UIAbilityContext): Promise<UIContext | null> {
        bjccovms5u83q2.instrumentFunction(29);
        try {
            bjccovms5u83q2.instrumentRegion(29, 1);
            const win: window.Window = await window.getLastWindow(context);
            return win.getUIContext();
        }
        catch (_e) {
            bjccovms5u83q2.instrumentRegion(29, 2);
            return null;
        }
    }
    private constructor() { bjccovms5u83q2.instrumentFunction(30); }
}
