import { _decorator, AnimationClip, Animation, ccenum, Component, Label, Node } from 'cc';
const { ccclass, property } = _decorator;

export enum MESSAGE_TYPE
{
    MT_LEVEL_SEL
}
ccenum(MESSAGE_TYPE);

@ccclass('MessageData')
export class MessageData
{
    @property({type: MESSAGE_TYPE})
    public m_MsgType: MESSAGE_TYPE;

    @property({type: String})
    public m_Msg: string;
}

@ccclass('MessagePanel')
export class MessagePanel extends Component // Create a new UIPanelScaled.ts
{
    @property({type: [MessageData]})
    private m_MessageDatas: MessageData[] = [];

    @property({type: Label})
    private m_MessageText: Label;

    @property({type: Animation})
    private m_AnimationComp: Animation;

    @property({type: AnimationClip})
    private m_MsgScaleClip: AnimationClip;

    public fn_InitMessageText(type: MESSAGE_TYPE) : void
    {
        let msgData = this.m_MessageDatas.find(data => data.m_MsgType == type);
        this.m_MessageText.string = msgData.m_Msg;
        this.node.active = true; // refactor using parent class logic
    }

    protected onEnable(): void {
        this.m_AnimationComp.play("messageTextScale");//this.m_MsgScaleClip.name);
    }

    public fn_OnAnimFinished()
    {
        this.m_AnimationComp.stop();
        this.node.active = false;
    }
}

