import User from "../../FrameWork/User/User";
import AppPlatform from "../../FrameWork/Util/AppPlatform";
import Common5 from "../../Platform/th/Common5";
import TaskManager from "../JuQingChat/TaskManager";

const { ccclass, property } = cc._decorator;

@ccclass
export default class CommonTips extends cc.Component {
    @property(cc.Label)
    lab: cc.Label = null;

    @property(cc.Label)
    btnlab: cc.Label = null;

    @property(cc.Label)
    btnlab2: cc.Label = null;

    callback: any;
    callback2: any;
    isAD1: any;
    isAD2: any;
    // onLoad () {

    // }

    start() {
        Common5.playRemoteAudioEffect("remotesound/effect/游戏点击音效")
    }

    /**
     * 
     * @param str 提示信息
     * @param callback 第一个按钮回调
     * @param btnlab 第一个按钮文本
     * @param btnlab2 第二个按钮文本
     * @param isAD1 第一个按钮带不带广告
     * @param isAD2 第二个按钮带不带广告
     * @param callback2 第二个按钮回调
     */
    init(str, callback?, btnlab?, btnlab2?, isAD1?, isAD2?, callback2?) {
        this.lab.string = str
        this.callback = callback
        this.callback2 = callback2
        this.btnlab.string = btnlab ?? "确定"
        this.isAD1 = isAD1
        this.isAD2 = isAD2
        if (btnlab2) {
            this.btnlab2.string = btnlab2
            this.btnlab2.node.parent.parent.active = true
        } else {
            this.btnlab2.node.parent.parent.active = false
        }

        if (isAD2) {
            this.btnlab2.node.parent.getChildByName("video").active = true
        }
    }

    onTouchSure() {
        //Common5.playEffect("sound/按键点击")
        if (this.callback) {
            this.callback()
        }
        this.node.removeFromParent()
        this.node.destroy()
    }

    onTouchSure2(event) {
        if (this.isAD2) {
            let tab = {
                onClose: (finish) => {
                    if (finish) {
                        User.setShowAdNum(User.getShowAdNum() + 1)
                        Common5.ReportDY("inLevel", `任务${TaskManager.getCurUnLockMainTaskId()}-AD-直接通过`)
                        if (this.callback2) {
                            this.callback2()
                        }
                        this.node.removeFromParent()
                        this.node.destroy()
                    }
                    else {
                        Common5.showTips_custom("广告未观看完");
                    }
                }, onFailed: () => {
                }
            }
            AppPlatform.playVideo_custom(tab)
        } else {
            if (this.callback2) {
                this.callback2()
            }
            this.node.removeFromParent()
            this.node.destroy()
        }

    }
}