package mapped;

import java.awt.Component;
import java.awt.Graphics;
import java.awt.event.FocusListener;
import java.net.URL;
import java.util.Iterator;
import net.runelite.mapping.ObfuscatedName;
import net.runelite.mapping.ObfuscatedSignature;
import net.runelite.rs.api.RSCanvas;

@ObfuscatedName("ag")
public final class Canvas extends java.awt.Canvas implements RSCanvas {
   @ObfuscatedName("fk")
   @ObfuscatedSignature(
      descriptor = "Loh;"
   )
   static Archive field114;
   public static boolean shouldNotHaveFocus;
   @ObfuscatedName("at")
   Component component;

   Canvas(Component var1) {
      this.component = var1;
   }

   public final void update(Graphics var1) {
      this.component.update(var1);
   }

   public final void paint(Graphics var1) {
      this.component.paint(var1);
   }

   public void removeFocusListener(FocusListener var1) {
      super.removeFocusListener(var1);
      shouldNotHaveFocus = !this.hasFocus();
   }

   public void requestFocus() {
      if(!shouldNotHaveFocus) {
         this.requestFocusInWindow();
      }

   }

   public void setSize(int var1, int var2) {
      if(SpriteMask.client.isStretchedEnabled()) {
         super.setSize(SpriteMask.client.getStretchedDimensions().width, SpriteMask.client.getStretchedDimensions().height);
      } else {
         super.setSize(var1, var2);
      }

   }

   public void setLocation(int var1, int var2) {
      if(SpriteMask.client.isStretchedEnabled()) {
         super.setLocation((this.getParent().getWidth() - SpriteMask.client.getStretchedDimensions().width) / 2, 0);
      } else {
         super.setLocation(var1, var2);
      }

   }

   @ObfuscatedName("at")
   @ObfuscatedSignature(
      descriptor = "(II)Lhd;",
      garbageValue = "-1413317241"
   )
   public static FloorOverlayDefinition method333(int var0) {
      FloorOverlayDefinition var1 = (FloorOverlayDefinition)FloorOverlayDefinition.FloorOverlayDefinition_cached.get((long)var0);
      if(var1 != null) {
         return var1;
      } else {
         byte[] var2 = FloorOverlayDefinition.FloorOverlayDefinition_archive.takeFile_base(4, var0);
         var1 = new FloorOverlayDefinition();
         if(var2 != null) {
            var1.method4018(new Buffer(var2), var0);
         }

         var1.postDecode_base();
         FloorOverlayDefinition.FloorOverlayDefinition_cached.put(var1, (long)var0);
         return var1;
      }
   }

   @ObfuscatedName("ah")
   @ObfuscatedSignature(
      descriptor = "(II)Lha;",
      garbageValue = "-2114676262"
   )
   public static SpotAnimationDefinition method324(int var0) {
      SpotAnimationDefinition var1 = (SpotAnimationDefinition)SpotAnimationDefinition.SpotAnimationDefinition_cached.get((long)var0);
      if(var1 != null) {
         return var1;
      } else {
         byte[] var2 = SpotAnimationDefinition.SpotAnimationDefinition_archive.takeFile_base(13, var0);
         var1 = new SpotAnimationDefinition();
         var1.id = var0;
         if(var2 != null) {
            var1.method3765(new Buffer(var2));
         }

         SpotAnimationDefinition.SpotAnimationDefinition_cached.put(var1, (long)var0);
         return var1;
      }
   }

