import { TipsData, TipsLayer } from "../../prefab/layer/TipsLayer";
import ADManager from "./ADManager";

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

  public async showAd() {
    //@ts-ignore
    if (!window.googletag) {
      let tipsData = TipsLayer.build("Failed to connect Google Ad Server");
      tipsData.forceConfirm = true;
      await tipsData.show();
      return false;
    } else {
      let success: boolean = await TipsLayer.showConfirm(
        "",
        "Complete the ad to claim your rewards!"
      );
      if (success) {
        return new Promise(async (resolve, reject) => {
          let success = false;
          ADManager.ins.showGoogleAD(() => {
            success = true;
            resolve(true);
          });

          setTimeout(() => {
            if (success) {
              return;
            }
            resolve(false);
          }, 40*1000);
        });
      }
    }
  }
}
