import Gamecfg from "../../../../common/gameCfg";
import { gameMethod } from "../../../../common/gameMethod";
import { UserEvent } from "../../../../data/const/EventConst";
import GameDataCenter from "../../../../data/GameDataCenter";
import { MergeItem } from "../../../../data/model/GridMap/GridMapModel";
import { ListUtil } from "../../../../frameWork/fgui/ListUtil";
import EventMng from "../../../../manager/EventMng";
import { GridEvent } from "../../../gridMap/GridEvent";
import HomeMergeTipItem from "./HomeMergeTipItem";


export interface MergeTipData {
    isShow: boolean;
    mergeArr?: MergeItem[];
}
export default class HomeMergeTipCom {
    private _vm: fairygui.GComponent;
    private MergeList: fgui.GList;
    private mergeGroup: fgui.GGroup;
    MergeListUtil: ListUtil;
    public constructor(vm: fgui.GComponent) {
        this._vm = vm;
        this.MergeList = vm.getChild('MergeList').asList;
        this.mergeGroup = vm.getChild('mergeGroup').asGroup;
        this.MergeListUtil = new ListUtil(this.MergeList, HomeMergeTipItem);

    }

    public onEnable(): void {
        EventMng.on(GridEvent.HC_MERGE_TIP, this.OnHcMergeTip, this);
    }


    public onDisable(): void {
        EventMng.off(GridEvent.HC_MERGE_TIP, this.OnHcMergeTip, this);

    }


    private OnHcMergeTip(data: MergeTipData): void {
        this._vm.visible = data.isShow;
        if (data.isShow) {
            this.MergeListUtil.refreshItems(data.mergeArr);
        }
    }
}
