import { MUtils } from "../MUtils";
import MItem from "../components/MItem";
import { NetPromise } from "../NetPromise";
import PanelCtrl from "../ctrls/panelCtrl";
import { ModuleTypes } from "../types/sceneTypes";
import { DataManager } from "../../libs/tw/manager/DataManager";
import { NetName } from "../../libs/tw/enum/NetName";

export default class ListenMusicItem extends MItem {
    public avatarGroup:eui.Group;
    public pic:eui.Image;
    public picMask:eui.Rect;
    public musicName:eui.Label;
    public singer:eui.Label;
    public btnOk:eui.Button;
    public lableMask:eui.Rect;
    dataChanged() {
        this.musicName.text = this.data["musicName"];
        this.singer.text = this.data["singer"];
        this.musicName.mask=this.lableMask;
        this.pic.mask=this.picMask;
        this.musicName.mask=this.lableMask;
        this.pic.source = this.data["albumpic"];
    }

    protected onSkinComplete() {
        this.btnOk.addEventListener(egret.TouchEvent.TOUCH_TAP, () => {
            console.log("收听歌曲：" + this.data["musicName"]);
            NetPromise.ins.completeTaskKuwo(window["eduSignId"],2)
            .then(()=>{
                console.log("收听歌曲")
                NetPromise.ins.handlePlay({
                    album: "Live It Up (Official Song 2018 FIFA World Cup Russia)",
                    artist: "Will Smith&Nicky Jam&Era Istrefi",
                    formats: "",
                    fsongname: "",
                    hasmv: false,
                    isdownload: "0",
                    kmark: "",
                    musicrid: "41450436",
                    name: "Live It Up (Official Song 2018 FIFA World Cup Russia)",
                    nationid: "1",
                    online: "1",
                    pay: "16515324",
          psrc: "h5app_worldcup"
                })
                PanelCtrl.instance.show(ModuleTypes.REWARD_PANEL, {
                    title: `完成收听歌曲`,
                    rewardNum: DataManager.ins.getData(NetName.COMPLETE_TASK_KUWO).data.response.changeMoney ? DataManager.ins.getData(NetName.COMPLETE_TASK_KUWO).data.response.changeMoney : 0
                });
                this.enabled=true;
            })
            .catch(()=>{
                this.enabled=true;
            })
        }, this);
    }
}