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() {
        this.construct(Icon.CHAT, false);
    }

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

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

    private void construct(Icon icon, boolean preSpace) {
        if(preSpace) {
            super.appendStatic("  ");
            this.pipe();
            super.appendStatic("\n");
        }
        this.appendStatic(icon.getComponent());
        this.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(this.build(p));
    }
}
