package net.moonleay.gimble.client.util

import net.minecraft.client.MinecraftClient
import net.minecraft.client.toast.SystemToast
import net.minecraft.text.Text

object ChatUtil {
     /**
      * Note: command arg should contain "/" at the beginning.
      * */
    fun sendCommand(command: String, client: MinecraftClient, addToHistory: Boolean = true): Boolean {
        if (addToHistory) {
            client.inGameHud.chatHud.addToMessageHistory(command)
        }
        return client.player?.sendCommand(command.substring(1))?: false
    }

    fun addToChatHistory(message: String, client: MinecraftClient) {
        client.inGameHud.chatHud.addMessage(Text.of(message))
    }

    fun showToastToSelf(title: String, description: String, client: MinecraftClient) {
        val toast = SystemToast(SystemToast.Type.PERIODIC_NOTIFICATION, Text.of(title), Text.of(description))
        client.toastManager.add(toast)
    }
}
