package dev.crucifixbeta.core.impl;

import dev.crucifixbeta.mod.modules.impl.player.TimerModule;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;

@Environment(EnvType.CLIENT)
public class TimerManager {
   public float timer = 1.0F;
   public float lastTimer;
   private int skipTicks;

   public void set(float factor) {
      if (factor < 0.1F) {
         factor = 0.1F;
      }

      this.timer = factor;
   }

   public void reset() {
      this.lastTimer = this.timer = this.getDefault();
   }

   public void tryReset() {
      if (this.lastTimer != this.getDefault()) {
         this.reset();
      }
   }

   public float get() {
      return this.timer;
   }

   public float getDefault() {
      return TimerModule.INSTANCE.isOn()
         ? (TimerModule.INSTANCE.boostKey.isPressed() ? TimerModule.INSTANCE.boost.getValueFloat() : TimerModule.INSTANCE.multiplier.getValueFloat())
         : 1.0F;
   }

   public void addSkipTicks(int ticks) {
      this.skipTicks = this.skipTicks + Math.max(0, ticks);
   }

   public void clearSkipTicks() {
      this.skipTicks = 0;
   }

   public int consumeSkipTicks() {
      return this.skipTicks <= 0 ? 0 : this.skipTicks--;
   }
}
