if (!("finalizeConstruction" in ViewPU.prototype)) {
    Reflect.set(ViewPU.prototype, "finalizeConstruction", () => { });
}
interface Index_Params {
    tn?: string;
    mode?: string;
    url?: string;
    seType?: string;
    inputSeType?: string;
    controller?: TextInputController;
}
import http from "@ohos:net.http";
import type { BusinessError } from "@ohos:base";
import PaymentManager from "@bundle:com.unionpay.ohos.paydemo/entry/ets/manager/PaymentManger";
class Index extends ViewPU {
    constructor(parent, params, __localStorage, elmtId = -1, paramsLambda = undefined, extraInfo) {
        super(parent, __localStorage, elmtId, extraInfo);
        if (typeof paramsLambda === "function") {
            this.paramsGenerator_ = paramsLambda;
        }
        this.__tn = new ObservedPropertySimplePU('', this, "tn");
        this.__mode = new ObservedPropertySimplePU('00', this, "mode");
        this.__url = new ObservedPropertySimplePU('', this, "url");
        this.__seType = new ObservedPropertySimplePU('', this, "seType");
        this.__inputSeType = new ObservedPropertySimplePU('', this, "inputSeType");
        this.controller = new TextInputController();
        this.setInitiallyProvidedValue(params);
        this.finalizeConstruction();
    }
    setInitiallyProvidedValue(params: Index_Params) {
        if (params.tn !== undefined) {
            this.tn = params.tn;
        }
        if (params.mode !== undefined) {
            this.mode = params.mode;
        }
        if (params.url !== undefined) {
            this.url = params.url;
        }
        if (params.seType !== undefined) {
            this.seType = params.seType;
        }
        if (params.inputSeType !== undefined) {
            this.inputSeType = params.inputSeType;
        }
        if (params.controller !== undefined) {
            this.controller = params.controller;
        }
    }
    updateStateVars(params: Index_Params) {
    }
    purgeVariableDependenciesOnElmtId(rmElmtId) {
        this.__tn.purgeDependencyOnElmtId(rmElmtId);
        this.__mode.purgeDependencyOnElmtId(rmElmtId);
        this.__url.purgeDependencyOnElmtId(rmElmtId);
        this.__seType.purgeDependencyOnElmtId(rmElmtId);
        this.__inputSeType.purgeDependencyOnElmtId(rmElmtId);
    }
    aboutToBeDeleted() {
        this.__tn.aboutToBeDeleted();
        this.__mode.aboutToBeDeleted();
        this.__url.aboutToBeDeleted();
        this.__seType.aboutToBeDeleted();
        this.__inputSeType.aboutToBeDeleted();
        SubscriberManager.Get().delete(this.id__());
        this.aboutToBeDeletedInternal();
    }
    private __tn: ObservedPropertySimplePU<string>;
    get tn() {
        return this.__tn.get();
    }
    set tn(newValue: string) {
        this.__tn.set(newValue);
    }
    private __mode: ObservedPropertySimplePU<string>;
    get mode() {
        return this.__mode.get();
    }
    set mode(newValue: string) {
        this.__mode.set(newValue);
    }
    private __url: ObservedPropertySimplePU<string>;
    get url() {
        return this.__url.get();
    }
    set url(newValue: string) {
        this.__url.set(newValue);
    }
    private __seType: ObservedPropertySimplePU<string>;
    get seType() {
        return this.__seType.get();
    }
    set seType(newValue: string) {
        this.__seType.set(newValue);
    }
    private __inputSeType: ObservedPropertySimplePU<string>;
    get inputSeType() {
        return this.__inputSeType.get();
    }
    set inputSeType(newValue: string) {
        this.__inputSeType.set(newValue);
    }
    private controller: TextInputController;
    initialRender() {
        this.observeComponentCreation2((elmtId, isInitialRender) => {
            Row.create();
            Row.height('100%');
        }, Row);
        this.observeComponentCreation2((elmtId, isInitialRender) => {
            Column.create();
            Column.width('100%');
        }, Column);
        this.observeComponentCreation2((elmtId, isInitialRender) => {
            Row.create();
            Row.width('100%');
        }, Row);
        this.observeComponentCreation2((elmtId, isInitialRender) => {
            TextInput.create({ text: this.tn, placeholder: '输入tn号', controller: this.controller });
            TextInput.placeholderColor(Color.Grey);
            TextInput.placeholderFont({ size: 14, weight: 400 });
            TextInput.caretColor(Color.Blue);
            TextInput.width('50%');
            TextInput.height(40);
            TextInput.margin({ left: '2%' });
            TextInput.fontSize(13);
            TextInput.fontColor(Color.Black);
            TextInput.onChange((value: string) => {
                this.tn = value;
            });
        }, TextInput);
        this.observeComponentCreation2((elmtId, isInitialRender) => {
            TextInput.create({ text: this.mode, placeholder: '输入mode', controller: this.controller });
            TextInput.margin({ left: '2%', right: '2%' });
            TextInput.placeholderColor(Color.Grey);
            TextInput.placeholderFont({ size: 10, weight: 400 });
            TextInput.caretColor(Color.Blue);
            TextInput.width('15%');
            TextInput.height(40);
            TextInput.fontSize(13);
            TextInput.fontColor(Color.Black);
            TextInput.onChange((value: string) => {
                this.mode = value;
            });
        }, TextInput);
        this.observeComponentCreation2((elmtId, isInitialRender) => {
            TextInput.create({ text: this.inputSeType, placeholder: '输入seType', controller: this.controller });
            TextInput.placeholderColor(Color.Grey);
            TextInput.placeholderFont({ size: 10, weight: 400 });
            TextInput.caretColor(Color.Blue);
            TextInput.width('25%');
            TextInput.height(40);
            TextInput.fontSize(13);
            TextInput.fontColor(Color.Black);
            TextInput.onChange((value: string) => {
                this.inputSeType = value;
            });
        }, TextInput);
        Row.pop();
        this.observeComponentCreation2((elmtId, isInitialRender) => {
            Button.createWithLabel('发起支付', { type: ButtonType.Normal, stateEffect: true });
            Button.fontSize(20);
            Button.fontWeight(FontWeight.Bold);
            Button.borderRadius(8);
            Button.backgroundColor(0x317aff);
            Button.width('80%');
            Button.height(40);
            Button.margin(20);
            Button.onClick(() => {
                this.directPay();
            });
        }, Button);
        Button.pop();
        Column.pop();
        Row.pop();
    }
    directPay() {
        if (this.mode && this.tn) {
            PaymentManager.startPay(this.tn, this.mode, 'uppaymerchantdemo', this.inputSeType);
        }
        else {
            AlertDialog.show({ message: '请先输入mode 和 tn', alignment: DialogAlignment.Center });
        }
    }
    startPay(mode: string, seType?: string) {
        this.sendTnRequest(mode).then((tn) => {
            PaymentManager.startPay(tn, mode, 'uppaymerchantdemo', seType);
            console.log("调用远程支付成功");
        }).catch((error: BusinessError) => {
            console.log("调用远程支付失败");
        });
    }
    sendTnRequest(mode: string): Promise<string> {
        return new Promise((resolve, reject) => {
            let httpRequest = http.createHttp();
            let url = "http://172.21.135.13:10000/para/getRedis";
            let requestOption: http.HttpRequestOptions = {
                method: http.RequestMethod.GET,
            };
            let responsePromise = httpRequest.request(url, requestOption);
            responsePromise.then((data: http.HttpResponse) => {
                let error: BusinessError = {
                    code: 9999,
                    name: "com.uinonpay.merchantdemo",
                    message: "tn请求失败"
                };
                if (data.responseCode === 200) {
                    let tn: string = data.result as string;
                    if (tn) {
                        resolve(tn);
                        return;
                    }
                }
                else {
                    error.code = data.responseCode;
                    error.message = data.result as string;
                }
                reject(error);
            }).catch((err: BusinessError) => {
                reject(err);
            });
        });
    }
    rerender() {
        this.updateDirtyElements();
    }
    static getEntryName(): string {
        return "Index";
    }
}
registerNamedRoute(() => new Index(undefined, {}), "", { bundleName: "com.unionpay.ohos.paydemo", moduleName: "entry", pagePath: "pages/Index", integratedHsp: "false" });
