/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  net.minecraft.class_124
 *  net.minecraft.class_1934
 *  net.minecraft.class_2561
 *  net.minecraft.class_5250
 *  net.minecraft.class_5251
 *  net.minecraft.class_640
 */
package meteordevelopment.meteorclient.systems.modules.render;

import meteordevelopment.meteorclient.settings.BoolSetting;
import meteordevelopment.meteorclient.settings.ColorSetting;
import meteordevelopment.meteorclient.settings.IntSetting;
import meteordevelopment.meteorclient.settings.Setting;
import meteordevelopment.meteorclient.settings.SettingGroup;
import meteordevelopment.meteorclient.systems.config.Config;
import meteordevelopment.meteorclient.systems.friends.Friend;
import meteordevelopment.meteorclient.systems.friends.Friends;
import meteordevelopment.meteorclient.systems.modules.Categories;
import meteordevelopment.meteorclient.systems.modules.Module;
import meteordevelopment.meteorclient.utils.render.color.Color;
import meteordevelopment.meteorclient.utils.render.color.SettingColor;
import net.minecraft.class_124;
import net.minecraft.class_1934;
import net.minecraft.class_2561;
import net.minecraft.class_5250;
import net.minecraft.class_5251;
import net.minecraft.class_640;

public class BetterTab
extends Module {
    private final SettingGroup sgGeneral;
    public final Setting<Integer> tabSize;
    public final Setting<Integer> tabHeight;
    private final Setting<Boolean> self;
    private final Setting<SettingColor> selfColor;
    private final Setting<Boolean> friends;
    public final Setting<Boolean> accurateLatency;
    private final Setting<Boolean> gamemode;

    public BetterTab() {
        super(Categories.Render, "better-tab", "Various improvements to the tab list.");
        this.sgGeneral = this.settings.getDefaultGroup();
        this.tabSize = this.sgGeneral.add(((IntSetting.Builder)((IntSetting.Builder)((IntSetting.Builder)new IntSetting.Builder().name("tablist-size")).description("How many players in total to display in the tablist.")).defaultValue(100)).min(1).sliderRange(1, 1000).build());
        this.tabHeight = this.sgGeneral.add(((IntSetting.Builder)((IntSetting.Builder)((IntSetting.Builder)new IntSetting.Builder().name("column-height")).description("How many players to display in each column.")).defaultValue(20)).min(1).sliderRange(1, 1000).build());
        this.self = this.sgGeneral.add(((BoolSetting.Builder)((BoolSetting.Builder)((BoolSetting.Builder)new BoolSetting.Builder().name("highlight-self")).description("Highlights yourself in the tablist.")).defaultValue(true)).build());
        this.selfColor = this.sgGeneral.add(((ColorSetting.Builder)((ColorSetting.Builder)((ColorSetting.Builder)new ColorSetting.Builder().name("self-color")).description("The color to highlight your name with.")).defaultValue(new SettingColor(250, 130, 30)).visible(this.self::get)).build());
        this.friends = this.sgGeneral.add(((BoolSetting.Builder)((BoolSetting.Builder)((BoolSetting.Builder)new BoolSetting.Builder().name("highlight-friends")).description("Highlights friends in the tablist.")).defaultValue(true)).build());
        this.accurateLatency = this.sgGeneral.add(((BoolSetting.Builder)((BoolSetting.Builder)((BoolSetting.Builder)new BoolSetting.Builder().name("accurate-latency")).description("Shows latency as a number in the tablist.")).defaultValue(true)).build());
        this.gamemode = this.sgGeneral.add(((BoolSetting.Builder)((BoolSetting.Builder)((BoolSetting.Builder)new BoolSetting.Builder().name("gamemode")).description("Display gamemode next to the nick.")).defaultValue(false)).build());
    }

    public class_2561 getPlayerName(class_640 playerListEntry) {
        Friend friend;
        Color color = null;
        class_2561 name = playerListEntry.method_2971();
        if (name == null) {
            name = class_2561.method_43470((String)playerListEntry.method_2966().name());
        }
        if (playerListEntry.method_2966().id().toString().equals(this.mc.field_1724.method_7334().id().toString()) && this.self.get().booleanValue()) {
            color = this.selfColor.get();
        } else if (this.friends.get().booleanValue() && Friends.get().isFriend(playerListEntry) && (friend = Friends.get().get(playerListEntry)) != null) {
            color = Config.get().friendColor.get();
        }
        if (color != null) {
            String nameString = name.getString();
            for (class_124 format : class_124.values()) {
                if (!format.method_543()) continue;
                nameString = nameString.replace(format.toString(), "");
            }
            name = class_2561.method_43470((String)nameString).method_10862(name.method_10866().method_27703(class_5251.method_27717((int)color.getPacked())));
        }
        if (this.gamemode.get().booleanValue()) {
            class_1934 gm = playerListEntry.method_2958();
            String gmText = "?";
            if (gm != null) {
                gmText = switch (gm) {
                    default -> throw new MatchException(null, null);
                    case class_1934.field_9219 -> "Sp";
                    case class_1934.field_9215 -> "S";
                    case class_1934.field_9220 -> "C";
                    case class_1934.field_9216 -> "A";
                };
            }
            class_5250 text = class_2561.method_43470((String)"");
            text.method_10852(name);
            text.method_27693(" [" + gmText + "]");
            name = text;
        }
        return name;
    }
}

