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


const { ccclass, property } = cc._decorator;

@ccclass
export default class YiMaJiangResult extends cc.Component {

    @property(cc.Node)
    successNode: cc.Node = null;

    @property(cc.Node)
    failNode: cc.Node = null;

    // LIFE-CYCLE CALLBACKS:

    // onLoad () {}
    leftCallFunc = null
    rightCallFunc = null

    start() {

    }

    initView(tag, leftCallFunc, rightCallFunc) {
        this.leftCallFunc = leftCallFunc
        this.rightCallFunc = rightCallFunc
        if (tag == 'success') {
            let mjConfig = YiMaJiangManager.getMjConfig()

            this.successNode.active = true
            this.failNode.active = false
            this.successNode.getChildByName('money').getComponent(cc.Label).string = Common5.getNumberChangeHanzi(mjConfig.jiangLi, '1', 1) + ''

        } else {
            this.successNode.active = false
            this.failNode.active = true
        }
    }
    onSuccessLingQu() {
        this.leftCallFunc && this.leftCallFunc()
        this.node.removeFromParent()
        this.node.destroy()
    }
    onSuccessShuangBeiLingQu() {
        let tab = {
            onClose: (finish) => {
                if (finish) {
                    User.setShowAdNum(User.getShowAdNum() + 1)
                    Common5.ReportDY("inLevel", `任务${TaskManager.getCurUnLockMainTaskId()}-AD-移麻将复活`)
                    // Common5.ReportDY("inLevel", '复活-AD-移麻将');
                    this.rightCallFunc && this.rightCallFunc()
                    this.node.removeFromParent()
                    this.node.destroy()
                }
                else {
                    Common5.showTips_custom("广告未观看完");
                }

            }, onFailed: () => {

            }
        }
        AppPlatform.playVideo_custom(tab)
    }
    onFailRestart() {
        this.leftCallFunc && this.leftCallFunc()
        this.node.removeFromParent()
        this.node.destroy()
    }
    onFailFuHuo() {
        let tab = {
            onClose: (finish) => {
                if (finish) {
                    User.setShowAdNum(User.getShowAdNum() + 1)
                    Common5.ReportDY("inLevel", `任务${TaskManager.getCurUnLockMainTaskId()}-AD-移麻将复活`)
                    // Common5.ReportDY("inLevel", '复活-AD-移麻将');
                    this.rightCallFunc && this.rightCallFunc()
                    this.node.removeFromParent()
                    this.node.destroy()
                }
                else {
                    Common5.showTips_custom("广告未观看完");
                }

            }, onFailed: () => {

            }
        }
        AppPlatform.playVideo_custom(tab)
    }
    // update (dt) {}
}