import { _decorator, Component, Node } from "cc";
import BaseUI from "../../scripts/base/BaseUI";
import { Tips } from "../../scripts/mgr/Tips";
import { IPayListener, PayItems, PayType } from "../common/PayItems";
import { Event } from "cc";
import ShopM, { ShopDto } from "../../scripts/api/ShopM";
import Utils from "../../scripts/utils/Utils";
import { instantiate } from "cc";
import UIUtils from "../../scripts/base/UIUtils";
import { Vec3 } from "cc";
import { ConfigShopItem } from "../../scripts/api/ConfigM";

const { ccclass, property } = _decorator;

@ccclass("GamePassItem")
export class GamePassItem extends BaseUI implements IPayListener {
  showAnim(to: Node) {
    let from = this.FindNode("icon_game_pass");
    if (to == null || from == null) {
      return;
    }
    let node = instantiate(from);
    node.setParent(from);
    node.setPosition(0, 0, 0);
    UIUtils.moveToNewParent(to, node);
    UIUtils.AnimBezierMoveAndScale(node, new Vec3(0, 0, 0), 1, 1, () => {
      node.destroy();
    });
  }
  onPay(type: PayType, price: number) {
    // this.FindNode("activate").active = true;
    switch (type) {
      case PayType.USDT:
        this.buyUseUSD();
        break;
      case PayType.Gem:
        break;
    }
  }
  buyUseUSD() {
    let result = ShopM.ins.createOrder(this._data.id, PayType.USDT);
  }
  private PaysItem: PayItems;
  private _data: ShopDto;

  protected onLoad(): void {
    super.onLoad();
    this.setTitles();
  }
  setTitles() {}
  init(data: ShopDto,c:ConfigShopItem) {
    this._data = data;
    
    this.setText(
      "lbl_title",
      Utils.setI18nLabel("Shop.GamePassItemTitle", "" + data.seasonId)
    );

    this.PaysItem = this.getComponentInChildren(PayItems);
    let payList = [
      {
        price: 30.0,
        type: PayType.USDT,
      },
    ];

    this.setText(
      "lbl_season_end_time",
      "End Time:" + Utils.formattedOnlyDate(data.endTimeAt)
    );

    this.setText(
      "lbl_desc4",
      Utils.setI18nLabel(
        "Shop.GamePassSalesInfo",
        data.totalSell + "/" +c.total,
        data.freeAirdropSell + "/" + data.freeAirdropTotal
      )
    );

    this.PaysItem.init(payList, this);
  }
}
