package mapped;

import net.runelite.api.MenuEntry;
import net.runelite.api.events.MenuOptionClicked;
import net.runelite.mapping.ObfuscatedGetter;
import net.runelite.mapping.ObfuscatedName;
import net.runelite.mapping.ObfuscatedSignature;
import net.runelite.rs.api.RSRuneLiteMenuEntry;

@ObfuscatedName("px")
public class class407 {
   @ObfuscatedName("at")
   @ObfuscatedGetter(
      intValue = 719897105
   )
   int field4506;

   @ObfuscatedSignature(
      descriptor = "(IZ)V",
      garbageValue = "1"
   )
   class407(int var1, boolean var2) {
      this.field4506 = var1;
   }

   @ObfuscatedName("at")
   @ObfuscatedSignature(
      descriptor = "(S)I",
      garbageValue = "6521"
   )
   public int method7655_base() {
      return this.field4506;
   }

   @ObfuscatedName("kx")
   @ObfuscatedSignature(
      descriptor = "(IIIIILjava/lang/String;Ljava/lang/String;IIB)V",
      garbageValue = "34"
   )
   static final void menuAction_base(int var0, int var1, int var2, int var3, int var4, String var5, String var6, int var7, int var8) {
      RSRuneLiteMenuEntry var9 = null;

      for(int var10 = SpriteMask.client.getMenuOptionCount() - 1; var10 >= 0; --var10) {
         if(SpriteMask.client.getMenuOpcodes()[var10] == var2 && SpriteMask.client.getMenuIdentifiers()[var10] == var3 && SpriteMask.client.getMenuArguments1()[var10] == var0 && SpriteMask.client.getMenuArguments2()[var10] == var1 && SpriteMask.client.getMenuItemIds()[var10] == var4 && var5.equals(SpriteMask.client.getMenuOptions()[var10]) && var6.equals(SpriteMask.client.getMenuTargets()[var10])) {
            var9 = Client.rl$menuEntries[var10];
            break;
         }
      }

      boolean var17 = false;
      if(SpriteMask.client.getTempMenuAction() != null) {
         var17 = SpriteMask.client.getTempMenuAction().getOpcode() == var2 && SpriteMask.client.getTempMenuAction().getIdentifier() == var3 && SpriteMask.client.getTempMenuAction().getOption().equals(var5) && SpriteMask.client.getTempMenuAction().getTarget().equals(var6) && SpriteMask.client.getTempMenuAction().getParam0() == var0 && SpriteMask.client.getTempMenuAction().getParam1() == var1 && SpriteMask.client.getTempMenuAction().getItemId() == var4;
      }

      if(var9 == null && var17) {
         int var11;
         if(SpriteMask.client.getMenuOptionCount() < 500) {
            var11 = SpriteMask.client.getMenuOptionCount();
            SpriteMask.client.setMenuOptionCount(SpriteMask.client.getMenuOptionCount() + 1);
         } else {
            var11 = 0;
         }

         SpriteMask.client.getMenuOpcodes()[var11] = var2;
         SpriteMask.client.getMenuIdentifiers()[var11] = var3;
         SpriteMask.client.getMenuOptions()[var11] = var5;
         SpriteMask.client.getMenuTargets()[var11] = var6;
         SpriteMask.client.getMenuArguments1()[var11] = var0;
         SpriteMask.client.getMenuArguments2()[var11] = var1;
         SpriteMask.client.getMenuItemIds()[var11] = var4;
         SpriteMask.client.getMenuForceLeftClick()[var11] = false;
         var9 = Client.rl$menuEntries[var11];
         if(var9 == null) {
            var9 = Client.rl$menuEntries[var11] = Client.newRuneliteMenuEntry(var11);
         }
      }

      MenuOptionClicked var14;
      if(var9 == null) {
         MenuEntry var12 = SpriteMask.client.createMenuEntry(var5, var6, var3, var2, var0, var1, var4, false);
         var14 = new MenuOptionClicked(var12);
         if(var7 != -1 || var8 != -1) {
            SpriteMask.client.getLogger().warn("Unable to find clicked menu op {} targ {} action {} id {} p0 {} p1 {} item {}", new Object[]{var5, var6, Integer.valueOf(var2), Integer.valueOf(var3), Integer.valueOf(var0), Integer.valueOf(var1), Integer.valueOf(var4)});
         }
      } else {
         SpriteMask.client.getLogger().trace("Menu click op {} targ {} action {} id {} p0 {} p1 {}", new Object[]{var5, var6, Integer.valueOf(var2), Integer.valueOf(var3), Integer.valueOf(var0), Integer.valueOf(var1)});
         var14 = new MenuOptionClicked(var9);
         SpriteMask.client.getCallbacks().post(var14);
         int var15 = Client.getItemId(var14.getId(), var14.getMenuAction().getId(), var14.getParam0(), var14.getParam1(), var14.getItemId());
         var14.setItemId(var15);
         if(var9.getConsumer() != null) {
            try {
               var9.getConsumer().accept(var9);
            } catch (Exception var16) {
               SpriteMask.client.getLogger().warn("exception in menu callback", var16);
            }
         }

         if(var14.isConsumed()) {
            return;
         }
      }

      boolean var18 = false;
      if(var2 >= 2000) {
         var18 = true;
         var2 -= 2000;
      }

      if(Client.printMenuActions) {
         SpriteMask.client.getLogger().info("|MenuAction|: MenuOption={} MenuTarget={} Id={} Opcode={}/{} Param0={} Param1={} CanvasX={} CanvasY={} ItemId={}", new Object[]{var14.getMenuOption(), var14.getMenuTarget(), Integer.valueOf(var14.getId()), var14.getMenuAction(), Integer.valueOf(var2 + (var18?2000:0)), Integer.valueOf(var14.getParam0()), Integer.valueOf(var14.getParam1()), Integer.valueOf(var7), Integer.valueOf(var8), Integer.valueOf(var14.getItemId())});
         if(var9 != null) {
            SpriteMask.client.getLogger().info("|MenuEntry|: Idx={} MenuOption={} MenuTarget={} Id={} MenuAction={} Param0={} Param1={} Consumer={} IsItemOp={} ItemOp={} ItemID={} Widget={}", new Object[]{Integer.valueOf(var9.getIdx()), var9.getOption(), var9.getTarget(), Integer.valueOf(var9.getIdentifier()), var9.getType(), Integer.valueOf(var9.getParam0()), Integer.valueOf(var9.getParam1()), var9.getConsumer(), Boolean.valueOf(var9.isItemOp()), Integer.valueOf(var9.getItemOp()), Integer.valueOf(var9.getItemId()), var9.getWidget()});
         }
      }

      Client.copy$menuAction(var14.getParam0(), var14.getParam1(), var14.getMenuAction() == net.runelite.api.MenuAction.UNKNOWN?var2:var14.getMenuAction().getId(), var14.getId(), var14.getItemId(), var14.getMenuOption(), var14.getMenuTarget(), var7, var8, (byte)34);
   }
}
