package wtf.opal.utility.misc.time;

import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;

@Environment(EnvType.CLIENT)
public final class Stopwatch {
   private long lastMs;

   public Stopwatch(long lastMs) {
      this.lastMs = lastMs;
   }

   public Stopwatch() {
      this.reset();
   }

   public void reset() {
      this.lastMs = System.currentTimeMillis();
   }

   public boolean hasTimeElapsed(long time, boolean reset) {
      if (this.getTime() > time) {
         if (reset) {
            this.reset();
         }

         return true;
      } else {
         return false;
      }
   }

   public boolean hasTimeElapsed(long time) {
      return this.hasTimeElapsed(time, false);
   }

   public long getTime() {
      return System.currentTimeMillis() - this.lastMs;
   }

   public void setTime(long time) {
      this.lastMs = time;
   }

   public long remainingUntil(long time) {
      long var3 = time - this.getTime();
      return Math.max(0L, var3);
   }

   public boolean isWithin(long time, long lookaheadMs) {
      if (time <= 0L) {
         return false;
      } else {
         long var5 = this.getTime();
         long var7 = Math.max(0L, time - Math.max(0L, lookaheadMs));
         return var5 >= var7;
      }
   }
}
