import Utils from "../utils/Utils";
import TgM from "./TgM";
import { Tips } from "./Tips";

export default class ShareM {
  private static _ins: ShareM;
  public static get ins(): ShareM {
    return (ShareM._ins ??= new ShareM());
  }

  private static readonly tgLink = `https://t.me/TelgatherPortalBot/portal`;
  private static readonly webLink = `https://portal.telgather.com`;
  async shareFamily(familyName: string, familyOwner: string) {
    let shareLink = await this.getFamilyShareLink(familyName, familyOwner);
    await this.share(shareLink);
  }

  async getFamilyShareLink(
    familyName: string,
    familyOwner: string
  ): Promise<string> {
    let isTg = await TgM.ins.isTG();
    let link = isTg ? ShareM.tgLink : ShareM.webLink;
    let fullString = `Join my Family from Telgather Game Portal now to share progress and unlock rewards together!
    [${familyName}] [${familyOwner}] ${link}`;
    return fullString;
  }

  async share(shareLink: string) {
    let isTg = await TgM.ins.isTG();
    if (isTg) {
      TgM.ins.shareToTg(shareLink);
    } else {
      Utils.copyText(shareLink);
      Tips.show("Copied to clipboard");
    }
  }
}
