#include "ChatUtils.h"

#include "Mod/Test.h"
#include "Datas/UserDatas.h"

void Utils::Chat::display(std::string msg, Type type, PrefixType prefixtype) {
	auto clientinstance = Client::clientinstance;
	if (!clientinstance) return;

	auto localplayer = clientinstance->getLocalPlayer();
	if (!localplayer) return;

	std::string prefix = "";

	switch (prefixtype) {
	case PrefixType::VALKYRIE:
		prefix = reinterpret_cast<const char*>(_(u8"§c")) + Client::clientName;
		break;
	case PrefixType::IRC:
		prefix = reinterpret_cast<const char*>(_(u8"§7IRC"));
		break;
	}

	switch (type) {
	case Type::NONE:
		localplayer->displayClientMessage(msg);
		break;
	case Type::NORMAL:
		localplayer->displayClientMessage(reinterpret_cast<const char*>(_(u8"§l§8")) + prefix + reinterpret_cast<const char*>(_(u8" »§r ")) + msg);
		break;
	case Type::GREEN:
		localplayer->displayClientMessage(reinterpret_cast<const char*>(_(u8"§l§8")) + prefix + reinterpret_cast<const char*>(_(u8" »§r§a ")) + msg);
		break;
	case Type::RED:
		localplayer->displayClientMessage(reinterpret_cast<const char*>(_(u8"§l§8")) + prefix + reinterpret_cast<const char*>(_(u8" »§r§c ")) + msg);
		break;
	}
}

void Utils::Chat::display_(std::string msg, Type type, PrefixType prefixtype) {
	auto testMod = Client::findMod<Test>(_("Test"));

	if (Datas::User::role == Datas::User::Role::Developer) {
		if (testMod && testMod->enabled)
			display(msg, type, prefixtype);
	}
}
