// Learn TypeScript:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html

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

const {ccclass, property} = cc._decorator;

@ccclass
export default class BoxTanChuang extends cc.Component {

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

    @property(cc.SpriteFrame)
    titleAprite: cc.SpriteFrame[] = [];


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

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

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


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

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

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


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

    sureCallFunc = null
    cancleCallFunc = null

    setViewData(indexNum,contentStr,sureCallFunc?,cancleCallFunc?){
        if(indexNum<=1){
            this.btnSure.active = true
            this.btnCancle.active = false
            
        }else if(indexNum==2){
            this.btnSure.active = true
            this.btnCancle.active = true
            
        }else if(indexNum==3){
            this.btnSureAD.active = true
            this.btnCancle.active = true
            this.btnSure.active = false
        }
        this.contentStr.string = contentStr
        this.sureCallFunc = sureCallFunc
        this.cancleCallFunc = cancleCallFunc
    }
    
    //0突发事件
    //1剧情完成
    //2重要提示
    //3 突破
    setTitle(titleIndex = 0) {
        this.titleNode.getComponent(cc.Sprite).spriteFrame = this.titleAprite[titleIndex]
    }


    setBtnStr(sureStr, cancleStr, sureADStr) {
        if(sureStr && sureStr.length>0){
            this.btnSureStr.string = sureStr
        }
        if(cancleStr && cancleStr.length>0){
            this.btnCancleStr.string = cancleStr
        }
        if(sureADStr && sureADStr.length>0){
            this.btnSureADStr.string = sureADStr
        }
    }


    start () {

    }

    btSureClick(){
        //Common5.playEffect("sound/按键点击")
        this.sureCallFunc && this.sureCallFunc(false)
        this.node.removeFromParent()
        this.node.destroy()
    }

    btSureADClick(){
        //Common5.playEffect("sound/按键点击")
        let tab = {
            onClose: (finish) => {
                if (finish) {
                    this.sureCallFunc && this.sureCallFunc(true)
                    this.node.removeFromParent()
                    this.node.destroy()

                }else {
                    
                }
            }, onFailed: () => {

            }
        }
        AppPlatform.playVideo_custom(tab)

    }

    btCancleClick(){
        //Common5.playEffect("sound/按键点击")
        this.cancleCallFunc && this.cancleCallFunc(false)
        this.node.removeFromParent()
        this.node.destroy()
    }

    // update (dt) {}
}