import { ryw_Event } from "../FrameWork/Event/EventEnum";
import EventMgr from "../FrameWork/Event/EventMgr";
import GameMgr from "../FrameWork/Mgr/GameMgr";
import AppPlatform from "../FrameWork/Util/AppPlatform";
import Common5 from "../Platform/th/Common5";
import TTAPI from "../Platform/tt/TTAPI";
import PhysicalPowerManger from "../ttFrame/manager/PhysicalPowerManger";


/*
 * @Author: YeeChan
 * @Date: 2021-12-22 18:54:23
 * @Description: 体力不足弹窗
 */
const { ccclass, property } = cc._decorator;

@ccclass
export default class AddPowerUI extends cc.Component {

    protected showNode: cc.Node = null;
    protected btnOk: cc.Node = null;
    protected btnClose: cc.Node = null;
    protected btnBack: cc.Node = null;

    protected start(): void {
        this.showNode = this.node.getChildByName("show");
        this.btnOk = this.showNode.getChildByName("btnOk");
        this.btnClose = this.showNode.getChildByName("btnClose");
        this.btnBack = this.showNode.getChildByName("btnBack");
        this.btnOk.on("click", () => {
            let tab = {
                onClose: (finish)=>{
                    if (finish) {
                        if(AppPlatform.is_TT_GAME_custom()){
                            window["tt"].reportAnalytics('watchAd', {
                                type: '看视频普通体力',
                            });
                        }
                        PhysicalPowerManger.setPhysicalNum(Common5.videoGetPowerNum);
                        GameMgr.getInstance_custom().saveGameData_custom();
                        this.btnCloseFunc();
                        EventMgr.emitEvent_custom(ryw_Event.game_restart);
                    }
                },onFailed:()=>{
    
                }
            }
            AppPlatform.playVideo_custom(tab)
        }, this);

        this.btnClose.on("click", () => {
            this.btnCloseFunc();
        }, this);

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

    btnCloseFunc() {
        this.node.removeFromParent();
        TTAPI.stopRecord_custom();
        cc.director.loadScene("MainScene");
    }

}