package eu.mhsl.minenet.minigames.message.type;

import eu.mhsl.minenet.minigames.message.Icon;
import eu.mhsl.minenet.minigames.message.TranslatableMessage;
import net.minestom.server.entity.Player;

public class ChatMessage extends TranslatableMessage {
    public ChatMessage() {
        construct(Icon.CHAT, false);
    }

    public ChatMessage(Icon icon) {
        construct(icon, false);
    }

    public ChatMessage(Icon icon, boolean preSpace) {
        construct(icon, preSpace);
    }

    private void construct(Icon icon, boolean preSpace) {
        if(preSpace) {
            super.appendStatic("  ");
            pipe();
            super.appendStatic("\n");
        }
        appendStatic(icon.getComponent());
        pipe();
    }

    @Override
    public TranslatableMessage newLine() {
        super.appendStatic("\n");
        super.appendStatic("  ");
        super.pipe();
        super.appendStatic("  ".repeat(super.indention));
        return this;
    }

    public void send(Player p) {
        p.sendMessage(build(p));
    }
}
