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

import PoolMgr, { NODEPOOLPREFABTYPE } from "../../mgr/PoolMgr";
import LevelRedPacketUI from "../LevelRedPacketUI";
import GamePlay from "../../GamePlay";
import GameMgr, { UIITEM_NAME, UI_NAME } from "../../mgr/GameMgr";

const { ccclass, property } = cc._decorator;

@ccclass
export default class LevelRedPacketItem extends cc.Component {

    @property(cc.Animation)
    ani_waggle: cc.Animation = null;


    // LIFE-CYCLE CALLBACKS:

    // onLoad () {}

    start() {
        this.node.on(cc.Node.EventType.TOUCH_END, this.onClick, this);
    }

    // update (dt) {}

    onClick() {
        
        GameMgr.Inst.sendEvent(UIITEM_NAME.LevelRedPacketItem,"点击随机红包");
       
        mk.ui.openPanel("game/prefab/uiPanel/LevelRedPacketUI").then((node)=>{
            node.getComponent(LevelRedPacketUI).init(GamePlay.Inst.cleanedVecArr.length);
        })
      
        this.recycle();
    }

    recycle() {
        PoolMgr.Inst.recyclePoolPrefab(NODEPOOLPREFABTYPE.LevelRedPacketItem, this.node);
    }
}
