import { _decorator, Component, Node } from "cc";
import BaseUI from "../../scripts/base/BaseUI";
import { RichText } from "cc";
import UserM, { AnnouncementInfo } from "../../scripts/api/UserM";
import { Hall } from "../hall/Hall";
import ConfigM from "../../scripts/api/ConfigM";
const { ccclass, property } = _decorator;

@ccclass("NoticeLayer")
export class NoticeLayer extends BaseUI {
  static async show(announcement: AnnouncementInfo) {
    if (
      !announcement ||
      announcement.message == null ||
      announcement.message == ""
    ) {
      return;
    }
    let layer = await Hall.ins.showLayer("prefab/layer/NoticeLayer");
    layer.getComponent(NoticeLayer).init(announcement);
  }
  private announcement: AnnouncementInfo;
  init(announcement: AnnouncementInfo) {
    this.announcement = announcement;
    this.FindAs("text_content", RichText).string = announcement.message;
  }

  protected onLoad(): void {
    super.onLoad();
  }

  protected simpleOnBtnClick(name: string): void {
    switch (name) {
      case "btn_chat":
        if (this.announcement.chatLink) {
          ConfigM.ins.openLink(this.announcement.chatLink);
        }
        break;
      case "btn_notice":
        if (this.announcement.noticeLink) {
          ConfigM.ins.openLink(this.announcement.noticeLink);
        }
        break;
    }
  }
}
