import Panel from "../views/Panel";

export default class ToastPanel extends Panel {
    public msg: eui.Label;
    public bg: eui.Image;

    private readonly margin = 55;

    constructor(data?: any) {
        super(data, false);
    }

    private mdata: {
        msg: string
    }
    public get skinKey() { return 'ToastPanel' }

    start(data: any) {
        this.mdata = data;
        this.percentHeight = 100;

    }

    onSkinComplete() {
        super.onSkinComplete();
        this.once(egret.Event.ADDED_TO_STAGE, this.onLoad, this);
        if (this.stage) {
            this.onLoad();
        }
    }

    private onLoad(): void {
        if (this.mdata) {
            this.msg.text = this.mdata.msg;
            this.msg.validateSize();
            this.width = this.msg.width + 2 * this.margin;
        }

        setTimeout(function () {
            egret.Tween.get(this).to({ alpha: 0 }, 500, egret.Ease.quintOut).call(function () {
                this.onTouchTap();
            }.bind(this));
        }.bind(this), 1500);

    }

}