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 CleanerCommand extends Command {

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

   @Override
   public void runCommand(String[] parameters) {
      if (parameters.length == 0) {
         PlayerManager.screenToOpen = new WindowsScreen(new ItemSelectWindow(CrucifixBeta.CLEANER));
      } else {
         String var2 = parameters[0];
         switch (var2) {
            case "reset":
               CrucifixBeta.CLEANER.clear();
               CrucifixBeta.CLEANER.add(Items.NETHERITE_SWORD.getTranslationKey());
               CrucifixBeta.CLEANER.add(Items.NETHERITE_PICKAXE.getTranslationKey());
               CrucifixBeta.CLEANER.add(Items.NETHERITE_HELMET.getTranslationKey());
               CrucifixBeta.CLEANER.add(Items.NETHERITE_CHESTPLATE.getTranslationKey());
               CrucifixBeta.CLEANER.add(Items.NETHERITE_LEGGINGS.getTranslationKey());
               CrucifixBeta.CLEANER.add(Items.NETHERITE_BOOTS.getTranslationKey());
               CrucifixBeta.CLEANER.add(Items.OBSIDIAN.getTranslationKey());
               CrucifixBeta.CLEANER.add(Items.ENDER_CHEST.getTranslationKey());
               CrucifixBeta.CLEANER.add(Items.ENDER_PEARL.getTranslationKey());
               CrucifixBeta.CLEANER.add(Items.ENCHANTED_GOLDEN_APPLE.getTranslationKey());
               CrucifixBeta.CLEANER.add(Items.EXPERIENCE_BOTTLE.getTranslationKey());
               CrucifixBeta.CLEANER.add(Items.COBWEB.getTranslationKey());
               CrucifixBeta.CLEANER.add(Items.POTION.getTranslationKey());
               CrucifixBeta.CLEANER.add(Items.SPLASH_POTION.getTranslationKey());
               CrucifixBeta.CLEANER.add(Items.TOTEM_OF_UNDYING.getTranslationKey());
               CrucifixBeta.CLEANER.add(Items.END_CRYSTAL.getTranslationKey());
               CrucifixBeta.CLEANER.add(Items.ELYTRA.getTranslationKey());
               CrucifixBeta.CLEANER.add(Items.FLINT_AND_STEEL.getTranslationKey());
               CrucifixBeta.CLEANER.add(Items.PISTON.getTranslationKey());
               CrucifixBeta.CLEANER.add(Items.STICKY_PISTON.getTranslationKey());
               CrucifixBeta.CLEANER.add(Items.REDSTONE_BLOCK.getTranslationKey());
               CrucifixBeta.CLEANER.add(Items.GLOWSTONE.getTranslationKey());
               CrucifixBeta.CLEANER.add(Items.RESPAWN_ANCHOR.getTranslationKey());
               CrucifixBeta.CLEANER.add(Items.ANVIL.getTranslationKey());
               this.sendChatMessage("\u00a7fItems list got reset");
               return;
            case "clear":
               CrucifixBeta.CLEANER.getList().clear();
               this.sendChatMessage("\u00a7fItems list got clear");
               return;
            case "list":
               if (CrucifixBeta.CLEANER.getList().isEmpty()) {
                  this.sendChatMessage("\u00a7fItems list is empty");
                  return;
               }

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

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

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

               this.sendUsage();
               return;
            default:
               if (parameters.length == 1) {
                  this.sendChatMessage(
                     "§f" + parameters[0] + (CrucifixBeta.CLEANER.inList(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() + "cleaner") || 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;
      }
   }
}
