package org.adrianvictor.lib.text;

import org.adrianvictor.lib.reflection.ImplementationRegistry;
import org.adrianvictor.lib.text.provider.TextColorProvider;

public class TextColorUtils {
    private final TextColorProvider provider;

    public TextColorUtils(ImplementationRegistry registry) {
        provider = TextColor.create(registry);
    }

    public String formatColors(String message) {
        return message.replace("&", "§");
    }

    public String ignoreColors(String message) {
        return message.replaceAll("&([0-9a-fk-or])", "");
    }

    public String rainbow(String message) {
        String[] colorNames = {"RED", "GOLD", "YELLOW", "GREEN", "AQUA", "BLUE", "LIGHT_PURPLE"};
        int colorIndex = 0;
        String coloredMessage = "";

        for (char c : message.toCharArray()) {
            String currentColor = provider.colorize(colorNames[colorIndex]);
            coloredMessage += currentColor + c;
            colorIndex++;
            if (colorIndex >= colorNames.length) {
                colorIndex = 0;
            }
        }
        return coloredMessage;
    }
}
