import { ryw_Event } from "../../../FrameWork/Event/EventEnum";
import EventMgr from "../../../FrameWork/Event/EventMgr";
import GameReport, { ENTERTYPE, OUTTYPE } from "../../../FrameWork/Report/ZyZyReport";
import User from "../../../FrameWork/User/User";

import AppPlatform from "../../../FrameWork/Util/AppPlatform";

import Common5 from "../../../Platform/th/Common5";
import TTAPI from "../../../Platform/tt/TTAPI";
import TaskManager from "../../JuQingChat/TaskManager";
import Game from "./Game";
// import GameZC from "../GameZC";

const { ccclass, property } = cc._decorator;

@ccclass
export default class GameFailUITimeOut extends cc.Component {

    @property(cc.Node)
    protected btnRestart: cc.Node = null;
    @property(cc.Node)
    protected btnBack: cc.Node = null;
    @property(cc.RichText)
    timeLabel: cc.RichText = null;


    protected start(): void {
        TTAPI.stopRecord_custom();
        // Common5.stopMusic();
        Common5.playEffect("fail");
        Common5.stopMusic();
        // Common5.playMusic("bg");

        this.btnRestart.on("click", () => {
            let tab = {
                onClose: (finish) => {
                    if (finish) {
                        // Common5.selectGameNum = this.level;  
                        if (Common5.selectGameInfo) {

                            let bundle = Common5.selectGameInfo.bundle
                            if (bundle.includes('Level')) {
                                GameReport.ADReport(Common5.selectGameInfo.title2 + '我要加时', 1, "失物招领")
                                // Common5.ReportDY("inLevel", '失物招领-AD-我要加时')
                                User.setShowAdNum(User.getShowAdNum() + 1)
                                Common5.ReportDY("inLevel", `任务${TaskManager.getCurUnLockMainTaskId()}-AD-失物招领我要加时`)
                            } else {
                                GameReport.ADReport(Common5.selectGameInfo.title2 + '我要加时', 1, "总裁训练营")
                                // Common5.ReportDY("inLevel", '总裁训练营-AD-我要加时')
                                User.setShowAdNum(User.getShowAdNum() + 1)
                                Common5.ReportDY("inLevel", `任务${TaskManager.getCurUnLockMainTaskId()}-AD-总裁训练营我要加时`)
                            }

                        }
                        EventMgr.emitEvent_custom(ryw_Event.game_continue);
                        this.node.removeFromParent();
                    }
                    else {
                        let bundle = Common5.selectGameInfo.bundle
                        if (bundle.includes('Level')) {
                            GameReport.ADReport(Common5.selectGameInfo.title2 + '我要加时', 0, "失物招领")
                        } else {
                            GameReport.ADReport(Common5.selectGameInfo.title2 + '我要加时', 0, "总裁训练营")
                        }

                        Common5.showTips_custom("广告未观看完");
                    }
                    this.node.removeFromParent();
                }, onFailed: () => {
                }
            }
            AppPlatform.playVideo_custom(tab);
        }, this);

        this.btnBack.on("click", () => {
            this.btnBackFunc();
        }, this);

        if (this.timeLabel != null) {
            this.timeLabel.string = "还差一点就成功了\r\n看个视频立即加<color=#ff0000>" + Common5.selectGameInfo.timeInit + "</c>秒"
        }
    }

    btnBackFunc() {

        let bundle = Common5.selectGameInfo.bundle
        if (bundle.includes('Level')) {
            //GameZC.ins.clickBack(null,true)
        } else {
            Game.ins.clickBackTimeOut(null, true);
        }


        GameReport.OUTReport(OUTTYPE.SHIBAI, Common5.selectGameInfo.title2)
        this.node.removeFromParent();
    }
}