package mapped;

import java.awt.Desktop;
import java.awt.Desktop.Action;
import java.net.URI;
import net.runelite.mapping.ObfuscatedName;
import net.runelite.mapping.ObfuscatedSignature;
import net.runelite.rs.api.RSHealthBar;
import net.runelite.rs.api.RSHealthBarDefinition;
import net.runelite.rs.api.RSIterableNodeDeque;

@ObfuscatedName("de")
public class HealthBar extends Node implements RSHealthBar {
   @ObfuscatedName("as")
   @ObfuscatedSignature(
      descriptor = "Lnn;"
   )
   static Widget scriptActiveWidget;
   @ObfuscatedName("ar")
   @ObfuscatedSignature(
      descriptor = "Lgh;"
   )
   HealthBarDefinition definition;
   @ObfuscatedName("ao")
   @ObfuscatedSignature(
      descriptor = "Lpm;"
   )
   IterableNodeDeque updates;

   @ObfuscatedSignature(
      descriptor = "(Lgh;)V"
   )
   HealthBar(HealthBarDefinition var1) {
      this.updates = new IterableNodeDeque();
      this.definition = var1;
   }

   @ObfuscatedName("at")
   @ObfuscatedSignature(
      descriptor = "(IIIIB)V",
      garbageValue = "1"
   )
   void put_base(int var1, int var2, int var3, int var4) {
      HealthBarUpdate var5 = null;
      int var6 = 0;

      for(HealthBarUpdate var7 = (HealthBarUpdate)this.updates.method7290(); var7 != null; var7 = (HealthBarUpdate)this.updates.method7292()) {
         ++var6;
         if(var7.cycle == var1) {
            var7.set_base(var1, var2, var3, var4);
            return;
         }

         if(var7.cycle <= var1) {
            var5 = var7;
         }
      }

      if(var5 == null) {
         if(var6 < 4) {
            this.updates.method7288(new HealthBarUpdate(var1, var2, var3, var4));
         }

      } else {
         IterableNodeDeque.method7347(new HealthBarUpdate(var1, var2, var3, var4), var5);
         if(var6 >= 4) {
            this.updates.method7290().remove_base();
         }

      }
   }

   @ObfuscatedName("ah")
   @ObfuscatedSignature(
      descriptor = "(II)Ldv;",
      garbageValue = "478923199"
   )
   HealthBarUpdate method2648(int var1) {
      HealthBarUpdate var2 = (HealthBarUpdate)this.updates.method7290();
      if(var2 != null && var2.cycle <= var1) {
         for(HealthBarUpdate var3 = (HealthBarUpdate)this.updates.method7292(); var3 != null && var3.cycle <= var1; var3 = (HealthBarUpdate)this.updates.method7292()) {
            var2.remove_base();
            var2 = var3;
         }

         if(this.definition.int5 + var2.cycle + var2.cycleOffset > var1) {
            return var2;
         } else {
            var2.remove_base();
            return null;
         }
      } else {
         return null;
      }
   }

   @ObfuscatedName("ar")
   @ObfuscatedSignature(
      descriptor = "(I)Z",
      garbageValue = "1159323457"
   )
   boolean isEmpty_base() {
      return this.updates.method7350_base();
   }

   public RSHealthBarDefinition getDefinition() {
      return this.definition;
   }

   public RSIterableNodeDeque getUpdates() {
      return this.updates;
   }

   @ObfuscatedName("at")
   @ObfuscatedSignature(
      descriptor = "(II)I",
      garbageValue = "1558153210"
   )
   public static int getVarbit_base(int var0) {
      VarbitComposition var1 = ClientPreferences.method2644(var0);
      int var2 = var1.baseVar;
      int var3 = var1.startBit;
      int var4 = var1.endBit;
      int var5 = Varps.Varps_masks[var4 - var3];
      return Varps.Varps_main[var2] >> var3 & var5;
   }

   @ObfuscatedName("at")
   @ObfuscatedSignature(
      descriptor = "(I)[Ldm;",
      garbageValue = "-789514227"
   )
   static class89[] method2656_base() {
      return new class89[]{class89.field1075, class89.field1081, class89.field1072, class89.field1071, class89.field1077};
   }

   @ObfuscatedName("ah")
   @ObfuscatedSignature(
      descriptor = "(Ljava/lang/String;ZZI)V",
      garbageValue = "1900384662"
   )
   public static void openURL_base(String var0, boolean var1, boolean var2) {
      if(var1) {
         if(Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Action.BROWSE)) {
            try {
               Desktop.getDesktop().browse(new URI(var0));
               return;
            } catch (Exception var4) {
               ;
            }
         }

         if(class31.field157.startsWith("win")) {
            Canvas.method325_base(var0, 0, "openjs");
         } else if(class31.field157.startsWith("mac")) {
            Canvas.method325_base(var0, 1, "openjs");
         } else {
            Canvas.method325_base(var0, 2, "openjs");
         }
      } else {
         Canvas.method325_base(var0, 3, "openjs");
      }

   }
}
