package net.minecraft.client.gui.components;

import com.google.common.collect.Lists;
import net.minecraft.network.chat.Style;
import java.util.Optional;
import net.minecraft.client.ComponentCollector;
import java.util.List;
import net.minecraft.client.gui.Font;
import net.minecraft.ChatFormatting;
import net.minecraft.client.Minecraft;
import net.minecraft.network.chat.FormattedText;

public class ComponentRenderUtils {
    private static final FormattedText INDENT;
    
    private static String stripColor(final String string) {
        return Minecraft.getInstance().options.chatColors ? string : ChatFormatting.stripFormatting(string);
    }
    
    public static List<FormattedText> wrapComponents(final FormattedText mu, final int integer, final Font dmt) {
        final ComponentCollector dlm4 = new ComponentCollector();
        mu.visit((nb, string) -> {
            dlm4.append(FormattedText.of(stripColor(string), nb));
            return Optional.empty();
        }, Style.EMPTY);
        final List<FormattedText> list5 = dmt.getSplitter().splitLines(dlm4.getResultOrEmpty(), integer, Style.EMPTY, ComponentRenderUtils.INDENT);
        if (list5.isEmpty()) {
            return Lists.<FormattedText>newArrayList(FormattedText.EMPTY);
        }
        return list5;
    }
    
    static {
        INDENT = FormattedText.of(" ");
    }
}
