package dev.crucifixbeta.mod.gui.items;

import dev.crucifixbeta.api.utils.math.Animation;
import dev.crucifixbeta.api.utils.math.Easing;
import dev.crucifixbeta.core.impl.FontManager;
import dev.crucifixbeta.mod.Mod;
import dev.crucifixbeta.mod.modules.impl.client.ClickGui;
import dev.crucifixbeta.mod.modules.impl.client.Sounds;
import dev.crucifixbeta.mod.modules.impl.render.AntiAlias;
import java.awt.Color;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.sound.PositionedSoundInstance;
import net.minecraft.sound.SoundEvents;

@Environment(EnvType.CLIENT)
public class Item extends Mod {
   public static DrawContext context;
   protected float x;
   protected float y;
   protected int width;
   protected int height;
   private boolean hidden;
   private final Animation visibleHeightAnimation = new Animation();

   public Item(String name) {
      super(name);
   }

   public void setLocation(float x, float y) {
      this.x = x;
      this.y = y;
   }

   public static void sound() {
      if (Sounds.INSTANCE != null) {
         Sounds.INSTANCE.playSwitchSound();
      }
   }

   public static void hoverSound() {
      if (ClickGui.getInstance().hoverSound.getValue()) {
         mc.getSoundManager().play(PositionedSoundInstance.master(SoundEvents.BLOCK_NOTE_BLOCK_BELL, ClickGui.getInstance().hoverSoundPitch.getValueFloat()));
      }
   }

   public void drawScreen(DrawContext context, int mouseX, int mouseY, float partialTicks) {
   }

   public void mouseClicked(int mouseX, int mouseY, int mouseButton) {
   }

   public void mouseReleased(int mouseX, int mouseY, int releaseButton) {
   }

   public void update() {
   }

   public void onKeyTyped(char typedChar, int keyCode) {
   }

   public void onKeyPressed(int key) {
   }

   public float getX() {
      return this.x;
   }

   public float getY() {
      return this.y;
   }

   public int getWidth() {
      return this.width;
   }

   public void setWidth(int width) {
      this.width = width;
   }

   public int getHeight() {
      return this.height;
   }

   public void setHeight(int height) {
      this.height = height;
   }

   public boolean isHidden() {
      return this.hidden;
   }

   public void setHidden(boolean hidden) {
      this.hidden = hidden;
   }

   public double getVisibleHeight() {
      double var1 = this.hidden ? 0.0 : (double)this.getHeight();
      return this.visibleHeightAnimation.get(var1, 200L, Easing.CubicInOut);
   }

   protected double getColorDelay() {
      return (double)this.y / 10.0;
   }

   protected void drawString(String text, double x, double y, Color color) {
      this.drawString(text, x, y, color.hashCode());
   }

   protected void drawString(String text, double x, double y, int color) {
      boolean var7 = FontManager.isShadowEnabled();
      AntiAlias.withTextRender(() -> {
         if (FontManager.shouldUseClientFont(text, FontManager.isCustomFontEnabled())) {
            FontManager.ui.drawString(context.getMatrices(), text, (double)((int)x), (double)((int)y), color, var7);
         } else {
            AntiAlias.drawText(context, mc.textRenderer, text, (int)x, (int)y, color, var7);
         }
      });
   }

   protected void drawSettingString(String text, double x, double y, int color) {
      boolean var7 = FontManager.isShadowEnabled();
      AntiAlias.withTextRender(() -> {
         if (FontManager.shouldUseSettingsFont(text)) {
            FontManager.settings.drawString(context.getMatrices(), text, (double)((int)x), (double)((int)y), color, var7);
         } else if (FontManager.isCustomFontEnabled()) {
            FontManager.ui.drawString(context.getMatrices(), text, (double)((int)x), (double)((int)y), color, var7);
         } else {
            AntiAlias.drawText(context, mc.textRenderer, text, (int)x, (int)y, color, var7);
         }
      });
   }

   protected int getFontHeight() {
      return FontManager.isCustomFontEnabled() ? (int)FontManager.ui.getFontHeight() : 9;
   }

   protected float getCenteredTextY(float baseY, float boxHeight) {
      return baseY + (boxHeight - (float)this.getFontHeight()) / 2.0F + (float)ClickGui.getInstance().textOffset.getValueInt();
   }

   protected int getWidth(String s) {
      return FontManager.shouldUseClientFont(s, FontManager.isCustomFontEnabled()) ? (int)FontManager.ui.getWidth(s) : mc.textRenderer.getWidth(s);
   }

   protected int getSettingWidth(String s) {
      if (FontManager.shouldUseSettingsFont(s)) {
         return (int)FontManager.settings.getWidth(s);
      } else {
         return FontManager.isCustomFontEnabled() ? (int)FontManager.ui.getWidth(s) : mc.textRenderer.getWidth(s);
      }
   }
}
