package wtf.opal.client.screen.click.dropdown.panel.property.impl;

import com.ibm.icu.impl.Pair;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.gui.DrawContext;
import wtf.opal.client.feature.module.property.impl.mode.ModeProperty;
import wtf.opal.client.renderer.NVGRenderer;
import wtf.opal.client.renderer.repository.FontRepository;
import wtf.opal.client.renderer.text.NVGTextRenderer;
import wtf.opal.client.screen.click.dropdown.ClickGuiAnimationConfig;
import wtf.opal.client.screen.click.dropdown.panel.property.PropertyPanel;
import wtf.opal.utility.render.ClientTheme;
import wtf.opal.utility.render.ColorUtility;
import wtf.opal.utility.render.animation.Animation;
import wtf.opal.utility.render.animation.Easing;

@Environment(EnvType.CLIENT)
public final class ModePropertyComponent extends PropertyPanel<ModeProperty<?>> {
   private final Animation expandAnimation = new Animation(Easing.DECELERATE, 125L);
   private boolean expanded;

   public ModePropertyComponent(ModeProperty<?> property) {
      super(property);
   }

   @Override
   public void render(DrawContext context, int mouseX, int mouseY, float delta) {
      super.render(context, mouseX, mouseY, delta);
      ClickGuiAnimationConfig.applyParameterPanel(this.expandAnimation, 125L, Easing.DECELERATE);
      this.expandAnimation.run(this.expanded ? 1.0F : 0.0F);
      NVGTextRenderer var5 = FontRepository.getFont("productsans-medium");
      NVGTextRenderer var6 = FontRepository.getFont("productsans-bold");
      var5.drawString(this.getProperty().getName(), this.x + 5.0F, this.y + 9.5F, 7.0F, -1);
      float var7 = 2.0F;
      float var8 = this.x + 3.0F;
      float var9 = this.y + 2.0F + 11.5F;
      float var10 = this.width - 5.0F - 2.0F;
      NVGRenderer.roundedRect(var8, var9, var10, this.height - 2.0F - 15.0F, 4.0F, ColorUtility.scaleOpacity(ColorUtility.getPanelBackgroundColor(), 0.25F));
      var6.drawString(this.getProperty().getValue().toString(), var8 + 4.0F, var9 + 10.0F, 7.0F, -1);
      if (this.getProperty().isTheme()) {
         ClientTheme var11 = ClientTheme.valueOf(this.getProperty().getValue().name());
         Pair var12 = var11.getColors();
         float var13 = var6.getStringWidth(this.getProperty().getValue().toString(), 7.0F);
         NVGRenderer.roundedRect(var8 + var13 + 7.0F, var9 + 4.0F, 7.0F, 7.0F, 2.0F, (Integer)var12.first);
         NVGRenderer.roundedRect(var8 + var13 + 16.0F, var9 + 4.0F, 7.0F, 7.0F, 2.0F, (Integer)var12.second);
      }

      String var15 = "\ue5cf";
      NVGTextRenderer var16 = FontRepository.getFont("materialicons-regular");
      float var17 = 9.0F;
      float var14 = var16.getStringWidth("\ue5cf", 9.0F);
      NVGRenderer.rotate(
         (double)(this.expandAnimation.getValue() * 180.0F),
         var8 + var10 - 12.0F,
         var9 + 2.5F,
         var14,
         9.0F,
         () -> var16.drawString("\ue5cf", 0.0F, 0.0F, 9.0F, -1, false, 18)
      );
      NVGRenderer.scissor(
         var8,
         var9,
         var10,
         this.height - 2.0F - 15.0F,
         () -> {
            // $VF: Couldn't be decompiled
            // Please report this to the Vineflower issue tracker, at https://github.com/Vineflower/vineflower/issues with a copy of the class file (if you have the rights to distribute it!)
            // java.lang.NullPointerException: Cannot invoke "org.jetbrains.java.decompiler.struct.gen.VarType.isGeneric()" because "newRet" is null
            //   at org.jetbrains.java.decompiler.modules.decompiler.exps.InvocationExprent.getInferredExprType(InvocationExprent.java:634)
            //   at org.jetbrains.java.decompiler.modules.decompiler.stats.DoStatement.toJava(DoStatement.java:146)
            //   at org.jetbrains.java.decompiler.modules.decompiler.ExprProcessor.jmpWrapper(ExprProcessor.java:833)
            //   at org.jetbrains.java.decompiler.modules.decompiler.stats.IfStatement.toJava(IfStatement.java:241)
            //   at org.jetbrains.java.decompiler.modules.decompiler.ExprProcessor.jmpWrapper(ExprProcessor.java:833)
            //   at org.jetbrains.java.decompiler.modules.decompiler.stats.SequenceStatement.toJava(SequenceStatement.java:107)
            //   at org.jetbrains.java.decompiler.modules.decompiler.stats.RootStatement.toJava(RootStatement.java:36)
            //   at org.jetbrains.java.decompiler.main.ClassWriter.methodLambdaToJava(ClassWriter.java:949)
            //
            // Bytecode:
            // 00: bipush 0
            // 01: istore 4
            // 03: aload 0
            // 04: getfield wtf/opal/client/screen/click/dropdown/panel/property/impl/ModePropertyComponent.expandAnimation Lwtf/opal/utility/render/animation/Animation;
            // 07: invokevirtual wtf/opal/utility/render/animation/Animation.getValue ()F
            // 0a: fconst_0
            // 0b: fcmpl
            // 0c: ifle e8
            // 0f: aload 0
            // 10: invokevirtual wtf/opal/client/screen/click/dropdown/panel/property/impl/ModePropertyComponent.getProperty ()Lwtf/opal/client/feature/module/property/Property;
            // 13: checkcast wtf/opal/client/feature/module/property/impl/mode/ModeProperty
            // 16: invokevirtual wtf/opal/client/feature/module/property/impl/mode/ModeProperty.getValues ()[Ljava/lang/Enum;
            // 19: astore 5
            // 1b: aload 5
            // 1d: arraylength
            // 1e: istore 6
            // 20: bipush 0
            // 21: istore 7
            // 23: iload 7
            // 25: iload 6
            // 27: if_icmpge e8
            // 2a: aload 5
            // 2c: iload 7
            // 2e: aaload
            // 2f: astore 8
            // 31: aload 8
            // 33: ifnull e2
            // 36: aload 8
            // 38: aload 0
            // 39: invokevirtual wtf/opal/client/screen/click/dropdown/panel/property/impl/ModePropertyComponent.getProperty ()Lwtf/opal/client/feature/module/property/Property;
            // 3c: checkcast wtf/opal/client/feature/module/property/impl/mode/ModeProperty
            // 3f: invokevirtual wtf/opal/client/feature/module/property/impl/mode/ModeProperty.getValue ()Ljava/lang/Object;
            // 42: if_acmpne 48
            // 45: goto e2
            // 48: aload 1
            // 49: aload 8
            // 4b: invokevirtual java/lang/Enum.toString ()Ljava/lang/String;
            // 4e: fload 2
            // 4f: ldc 4.0
            // 51: fadd
            // 52: fload 3
            // 53: ldc 9.5
            // 55: fadd
            // 56: ldc 13.0
            // 58: fadd
            // 59: iload 4
            // 5b: i2f
            // 5c: fadd
            // 5d: ldc 7.0
            // 5f: bipush -1
            // 60: invokevirtual wtf/opal/client/renderer/text/NVGTextRenderer.drawString (Ljava/lang/String;FFFI)F
            // 63: pop
            // 64: aload 0
            // 65: invokevirtual wtf/opal/client/screen/click/dropdown/panel/property/impl/ModePropertyComponent.getProperty ()Lwtf/opal/client/feature/module/property/Property;
            // 68: checkcast wtf/opal/client/feature/module/property/impl/mode/ModeProperty
            // 6b: invokevirtual wtf/opal/client/feature/module/property/impl/mode/ModeProperty.isTheme ()Z
            // 6e: ifeq df
            // 71: aload 8
            // 73: invokevirtual java/lang/Enum.name ()Ljava/lang/String;
            // 76: invokestatic wtf/opal/utility/render/ClientTheme.valueOf (Ljava/lang/String;)Lwtf/opal/utility/render/ClientTheme;
            // 79: astore 9
            // 7b: aload 9
            // 7d: invokevirtual wtf/opal/utility/render/ClientTheme.getColors ()Lcom/ibm/icu/impl/Pair;
            // 80: astore 10
            // 82: fload 2
            // 83: aload 0
            // 84: getfield wtf/opal/client/screen/click/dropdown/panel/property/impl/ModePropertyComponent.width F
            // 87: fadd
            // 88: ldc 5.0
            // 8a: fsub
            // 8b: fconst_2
            // 8c: fsub
            // 8d: ldc_w 20.5
            // 90: fsub
            // 91: fload 3
            // 92: ldc_w 3.5
            // 95: fadd
            // 96: ldc 13.0
            // 98: fadd
            // 99: iload 4
            // 9b: i2f
            // 9c: fadd
            // 9d: ldc 7.0
            // 9f: ldc 7.0
            // a1: ldc 2.5
            // a3: aload 10
            // a5: getfield com/ibm/icu/impl/Pair.first Ljava/lang/Object;
            // a8: checkcast java/lang/Integer
            // ab: invokevirtual java/lang/Integer.intValue ()I
            // ae: invokestatic wtf/opal/client/renderer/NVGRenderer.roundedRect (FFFFFI)V
            // b1: fload 2
            // b2: aload 0
            // b3: getfield wtf/opal/client/screen/click/dropdown/panel/property/impl/ModePropertyComponent.width F
            // b6: fadd
            // b7: ldc 5.0
            // b9: fsub
            // ba: fconst_2
            // bb: fsub
            // bc: ldc 12.0
            // be: fsub
            // bf: fload 3
            // c0: ldc_w 3.5
            // c3: fadd
            // c4: ldc 13.0
            // c6: fadd
            // c7: iload 4
            // c9: i2f
            // ca: fadd
            // cb: ldc 7.0
            // cd: ldc 7.0
            // cf: ldc 2.5
            // d1: aload 10
            // d3: getfield com/ibm/icu/impl/Pair.second Ljava/lang/Object;
            // d6: checkcast java/lang/Integer
            // d9: invokevirtual java/lang/Integer.intValue ()I
            // dc: invokestatic wtf/opal/client/renderer/NVGRenderer.roundedRect (FFFFFI)V
            // df: iinc 4 13
            // e2: iinc 7 1
            // e5: goto 23
            // e8: aload 0
            // e9: ldc 32.0
            // eb: iload 4
            // ed: i2f
            // ee: aload 0
            // ef: getfield wtf/opal/client/screen/click/dropdown/panel/property/impl/ModePropertyComponent.expandAnimation Lwtf/opal/utility/render/animation/Animation;
            // f2: invokevirtual wtf/opal/utility/render/animation/Animation.getValue ()F
            // f5: fmul
            // f6: fadd
            // f7: invokevirtual wtf/opal/client/screen/click/dropdown/panel/property/impl/ModePropertyComponent.setHeight (F)V
            // fa: return
         }
      );
   }

