package dev.crucifixbeta.mod.modules.impl.client.hud;

import dev.crucifixbeta.api.utils.render.TextUtil;
import dev.crucifixbeta.core.impl.FontManager;
import dev.crucifixbeta.mod.modules.HudModule;
import dev.crucifixbeta.mod.modules.impl.client.ColorsModule;
import dev.crucifixbeta.mod.modules.settings.impl.StringSetting;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.gui.DrawContext;

@Environment(EnvType.CLIENT)
public class WaterMarkHudModule extends HudModule {
   public static WaterMarkHudModule INSTANCE;
   public final StringSetting title = this.add(new StringSetting("Title", "%hackname% %version%"));

   public WaterMarkHudModule() {
      super("WaterMark", "\u6c34\u5370", 1, 1);
      INSTANCE = this;
   }

   @Override
   public void onRender2D(DrawContext context, float tickDelta) {
      String var3 = this.title
         .getValue()
         .replaceAll("%version%", "V3.0")
         .replaceAll("%hackname%", "CrucifiX Beta");
      int var4 = HudSetting.useFont() ? (int)Math.ceil((double)FontManager.ui.getWidth(var3)) : mc.textRenderer.getWidth(var3);
      int var5;
      if (HudSetting.useFont()) {
         var5 = (int)Math.ceil((double)FontManager.ui.getFontHeight());
      } else {
         var5 = 9;
      }

      int var6 = this.getHudRenderX(var4);
      int var7 = this.getHudRenderY(var5);
      int var8 = this.getHudColor(0.0);
      TextUtil.drawString(context, var3, (double)var6, (double)var7, var8, HudSetting.useFont(), false);
      this.setHudBounds(var6, var7, Math.max(1, var4), Math.max(1, var5));
   }

   private int getHudColor(double delay) {
      ColorsModule var3 = ColorsModule.INSTANCE;
      return var3 == null ? -1 : var3.getHudColorRGB(delay);
   }
}
