package org.atmospheregames.network.util;

import org.bukkit.ChatColor;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author Zion
 * @project Network
 * @date 14/06/2024
 */
public class Style {
    public static final String BLUE = ChatColor.BLUE.toString();
    public static final String AQUA = ChatColor.AQUA.toString();
    public static final String YELLOW = ChatColor.YELLOW.toString();
    public static final String RED = ChatColor.RED.toString();
    public static final String GRAY = ChatColor.GRAY.toString();
    public static final String GOLD = ChatColor.GOLD.toString();
    public static final String GREEN = ChatColor.GREEN.toString();
    public static final String WHITE = ChatColor.WHITE.toString();
    public static final String BLACK = ChatColor.BLACK.toString();
    public static final String BOLD = ChatColor.BOLD.toString();
    public static final String ITALIC = ChatColor.ITALIC.toString();
    public static final String UNDER_LINE = ChatColor.UNDERLINE.toString();
    public static final String STRIKE_THROUGH = ChatColor.STRIKETHROUGH.toString();
    public static final String RESET = ChatColor.RESET.toString();
    public static final String MAGIC = ChatColor.MAGIC.toString();
    public static final String DBLUE = ChatColor.DARK_BLUE.toString();
    public static final String DAQUA = ChatColor.DARK_AQUA.toString();
    public static final String DGRAY = ChatColor.DARK_GRAY.toString();
    public static final String DGREEN = ChatColor.DARK_GREEN.toString();
    public static final String DPURPLE = ChatColor.DARK_PURPLE.toString();
    public static final String DRED = ChatColor.DARK_RED.toString();
    public static final String PURPLE = ChatColor.DARK_PURPLE.toString();
    public static final String PINK = ChatColor.LIGHT_PURPLE.toString();
    public static final String MENU_BAR = ChatColor.GRAY.toString() + ChatColor.STRIKETHROUGH + "------------------------";
    public static final String CHAT_BAR = ChatColor.GRAY.toString() + ChatColor.STRIKETHROUGH + "------------------------------------------------";
    public static final String SMALL_CHAT_BAR = ChatColor.GRAY.toString() + ChatColor.STRIKETHROUGH + "-----------------";
    public static final String SB_BAR = ChatColor.GRAY.toString() + ChatColor.STRIKETHROUGH + "----------------------";

    public static String translate(String input) {
        return ChatColor.translateAlternateColorCodes('&', input);
    }

    public static List<String> translate(String[] inputs) {
        List<String> toReturn = new ArrayList<>();

        Arrays.stream(inputs).forEach(string -> {
            Style.translate(string);
            toReturn.add(string);
        });

        return toReturn;
    }

    public static List<String> translate(List<String> inputs) {
        List<String> toReturn = new ArrayList<>();

        inputs.forEach(string -> {
            Style.translate(string);
            toReturn.add(string);
        });

        return toReturn;
    }

    public static String strip(String input) {
        return ChatColor.stripColor(input);
    }

    public static List<String> strip(String[] inputs) {
        List<String> toReturn = new ArrayList<>();

        Arrays.stream(inputs).forEach(string -> {
            Style.strip(string);
            toReturn.add(string);
        });

        return toReturn;
    }

    public static String tps(Double input) {
        double tpsValue = Math.min(20,  Math.round(input* 10) / 10.0);
        String color;
        if (tpsValue > 19.2D) {
            color = Style.GREEN;
        } else if (tpsValue > 17.4D) {
            color = Style.YELLOW;
        } else {
            color = Style.RED;
        }

        String tps = String.valueOf(tpsValue);
        if (tps.equals("20.0")) {
            tps = "*20.0";
        }

        return color+tps;
    }

    public static List<String> strip(List<String> inputs) {
        List<String> toReturn = new ArrayList<>();

        inputs.forEach(string -> {
            Style.strip(string);
            toReturn.add(string);
        });

        return toReturn;
    }
}
