if (!("finalizeConstruction" in ViewPU.prototype)) {
    Reflect.set(ViewPU.prototype, "finalizeConstruction", () => { });
}
import sysWebview from '@ohos:web.webview';
import router from '@ohos:router';
import UPUtil from '@package:pkg_modules/.ohpm/uppayment@gx7nzjcazfb3kvk6jc+phqy7h84=/pkg_modules/uppayment/src/main/ets/utils/UPUtil';
import { UPWebViewJsBridge, UPWebViewJavascriptBridgeMethodList, UPWebViewJavascriptBridge } from '@package:pkg_modules/.ohpm/uppayment@gx7nzjcazfb3kvk6jc+phqy7h84=/pkg_modules/uppayment/src/main/ets/utils/UPWebViewJsBridge';
import UPLogger from '@package:pkg_modules/.ohpm/uppayment@gx7nzjcazfb3kvk6jc+phqy7h84=/pkg_modules/uppayment/src/main/ets/utils/UPLogger';
import UPConstant from '@package:pkg_modules/.ohpm/uppayment@gx7nzjcazfb3kvk6jc+phqy7h84=/pkg_modules/uppayment/src/main/ets/common/UPConstant';
import window from '@ohos:window';
const EnterName = 'UPWebPage';
export default EnterName;
class UPWebPage extends ViewPU {
    constructor(b5, c5, d5, e5 = -1, f5 = undefined, g5) {
        super(b5, d5, e5, g5);
        if (typeof f5 === "function") {
            this.paramsGenerator_ = f5;
        }
        this.__webSrc = new ObservedPropertySimplePU(router.getParams()['webSrc'] || '', this, "webSrc");
        this.__subPage = new ObservedPropertySimplePU(router.getParams()['subPage'] || false, this, "subPage");
        this.__backBtnVisibility = new ObservedPropertySimplePU(Visibility.Visible, this, "backBtnVisibility");
        this.__topSafeHeight = new ObservedPropertySimplePU(0, this, "topSafeHeight");
        this.tn = router.getParams()['tn'] || undefined;
        this.controller = new sysWebview.WebviewController();
        this.jsBridge = new UPWebViewJsBridge(this.controller);
        this.javaScriptAccess = true;
        this.fileAccess = false;
        this.navCloseBtnBase64 = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGAAAABgCAYAAADimHc4AAAAAXNSR0IArs4c6QAAA8JJREFUeF7tnD9uE0EUh980lmxRUEAJCLhADkABbSrgEDaWXKSg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d7Jw7rarqZQT/+KJ9Vrw7roJ6dAY09m9C+frVavXWe38oIiOq8vUx6WfPJq4bakC7E0iyBHUPa0+0BEwAeC6YABMAJgAObxlgAsAEwOEtA0wAmAA4vGWACQATAIe3DDABYALg8JYBJgBMABz+L3oFF51bXkJGAAAAAElFTkSuQmCC";
        this.windowClass = undefined;
        this.setInitiallyProvidedValue(c5);
        this.finalizeConstruction();
    }
    setInitiallyProvidedValue(a5) {
        if (a5.webSrc !== undefined) {
            this.webSrc = a5.webSrc;
        }
        if (a5.subPage !== undefined) {
            this.subPage = a5.subPage;
        }
        if (a5.backBtnVisibility !== undefined) {
            this.backBtnVisibility = a5.backBtnVisibility;
        }
        if (a5.topSafeHeight !== undefined) {
            this.topSafeHeight = a5.topSafeHeight;
        }
        if (a5.tn !== undefined) {
            this.tn = a5.tn;
        }
        if (a5.controller !== undefined) {
            this.controller = a5.controller;
        }
        if (a5.jsBridge !== undefined) {
            this.jsBridge = a5.jsBridge;
        }
        if (a5.javaScriptAccess !== undefined) {
            this.javaScriptAccess = a5.javaScriptAccess;
        }
        if (a5.fileAccess !== undefined) {
            this.fileAccess = a5.fileAccess;
        }
        if (a5.navCloseBtnBase64 !== undefined) {
            this.navCloseBtnBase64 = a5.navCloseBtnBase64;
        }
        if (a5.windowClass !== undefined) {
            this.windowClass = a5.windowClass;
        }
    }
    updateStateVars(z4) {
    }
    purgeVariableDependenciesOnElmtId(y4) {
        this.__webSrc.purgeDependencyOnElmtId(y4);
        this.__subPage.purgeDependencyOnElmtId(y4);
        this.__backBtnVisibility.purgeDependencyOnElmtId(y4);
        this.__topSafeHeight.purgeDependencyOnElmtId(y4);
    }
    aboutToBeDeleted() {
        this.__webSrc.aboutToBeDeleted();
        this.__subPage.aboutToBeDeleted();
        this.__backBtnVisibility.aboutToBeDeleted();
        this.__topSafeHeight.aboutToBeDeleted();
        SubscriberManager.Get().delete(this.id__());
        this.aboutToBeDeletedInternal();
    }
    get webSrc() {
        return this.__webSrc.get();
    }
    set webSrc(x4) {
        this.__webSrc.set(x4);
    }
    get subPage() {
        return this.__subPage.get();
    }
    set subPage(w4) {
        this.__subPage.set(w4);
    }
    get backBtnVisibility() {
        return this.__backBtnVisibility.get();
    }
    set backBtnVisibility(v4) {
        this.__backBtnVisibility.set(v4);
    }
    get topSafeHeight() {
        return this.__topSafeHeight.get();
    }
    set topSafeHeight(u4) {
        this.__topSafeHeight.set(u4);
    }
    aboutToAppear() {
        try {
            window.getLastWindow(getContext(this), (p4, q4) => {
                const r4 = p4.code;
                if (r4) {
                    UPLogger.error('getWindowAvoidArea失败，原因：' + JSON.stringify(p4));
                    return;
                }
                this.windowClass = q4;
                if (this.windowClass.getWindowProperties().isLayoutFullScreen) {
                    this.topSafeHeight = px2vp(this.windowClass.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM).topRect.height);
                    this.windowClass.on('avoidAreaChange', (t4) => {
                        if (t4.type == window.AvoidAreaType.TYPE_SYSTEM) {
                            this.topSafeHeight = px2vp(t4.area.topRect.height);
                        }
                    });
                }
            });
        }
        catch (n4) {
            UPLogger.error('监听avoidAreaChange失败，原因：' + JSON.stringify(n4));
        }
    }
    aboutToDisappear() {
        try {
            if (this.windowClass?.getWindowProperties().isLayoutFullScreen) {
                this.windowClass?.off('avoidAreaChange');
            }
        }
        catch (m4) {
            UPLogger.error('关闭avoidAreaChange监听失败，失败原因：' + JSON.stringify(m4));
        }
    }
    initialRender() {
        this.observeComponentCreation2((k4, l4) => {
            Stack.create();
            Stack.height('100%');
            Stack.width('100%');
            Stack.margin({ top: this.topSafeHeight });
        }, Stack);
        this.observeComponentCreation2((d4, e4) => {
            Web.create({ src: this.webSrc, controller: this.controller });
            Web.javaScriptProxy({
                object: this.jsBridge,
                name: UPWebViewJavascriptBridge,
                methodList: UPWebViewJavascriptBridgeMethodList,
                controller: this.controller,
            });
            Web.onControllerAttached(() => {
                this.registerHandler();
            });
            Web.onHttpErrorReceive((j4) => {
                if (j4) {
                    UPLogger.error('getResponseCode:' + j4.response.getResponseCode());
                }
            });
            Web.onErrorReceive((i4) => {
                if (i4) {
                    UPLogger.error('getErrorInfo:' + i4.error.getErrorInfo());
                    UPLogger.error('getErrorCode:' + i4.error.getErrorCode());
                }
            });
            Web.javaScriptAccess(this.javaScriptAccess);
            Web.fileAccess(this.fileAccess);
        }, Web);
        this.observeComponentCreation2((a4, b4) => {
            Row.create();
            Row.width(34);
            Row.height(34);
            Row.padding({ left: 10, top: 10 });
            Row.position({ x: 4, y: 4 });
            Row.visibility(this.backBtnVisibility);
            Row.onClick(() => {
                this.closePage(true);
            });
        }, Row);
        this.observeComponentCreation2((y3, z3) => {
            Image.create(this.navCloseBtnBase64);
            Image.width(24);
            Image.height(24);
        }, Image);
        Row.pop();
        Stack.pop();
    }
    registerHandler() {
        this.jsBridge.registerHandler('getDeviceInfo', (o3, p3) => {
            if (this.jsBridge) {
                UPUtil.getDeviceInfo().then((t3) => {
                    this.responseToJS(UPConstant.WEB_PLUGIN_SUCCESS_CODE, UPConstant.WEB_PLUGIN_SUCCESS_MSG, JSON.stringify(t3), p3);
                }).catch((s3) => {
                    this.responseToJS(UPConstant.WEB_PLUGIN_FAIL_CODE, s3.message, null, p3);
                });
            }
        });
        this.jsBridge.registerHandler('saveData', (h3, i3) => {
            if (this.jsBridge) {
                try {
                    if (h3) {
                        let k3 = JSON.parse(h3);
                        UPUtil.writeDatasToPreferences(k3, UPUtil.getApplicationContext())
                            .then(() => {
                            this.responseToJS(UPConstant.WEB_PLUGIN_SUCCESS_CODE, UPConstant.WEB_PLUGIN_SUCCESS_MSG, null, i3);
                        }).catch((n3) => {
                            this.responseToJS(UPConstant.WEB_PLUGIN_FAIL_CODE, n3.message, null, i3);
                        });
                    }
                    else {
                        this.responseToJS(UPConstant.WEB_PLUGIN_FAIL_CODE, UPConstant.WEB_PLUGIN_FAIL_EMPTY_MSG, null, i3);
                    }
                }
                catch (j3) {
                    this.responseToJS(UPConstant.WEB_PLUGIN_FAIL_CODE, j3.message, null, i3);
                }
            }
        });
        this.jsBridge.registerHandler('getData', (b3, c3) => {
            if (this.jsBridge) {
                if (b3) {
                    UPUtil.readDataFromPreferences(b3, UPUtil.getApplicationContext())
                        .then((g3) => {
                        this.responseToJS(UPConstant.WEB_PLUGIN_SUCCESS_CODE, UPConstant.WEB_PLUGIN_SUCCESS_MSG, g3, c3);
                    }).catch((f3) => {
                        this.responseToJS(UPConstant.WEB_PLUGIN_FAIL_CODE, f3.message, null, c3);
                    });
                }
                else {
                    this.responseToJS(UPConstant.WEB_PLUGIN_FAIL_CODE, UPConstant.WEB_PLUGIN_FAIL_EMPTY_MSG, null, c3);
                }
            }
        });
        this.jsBridge.registerHandler('removeData', (w2, x2) => {
            if (this.jsBridge) {
                if (w2) {
                    UPUtil.deleteDataFromPreferences(w2, UPUtil.getApplicationContext())
                        .then(() => {
                        this.responseToJS(UPConstant.WEB_PLUGIN_SUCCESS_CODE, UPConstant.WEB_PLUGIN_SUCCESS_MSG, null, x2);
                    }).catch((a3) => {
                        this.responseToJS(UPConstant.WEB_PLUGIN_FAIL_CODE, a3.message, null, x2);
                    });
                }
                else {
                    this.responseToJS(UPConstant.WEB_PLUGIN_FAIL_CODE, UPConstant.WEB_PLUGIN_FAIL_EMPTY_MSG, null, x2);
                }
            }
        });
        this.jsBridge.registerHandler('openNewPage', (r2, s2) => {
            if (this.jsBridge) {
                if (r2) {
                    try {
                        let u2 = JSON.parse(r2);
                        let v2 = u2.get('url');
                        router.pushNamedRoute({
                            name: EnterName,
                            params: {
                                webSrc: v2,
                                tn: this.tn,
                                subPage: true,
                            }
                        });
                        this.responseToJS(UPConstant.WEB_PLUGIN_SUCCESS_CODE, UPConstant.WEB_PLUGIN_SUCCESS_MSG, null, s2);
                    }
                    catch (t2) {
                        this.responseToJS(UPConstant.WEB_PLUGIN_FAIL_CODE, t2.message, null, s2);
                    }
                }
                else {
                    this.responseToJS(UPConstant.WEB_PLUGIN_FAIL_CODE, UPConstant.WEB_PLUGIN_FAIL_EMPTY_MSG, null, s2);
                }
            }
        });
        this.jsBridge.registerHandler('closePage', (p2, q2) => {
            if (this.jsBridge) {
                this.closePage();
                this.responseToJS(UPConstant.WEB_PLUGIN_SUCCESS_CODE, UPConstant.WEB_PLUGIN_SUCCESS_MSG, null, q2);
            }
        });
        this.jsBridge.registerHandler('payResult', (i2, j2) => {
            if (this.jsBridge) {
                if (i2) {
                    try {
                        let l2 = JSON.parse(i2);
                        let m2 = l2['resultCode'];
                        let n2 = l2['resultData'];
                        let o2 = {
                            'code': m2,
                            'data': n2,
                        };
                        this.sendPayResult(o2);
                        this.responseToJS(UPConstant.WEB_PLUGIN_SUCCESS_CODE, UPConstant.WEB_PLUGIN_SUCCESS_MSG, null, j2);
                    }
                    catch (k2) {
                        this.responseToJS(UPConstant.WEB_PLUGIN_FAIL_CODE, k2.message, null, j2);
                    }
                }
                else {
                    this.responseToJS(UPConstant.WEB_PLUGIN_FAIL_CODE, UPConstant.WEB_PLUGIN_FAIL_EMPTY_MSG, null, j2);
                }
            }
        });
        this.jsBridge.registerHandler('setPageBackEnable', (f2, g2) => {
            if (this.jsBridge) {
                if (typeof f2 === 'boolean') {
                    try {
                        this.isShowBackBtn(f2);
                        this.responseToJS(UPConstant.WEB_PLUGIN_SUCCESS_CODE, UPConstant.WEB_PLUGIN_SUCCESS_MSG, null, g2);
                    }
                    catch (h2) {
                        this.isShowBackBtn(false);
                        this.responseToJS(UPConstant.WEB_PLUGIN_FAIL_CODE, h2.message, null, g2);
                    }
                }
                else {
                    this.isShowBackBtn(false);
                    this.responseToJS(UPConstant.WEB_PLUGIN_FAIL_CODE, UPConstant.WEB_PLUGIN_FAIL_EMPTY_MSG, null, g2);
                }
            }
        });
    }
    responseToJS(r1, s1, t1, u1) {
        let v1 = {};
        v1[UPConstant.WEB_PLUGIN_CODEKEY] = r1;
        v1[UPConstant.WEB_PLUGIN_MSGKEY] = s1;
        if (t1) {
            v1[UPConstant.WEB_PLUGIN_VALUEKEY] = t1;
        }
        let w1 = JSON.stringify(v1);
        if (u1) {
            u1(w1);
        }
    }
    onBackPress() {
        return true;
    }
    isShowBackBtn(q1) {
        this.backBtnVisibility = q1 ? Visibility.Visible : Visibility.Hidden;
    }
    closePage(p1) {
        if (p1 && !this.subPage) {
            this.showExitDialog();
        }
        else {
            router.back();
        }
    }
    sendPayResult(o1) {
        UPUtil.getApplicationContext().eventHub.emit(UPConstant.WEB_PAYRESULT_NOTIFICATION + this.tn, o1);
    }
    showExitDialog() {
        AlertDialog.show({
            title: { "id": -1, "type": 10003, params: ['app.string.UPPAY_ALERT_TITLE'], "bundleName": "com.unionpay.ohos.paydemo", "moduleName": "entry" },
            message: { "id": -1, "type": 10003, params: ['app.string.UPPAY_ALERT_MESSAGE'], "bundleName": "com.unionpay.ohos.paydemo", "moduleName": "entry" },
            primaryButton: {
                value: { "id": -1, "type": 10003, params: ['app.string.UPPAY_ALERT_CANCEL'], "bundleName": "com.unionpay.ohos.paydemo", "moduleName": "entry" },
                action: () => {
                }
            },
            secondaryButton: {
                enabled: true,
                defaultFocus: true,
                style: DialogButtonStyle.HIGHLIGHT,
                value: { "id": -1, "type": 10003, params: ['app.string.UPPAY_ALERT_CONFIRM'], "bundleName": "com.unionpay.ohos.paydemo", "moduleName": "entry" },
                action: () => {
                    let n1 = { 'code': 'cancel' };
                    this.sendPayResult(n1);
                    router.back();
                }
            },
            autoCancel: false,
            alignment: DialogAlignment.Center
        });
    }
    rerender() {
        this.updateDirtyElements();
    }
    static getEntryName() {
        return "UPWebPage";
    }
}
{
    let l1 = EnterName;
    registerNamedRoute(() => new UPWebPage(undefined, {}), l1, { bundleName: "com.unionpay.ohos.paydemo", moduleName: "entry", pagePath: "", integratedHsp: "false" });
}
