package dev.crucifixbeta.mod.commands.impl;

import dev.crucifixbeta.CrucifixBeta;
import dev.crucifixbeta.mod.commands.Command;
import dev.crucifixbeta.mod.modules.impl.misc.AddFriend;
import java.util.ArrayList;
import java.util.List;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;

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

   public FriendCommand() {
      super("friend", "[name/reset/list] | [add/remove] [name]");
   }

   @Override
   public void runCommand(String[] parameters) {
      if (parameters.length == 0) {
         this.sendUsage();
      } else {
         String var2 = parameters[0];
         switch (var2) {
            case "reset":
               CrucifixBeta.FRIEND.friendList.clear();
               this.sendChatMessage("\u00a7fFriends list got reset");
               return;
            case "list":
               if (CrucifixBeta.FRIEND.friendList.isEmpty()) {
                  this.sendChatMessage("\u00a7fFriends list is empty");
                  return;
               } else {
                  StringBuilder var10 = new StringBuilder();
                  int var5 = 0;
                  boolean var6 = true;
                  boolean var7 = true;

                  for (String var9 : CrucifixBeta.FRIEND.friendList) {
                     if (!var6) {
                        var10.append(", ");
                     }

                     var10.append(var9);
                     var6 = false;
                     if (++var5 > 3) {
                        this.sendChatMessage((var7 ? "\u00a7eFriends \u00a7a" : "\u00a7a") + var10);
                        var10 = new StringBuilder();
                        var7 = false;
                        var6 = true;
                        var5 = 0;
                     }
                  }

                  if (var6) {
                     this.sendChatMessage("§a" + var10);
                  }

                  return;
               }
            case "add":
               if (parameters.length == 2) {
                  boolean var4 = CrucifixBeta.FRIEND.isFriend(parameters[1]);
                  CrucifixBeta.FRIEND.add(parameters[1]);
                  this.sendChatMessage(
                     "§f" + parameters[1] + (CrucifixBeta.FRIEND.isFriend(parameters[1]) ? " \u00a7ahas been friended" : " \u00a7chas been unfriended")
                  );
                  if (!var4 && CrucifixBeta.FRIEND.isFriend(parameters[1])) {
                     AddFriend.notifyFriendAdded(parameters[1]);
                  }

                  return;
               }

               this.sendUsage();
               return;
            case "remove":
            case "del":
               if (parameters.length == 2) {
                  CrucifixBeta.FRIEND.remove(parameters[1]);
                  this.sendChatMessage(
                     "§f" + parameters[1] + (CrucifixBeta.FRIEND.isFriend(parameters[1]) ? " \u00a7ahas been friended" : " \u00a7chas been unfriended")
                  );
                  return;
               }

               this.sendUsage();
               return;
            default:
               if (parameters.length == 1) {
                  this.sendChatMessage(
                     "§f" + parameters[0] + (CrucifixBeta.FRIEND.isFriend(parameters[0]) ? " \u00a7ais friended" : " \u00a7cisn't friended")
                  );
               } 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")) {
            if (var3.equalsIgnoreCase(CrucifixBeta.getPrefix() + "friend") || 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;
      }
   }
}
