import { _decorator, Component, Node, Event } from "cc";
import BaseUI from "../../scripts/base/BaseUI";

import { Layout } from "cc";
import { instantiate } from "cc";
import { PlayGameItem } from "../item/PlayGameItem";
import RankM, { RankDto } from "../../scripts/api/RankM";
import Utils from "../../scripts/utils/Utils";
import UserM from "../../scripts/api/UserM";
import { GoodsId } from "../../scripts/api/GoodsId";
import { PageRank } from "./PageRank";

const { ccclass, property } = _decorator;

@ccclass("PagePlay")
export class PagePlay extends BaseUI {
  private tpl: Node = null;
  protected onLoad(): void {
    super.onLoad();

    this.tpl = this.FindNode("PlayGameItem");
    this.tpl.active = false;
    this.ui();
  }
  async ui() {
    let layout = this.FindNode("games_layout");

    // this.tpl.getComponent(PlayGameItem).init(100);
    layout.removeAllChildren();
    let list = UserM.ins.data.gameList;

    for (let i = 0; i < list.length; i++) {
      if (list[i].gameId != 2) {
        continue;
      }

      let item = instantiate(this.tpl);
      item.parent = layout;
      item.active = true;
      item.getComponent(PlayGameItem).init(list[i]);
    }
  }

  public onShow(): void {
    super.onShow();
  }

  public onHide(): void {
    super.onHide();
  }
  protected onBtnClick(name: string, event: Event, customEventData: any): void {
    super.onBtnClick(name, event, customEventData);
  }
}
