package dev.crucifixbeta.mod.modules.settings.impl;

import dev.crucifixbeta.mod.modules.settings.Setting;
import java.lang.reflect.Field;
import java.util.function.BooleanSupplier;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import org.lwjgl.glfw.GLFW;

@Environment(EnvType.CLIENT)
public class BindSetting extends Setting {
   private final int defaultValue;
   public boolean holding = false;
   private int value;
   private boolean pressed = false;
   private boolean holdEnable = false;

   public BindSetting(String name, int value) {
      super(name);
      this.defaultValue = value;
      this.value = value;
   }

   public BindSetting(String name, int value, BooleanSupplier visibilityIn) {
      super(name, visibilityIn);
      this.defaultValue = value;
      this.value = value;
   }

   public int getValue() {
      return this.value;
   }

   public void setValue(int value) {
      this.value = value;
   }

   public String getKeyString() {
      if (this.value == -1) {
         return "None";
      } else if (this.value < -1) {
         return "Mouse" + (Math.abs(this.value) - 1);
      } else {
         String var1 = this.value > 0 ? GLFW.glfwGetKeyName(this.value, GLFW.glfwGetKeyScancode(this.value)) : "None";
         if (var1 == null) {
            try {
               for (Field var6 : GLFW.class.getDeclaredFields()) {
                  if (var6.getName().startsWith("GLFW_KEY_") && (Integer)var6.get(null) == this.value) {
                     String var8 = var6.getName().substring(("GLFW_KEY_").length());
                     var1 = var8.substring(0, 1).toUpperCase() + var8.substring(1).toLowerCase();
                  }
               }
            } catch (Exception var9) {
               var1 = "None";
            }
         }

         return var1 == null ? "Unknown " + this.value : var1.toUpperCase();
      }
   }

   public boolean isPressed() {
      return this.pressed;
   }

   public void setPressed(boolean pressed) {
      this.pressed = pressed;
   }

   public boolean isHoldEnable() {
      return this.holdEnable;
   }

   public void setHoldEnable(boolean holdEnable) {
      this.holdEnable = holdEnable;
   }

   public int getDefaultValue() {
      return this.defaultValue;
   }
}
