import { MUtils } from "../MUtils";
import MItem from "../components/MItem";

export default class ScoreItem extends MItem {
    public avatarGroup:eui.Group;
    public pic:eui.Image;
    public picMask:eui.Rect;
    public musicName:eui.Label;
    public singer:eui.Label;
    public btnPlay:eui.Button;
    public labelPlay:eui.Label;
    public lableMask:eui.Rect;

    private readonly playingColor: number = 0xfbc1c5;
    private readonly playColor: number = 0xfdfefe;

    private isPlaying = false;

    private async updatePlayState() {
       /*  if (this.isPlaying) {
            this.labelPlay.textColor = this.playingColor;
            MUtils.setButtonImage(this.btnPlay, await RES.getResAsync("score_playing_png"));
        } else {
            this.labelPlay.textColor = this.playColor;
            MUtils.setButtonImage(this.btnPlay, await RES.getResAsync("score_play_png"));
        } */
    }

    dataChanged() {
        this.musicName.text = this.data["musicName"];
        this.singer.text = this.data["singer"];
        this.pic.source = this.data["pic"];
        this.pic.mask=this.picMask;
        this.musicName.mask=this.lableMask;
        this.updatePlayState();
    }


    protected onSkinComplete() {
        this.btnPlay.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onClickPlay, this);
        this.labelPlay.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onClickPlay, this);
    }

    private onClickPlay() {
        this.isPlaying = !this.isPlaying;
        this.updatePlayState();
    }
}