   @Override
   public void mouseClicked(double mouseX, double mouseY, int button) {
      // $VF: Couldn't be decompiled
      // Please report this to the Vineflower issue tracker, at https://github.com/Vineflower/vineflower/issues with a copy of the class file (if you have the rights to distribute it!)
      // java.lang.NullPointerException: Cannot invoke "org.jetbrains.java.decompiler.struct.gen.VarType.isGeneric()" because "newRet" is null
      //   at org.jetbrains.java.decompiler.modules.decompiler.exps.InvocationExprent.getInferredExprType(InvocationExprent.java:634)
      //   at org.jetbrains.java.decompiler.modules.decompiler.stats.DoStatement.toJava(DoStatement.java:146)
      //   at org.jetbrains.java.decompiler.modules.decompiler.ExprProcessor.jmpWrapper(ExprProcessor.java:833)
      //   at org.jetbrains.java.decompiler.modules.decompiler.stats.SequenceStatement.toJava(SequenceStatement.java:107)
      //   at org.jetbrains.java.decompiler.modules.decompiler.ExprProcessor.jmpWrapper(ExprProcessor.java:833)
      //   at org.jetbrains.java.decompiler.modules.decompiler.stats.IfStatement.toJava(IfStatement.java:241)
      //   at org.jetbrains.java.decompiler.modules.decompiler.ExprProcessor.jmpWrapper(ExprProcessor.java:833)
      //   at org.jetbrains.java.decompiler.modules.decompiler.stats.SequenceStatement.toJava(SequenceStatement.java:107)
      //   at org.jetbrains.java.decompiler.modules.decompiler.stats.RootStatement.toJava(RootStatement.java:36)
      //   at org.jetbrains.java.decompiler.main.ClassWriter.writeMethod(ClassWriter.java:1283)
      //
      // Bytecode:
      // 00: aload 0
      // 01: getfield wtf/opal/client/screen/click/dropdown/panel/property/impl/ModePropertyComponent.expanded Z
      // 04: ifeq ab
      // 07: iload 5
      // 09: ifne ab
      // 0c: fconst_2
      // 0d: fstore 6
      // 0f: aload 0
      // 10: getfield wtf/opal/client/screen/click/dropdown/panel/property/impl/ModePropertyComponent.x F
      // 13: ldc 3.0
      // 15: fadd
      // 16: fstore 7
      // 18: aload 0
      // 19: getfield wtf/opal/client/screen/click/dropdown/panel/property/impl/ModePropertyComponent.y F
      // 1c: fconst_2
      // 1d: fadd
      // 1e: ldc 11.5
      // 20: fadd
      // 21: fstore 8
      // 23: aload 0
      // 24: getfield wtf/opal/client/screen/click/dropdown/panel/property/impl/ModePropertyComponent.width F
      // 27: ldc 8.0
      // 29: fsub
      // 2a: fconst_2
      // 2b: fsub
      // 2c: ldc 3.0
      // 2e: fsub
      // 2f: fstore 9
      // 31: bipush 0
      // 32: istore 10
      // 34: aload 0
      // 35: invokevirtual wtf/opal/client/screen/click/dropdown/panel/property/impl/ModePropertyComponent.getProperty ()Lwtf/opal/client/feature/module/property/Property;
      // 38: checkcast wtf/opal/client/feature/module/property/impl/mode/ModeProperty
      // 3b: invokevirtual wtf/opal/client/feature/module/property/impl/mode/ModeProperty.getValues ()[Ljava/lang/Enum;
      // 3e: astore 11
      // 40: aload 11
      // 42: arraylength
      // 43: istore 12
      // 45: bipush 0
      // 46: istore 13
      // 48: iload 13
      // 4a: iload 12
      // 4c: if_icmpge ab
      // 4f: aload 11
      // 51: iload 13
      // 53: aaload
      // 54: astore 14
      // 56: aload 14
      // 58: ifnull a5
      // 5b: aload 14
      // 5d: invokevirtual java/lang/Enum.ordinal ()I
      // 60: aload 0
      // 61: invokevirtual wtf/opal/client/screen/click/dropdown/panel/property/impl/ModePropertyComponent.getProperty ()Lwtf/opal/client/feature/module/property/Property;
      // 64: checkcast wtf/opal/client/feature/module/property/impl/mode/ModeProperty
      // 67: invokevirtual wtf/opal/client/feature/module/property/impl/mode/ModeProperty.getValue ()Ljava/lang/Object;
      // 6a: checkcast java/lang/Enum
      // 6d: invokevirtual java/lang/Enum.ordinal ()I
      // 70: if_icmpne 76
      // 73: goto a5
      // 76: fload 7
      // 78: fload 8
      // 7a: ldc 13.0
      // 7c: fadd
      // 7d: iload 10
      // 7f: i2f
      // 80: fadd
      // 81: fload 9
      // 83: ldc 13.0
      // 85: dload 1
      // 86: dload 3
      // 87: invokestatic wtf/opal/utility/misc/HoverUtility.isHovering (FFFFDD)Z
      // 8a: ifeq a2
      // 8d: aload 0
      // 8e: invokevirtual wtf/opal/client/screen/click/dropdown/panel/property/impl/ModePropertyComponent.getProperty ()Lwtf/opal/client/feature/module/property/Property;
      // 91: checkcast wtf/opal/client/feature/module/property/impl/mode/ModeProperty
      // 94: aload 14
      // 96: invokevirtual java/lang/Enum.ordinal ()I
      // 99: invokevirtual wtf/opal/client/feature/module/property/impl/mode/ModeProperty.setValueOrdinal (I)V
      // 9c: aload 0
      // 9d: bipush 0
      // 9e: putfield wtf/opal/client/screen/click/dropdown/panel/property/impl/ModePropertyComponent.expanded Z
      // a1: return
      // a2: iinc 10 13
      // a5: iinc 13 1
      // a8: goto 48
      // ab: aload 0
      // ac: getfield wtf/opal/client/screen/click/dropdown/panel/property/impl/ModePropertyComponent.x F
      // af: aload 0
      // b0: getfield wtf/opal/client/screen/click/dropdown/panel/property/impl/ModePropertyComponent.y F
      // b3: aload 0
      // b4: getfield wtf/opal/client/screen/click/dropdown/panel/property/impl/ModePropertyComponent.width F
      // b7: ldc 32.0
      // b9: dload 1
      // ba: dload 3
      // bb: invokestatic wtf/opal/utility/misc/HoverUtility.isHovering (FFFFDD)Z
      // be: ifeq d8
      // c1: iload 5
      // c3: bipush 1
      // c4: if_icmpne d8
      // c7: aload 0
      // c8: aload 0
      // c9: getfield wtf/opal/client/screen/click/dropdown/panel/property/impl/ModePropertyComponent.expanded Z
      // cc: ifne d3
      // cf: bipush 1
      // d0: goto d4
      // d3: bipush 0
      // d4: putfield wtf/opal/client/screen/click/dropdown/panel/property/impl/ModePropertyComponent.expanded Z
      // d7: return
      // d8: aload 0
      // d9: getfield wtf/opal/client/screen/click/dropdown/panel/property/impl/ModePropertyComponent.x F
      // dc: aload 0
      // dd: getfield wtf/opal/client/screen/click/dropdown/panel/property/impl/ModePropertyComponent.y F
      // e0: aload 0
      // e1: getfield wtf/opal/client/screen/click/dropdown/panel/property/impl/ModePropertyComponent.width F
      // e4: ldc 32.0
      // e6: dload 1
      // e7: dload 3
      // e8: invokestatic wtf/opal/utility/misc/HoverUtility.isHovering (FFFFDD)Z
      // eb: ifeq fe
      // ee: iload 5
      // f0: ifne fe
      // f3: aload 0
      // f4: invokevirtual wtf/opal/client/screen/click/dropdown/panel/property/impl/ModePropertyComponent.getProperty ()Lwtf/opal/client/feature/module/property/Property;
      // f7: checkcast wtf/opal/client/feature/module/property/impl/mode/ModeProperty
      // fa: bipush 1
      // fb: invokevirtual wtf/opal/client/feature/module/property/impl/mode/ModeProperty.cycle (Z)V
      // fe: return
   }
}
