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.parent = layout;
    this.tpl.active = true;
    this.tpl.getComponent(PlayGameItem).init(100);
    // layout.removeAllChildren();
    // for (let i = 0; i < 1; i++) {
    //   let item = instantiate(this.tpl);
    //   item.parent = layout;
    //   item.active = true;
    //   item.getComponent(PlayGameItem).init((i + 1) * 100);
    // }

    let data: RankDto = await RankM.ins.rankData(PageRank.RankTypeSeason);

    this.setText(
      "lbl_send_portal",
      Utils.formatNumber(data.remainPog, 0) +
        "/" +
        Utils.formatNumber(data.seasonPog, 0)
    );
    this.setText(
      "lbl_remain_portal",
      "" + UserM.ins.getGoodsCount(GoodsId.POG)
    );
  }

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

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