   @ObfuscatedName("ar")
   @ObfuscatedSignature(
      descriptor = "(Ljava/lang/String;ILjava/lang/String;B)Z",
      garbageValue = "50"
   )
   static boolean method325_base(String var0, int var1, String var2) {
      boolean var10000;
      if(var1 == 0) {
         try {
            if(!class31.field157.startsWith("win")) {
               throw new Exception();
            }

            if(!var0.startsWith("http://") && !var0.startsWith("https://")) {
               throw new Exception();
            }

            String var10 = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789?&=,.%+-_#:/*";

            for(int var4 = 0; var4 < var0.length(); ++var4) {
               if(var10.indexOf(var0.charAt(var4)) == -1) {
                  throw new Exception();
               }
            }

            Runtime.getRuntime().exec("cmd /c start \"j\" \"" + var0 + "\"");
            var10000 = true;
         } catch (Throwable var9) {
            return false;
         }

         return var10000;
      } else if(var1 == 1) {
         try {
            Object var3 = class26.method396_base(class31.field158, var2, new Object[]{(new URL(class31.field158.getCodeBase(), var0)).toString()});
            var10000 = var3 != null;
         } catch (Throwable var5) {
            return false;
         }

         return var10000;
      } else if(var1 == 2) {
         try {
            class31.field158.getAppletContext().showDocument(new URL(class31.field158.getCodeBase(), var0), "_blank");
            var10000 = true;
         } catch (Exception var6) {
            return false;
         }

         return var10000;
      } else if(var1 == 3) {
         try {
            class26.method394_base(class31.field158, "loggedout");
         } catch (Throwable var8) {
            ;
         }

         try {
            class31.field158.getAppletContext().showDocument(new URL(class31.field158.getCodeBase(), var0), "_top");
            var10000 = true;
         } catch (Exception var7) {
            return false;
         }

         return var10000;
      } else {
         throw new IllegalArgumentException();
      }
   }

   @ObfuscatedName("ab")
   @ObfuscatedSignature(
      descriptor = "(FFFFLfm;I)V",
      garbageValue = "-2092193307"
   )
   static void method334_base(float var0, float var1, float var2, float var3, class131 var4) {
      float var5 = var1 - var0;
      float var6 = var2 - var1;
      float var7 = var3 - var2;
      float var8 = var6 - var5;
      var4.field1528 = var7 - var6 - var8;
      var4.field1540 = var8 + var8 + var8;
      var4.field1539 = var5 + var5 + var5;
      var4.field1546 = var0;
   }

   @ObfuscatedName("au")
   @ObfuscatedSignature(
      descriptor = "(B)V",
      garbageValue = "6"
   )
   static void method329_base() {
      Script.Script_cached.clear_base();
   }

   @ObfuscatedName("aa")
   @ObfuscatedSignature(
      descriptor = "(B)V",
      garbageValue = "-18"
   )
   static void method332_base() {
      Iterator var0 = Messages.Messages_hashTable.iterator();

      while(var0.hasNext()) {
         Message var1 = (Message)var0.next();
         var1.clearIsFromIgnored_base();
      }

   }

   @ObfuscatedName("js")
   @ObfuscatedSignature(
      descriptor = "(Ldf;II)V",
      garbageValue = "-360697736"
   )
   static final void method331(Actor var0, int var1) {
      class514.worldToScreen_base(var0.x, var0.y, var1);
   }

   @ObfuscatedName("ln")
   @ObfuscatedSignature(
      descriptor = "(IIIIIIIII)V",
      garbageValue = "1842329520"
   )
   static final void drawWidgets_base(int var0, int var1, int var2, int var3, int var4, int var5, int var6, int var7) {
      if(HealthBarDefinition.widgetDefinition.loadInterface_base(var0)) {
         UserComparator10.field1453 = null;
         SoundSystem.method866(HealthBarDefinition.widgetDefinition.Widget_interfaceComponents[var0], -1, var1, var2, var3, var4, var5, var6, var7);
         if(UserComparator10.field1453 != null) {
            SoundSystem.method866(UserComparator10.field1453, -1412584499, var1, var2, var3, var4, ParamComposition.field2040, PendingSpawn.field1167, var7);
            UserComparator10.field1453 = null;
         }

      } else {
         if(var7 != -1) {
            Client.validRootWidgets[var7] = true;
         } else {
            for(int var8 = 0; var8 < 100; ++var8) {
               Client.validRootWidgets[var8] = true;
            }
         }

      }
   }
}
