package wtf.opal.client.feature.module.property.impl;

import java.awt.Color;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import wtf.opal.client.feature.module.property.Property;
import wtf.opal.client.feature.module.property.impl.mode.ModuleMode;
import wtf.opal.client.screen.click.dropdown.panel.property.PropertyPanel;
import wtf.opal.client.screen.click.dropdown.panel.property.impl.ColorPropertyComponent;
import wtf.opal.utility.render.ColorUtility;

@Environment(EnvType.CLIENT)
public final class ColorProperty extends Property<Integer> {
   private final float[] hsb = new float[3];

   public ColorProperty(String name, int value) {
      super(name);
      this.setValue(Integer.valueOf(value));
   }

   public ColorProperty(String name, ModuleMode<?> parent, int value) {
      super(name, parent);
      this.setValue(Integer.valueOf(value));
   }

   public float[] getHSB() {
      return this.hsb;
   }

   public void setHue(float hue) {
      this.hsb[0] = hue;
   }

   public void setSaturation(float saturation) {
      this.hsb[1] = saturation;
   }

   public void setBrightness(float brightness) {
      this.hsb[2] = brightness;
   }

   public void updateValue() {
      this.setValue(Integer.valueOf(Color.HSBtoRGB(this.hsb[0], this.hsb[1], this.hsb[2])));
   }

   @Override
   public PropertyPanel<?> createClickGUIComponent() {
      return new ColorPropertyComponent(this);
   }

   @Override
   public void applyValue(Object propertyValue) {
      double var2 = Double.parseDouble(String.valueOf(propertyValue));
      int[] var4 = ColorUtility.hexToRGB((int)var2);
      float[] var5 = Color.RGBtoHSB(var4[0], var4[1], var4[2], null);
      this.setHue(var5[0]);
      this.setSaturation(var5[1]);
      this.setBrightness(var5[2]);
      this.updateValue();
   }
}
