package net.minecraft.client.gui.spectator.categories;

import com.google.common.collect.ComparisonChain;
import net.minecraft.client.gui.GuiComponent;
import net.minecraft.client.gui.components.spectator.SpectatorGui;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.gui.spectator.SpectatorMenu;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.network.chat.Component;
import java.util.Iterator;
import net.minecraft.client.gui.spectator.PlayerMenuItem;
import net.minecraft.world.level.GameType;
import com.google.common.collect.Lists;
import java.util.Collection;
import net.minecraft.client.Minecraft;
import java.util.List;
import net.minecraft.client.multiplayer.PlayerInfo;
import com.google.common.collect.Ordering;
import net.minecraft.client.gui.spectator.SpectatorMenuItem;
import net.minecraft.client.gui.spectator.SpectatorMenuCategory;

public class TeleportToPlayerMenuCategory implements SpectatorMenuCategory, SpectatorMenuItem {
    private static final Ordering<PlayerInfo> PROFILE_ORDER;
    private final List<SpectatorMenuItem> items;
    
    public TeleportToPlayerMenuCategory() {
        this(TeleportToPlayerMenuCategory.PROFILE_ORDER.<PlayerInfo>sortedCopy(Minecraft.getInstance().getConnection().getOnlinePlayers()));
    }
    
    public TeleportToPlayerMenuCategory(final Collection<PlayerInfo> collection) {
        this.items = Lists.newArrayList();
        for (final PlayerInfo dyq4 : TeleportToPlayerMenuCategory.PROFILE_ORDER.<PlayerInfo>sortedCopy(collection)) {
            if (dyq4.getGameMode() != GameType.SPECTATOR) {
                this.items.add(new PlayerMenuItem(dyq4.getProfile()));
            }
        }
    }
    
    @Override
    public List<SpectatorMenuItem> getItems() {
        return this.items;
    }
    
    @Override
    public Component getPrompt() {
        return new TranslatableComponent("spectatorMenu.teleport.prompt");
    }
    
    @Override
    public void selectItem(final SpectatorMenu duj) {
        duj.selectCategory(this);
    }
    
    @Override
    public Component getName() {
        return new TranslatableComponent("spectatorMenu.teleport");
    }
    
    @Override
    public void renderIcon(final PoseStack dhl, final float float2, final int integer) {
        Minecraft.getInstance().getTextureManager().bind(SpectatorGui.SPECTATOR_LOCATION);
        GuiComponent.blit(dhl, 0, 0, 0.0f, 0.0f, 16, 16, 256, 256);
    }
    
    @Override
    public boolean isEnabled() {
        return !this.items.isEmpty();
    }
    
    static {
        PROFILE_ORDER = Ordering.<PlayerInfo>from((dyq1, dyq2) -> ComparisonChain.start().compare(dyq1.getProfile().getId(), dyq2.getProfile().getId()).result());
    }
}
