package net.vulkanmod.config.gui.widget;

import java.util.function.Consumer;
import net.minecraft.class_2561;
import net.minecraft.class_310;
import net.minecraft.class_327;
import net.minecraft.class_3532;
import net.vulkanmod.config.gui.render.GuiRenderer;
import net.vulkanmod.vulkan.util.ColorUtil;

public class VButtonWidget extends VAbstractWidget {
   boolean selected = false;
   Consumer<VButtonWidget> onPress;
   float alpha = 1.0F;

   public VButtonWidget(int x, int y, int width, int height, class_2561 message, Consumer<VButtonWidget> onPress) {
      this.setPosition(x, y, width, height);
      this.message = message;
      this.onPress = onPress;
   }

   public void renderWidget(double mouseX, double mouseY) {
      class_310 minecraftClient = class_310.method_1551();
      class_327 textRenderer = minecraftClient.field_1772;
      int xPadding = 0;
      int yPadding = 0;
      int color = ColorUtil.ARGB.pack(0.0F, 0.0F, 0.0F, this.active ? 0.45F : 0.3F);
      GuiRenderer.fill(this.x - xPadding, this.y - yPadding, this.x + this.width + xPadding, this.y + this.height + yPadding, color);
      if (this.active) {
         this.renderHovering(0, 0);
      }

      if (this.selected) {
         color = ColorUtil.ARGB.pack(0.3F, 0.0F, 0.0F, 1.0F);
         GuiRenderer.fillBox(this.x, this.y, 1, this.height, color);
         color = ColorUtil.ARGB.pack(0.3F, 0.0F, 0.0F, 0.2F);
         GuiRenderer.fillBox(this.x, this.y, this.width, this.height, color);
      }

      int j = this.active ? 16777215 : 10526880;
      GuiRenderer.drawCenteredString(textRenderer, this.message, this.x + this.width / 2, this.y + (this.height - 8) / 2, j | class_3532.method_15386(this.alpha * 255.0F) << 24);
   }

   public void setSelected(boolean selected) {
      this.selected = selected;
   }

   public void onClick(double mX, double mY) {
      this.onPress.accept(this);
   }
}
