package dev.crucifixbeta.mod.gui;

import dev.crucifixbeta.mod.modules.impl.client.ClientSetting;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.MinecraftClient;

@Environment(EnvType.CLIENT)
public final class WindowTitleScroller {
   private static final String TITLE_TEXT;
   private static final long UPDATE_DELAY_MS;
   private long lastTitleUpdate;
   private int titlePos;
   private boolean increasing = true;

   public void tick(MinecraftClient client) {
      if (client != null && client.getWindow() != null) {
         long var2 = System.currentTimeMillis();
         if (var2 - this.lastTitleUpdate >= ClientSetting.titleScrollDelay(50L)) {
            this.lastTitleUpdate = var2;
            if (this.increasing) {
               this.titlePos++;
               if (this.titlePos > ("CrucifiX Beta").length()) {
                  this.increasing = false;
               }
            } else {
               this.titlePos--;
               if (this.titlePos < 0) {
                  this.increasing = true;
               }
            }

            String var4;
            if (this.titlePos <= 0) {
               var4 = "";
            } else if (this.titlePos >= ("CrucifiX Beta").length()) {
               var4 = "CrucifiX Beta";
            } else {
               var4 = ("CrucifiX Beta").substring(0, this.titlePos);
            }

            client.getWindow().setTitle(var4);
         }
      }
   }

   static {

      UPDATE_DELAY_MS = 50L;
      TITLE_TEXT = "CrucifiX Beta";
   }
}
