package dev.crucifixbeta.mod.commands.impl;

import dev.crucifixbeta.CrucifixBeta;
import dev.crucifixbeta.core.impl.PlayerManager;
import dev.crucifixbeta.mod.commands.Command;
import dev.crucifixbeta.mod.gui.windows.WindowsScreen;
import dev.crucifixbeta.mod.gui.windows.impl.ItemSelectWindow;
import java.util.ArrayList;
import java.util.List;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.item.Items;

@Environment(EnvType.CLIENT)
public class TradeCommand extends Command {

   public TradeCommand() {
      super("trade", "[\"\"/name/reset/clear/list] | [add/remove] [name]");
   }

   @Override
   public void runCommand(String[] parameters) {
      if (parameters.length == 0) {
         PlayerManager.screenToOpen = new WindowsScreen(new ItemSelectWindow(CrucifixBeta.TRADE));
      } else {
         String var2 = parameters[0];
         switch (var2) {
            case "reset":
               CrucifixBeta.TRADE.clear();
               CrucifixBeta.TRADE.add(Items.ENCHANTED_BOOK.getTranslationKey());
               CrucifixBeta.TRADE.add(Items.DIAMOND_BLOCK.getTranslationKey());
               this.sendChatMessage("\u00a7fItems list got reset");
               return;
            case "clear":
               CrucifixBeta.TRADE.clear();
               this.sendChatMessage("\u00a7fItems list got clear");
               return;
            case "list":
               if (CrucifixBeta.TRADE.getList().isEmpty()) {
                  this.sendChatMessage("\u00a7fItems list is empty");
                  return;
               }

               for (String var5 : CrucifixBeta.TRADE.getList()) {
                  this.sendChatMessage("§a" + var5);
               }

               return;
            case "add":
               if (parameters.length == 2) {
                  CrucifixBeta.TRADE.add(parameters[1]);
                  this.sendChatMessage(
                     "§f" + parameters[1] + (CrucifixBeta.TRADE.inWhitelist(parameters[1]) ? " \u00a7ahas been added" : " \u00a7chas been removed")
                  );
                  return;
               }

               this.sendUsage();
               return;
            case "remove":
               if (parameters.length == 2) {
                  CrucifixBeta.TRADE.remove(parameters[1]);
                  this.sendChatMessage(
                     "§f" + parameters[1] + (CrucifixBeta.TRADE.inWhitelist(parameters[1]) ? " \u00a7ahas been added" : " \u00a7chas been removed")
                  );
                  return;
               }

               this.sendUsage();
               return;
            default:
               if (parameters.length == 1) {
                  this.sendChatMessage(
                     "§f" + parameters[0] + (CrucifixBeta.TRADE.inWhitelist(parameters[0]) ? " \u00a7ais in whitelist" : " \u00a7cisn't in whitelist")
                  );
               } else {
                  this.sendUsage();
               }
         }
      }
   }

   @Override
   public String[] getAutocorrect(int count, List<String> seperated) {
      if (count != 1) {
         return null;
      } else {
         String var3 = ((String)seperated.getLast()).toLowerCase();
         ArrayList<String> var4 = new ArrayList<>();

         for (String var7 : List.of(
            "add", "remove", "list", "reset", "clear"
         )) {
            if (var3.equalsIgnoreCase(CrucifixBeta.getPrefix() + "trade") || var7.toLowerCase().startsWith(var3)) {
               var4.add(var7);
            }
         }

         int var11 = var4.size();
         String[] var12 = new String[var11];
         int var8 = 0;

         for (String var10 : var4) {
            var12[var8++] = var10;
         }

         return var12;
      }
   }
}
