#include "ClickGui.h"
#include "Client.h"
#include "Utils/ImGuiRenderUtils.h"
#include "Utils/MathUtils.h"
#include "Utils/ColorUtils.h"
#include "Utils/AudioUtils.h"

#include "Mod/Interface.h"

auto ClickGui::onImGuiRender() -> void {
	Interface* interfaceMod = Client::findMod<Interface>(_("Interface"));

	if ((enabled && !unvisible) && Client::clientinstance && Client::screenName == _("hud_screen"))
		Client::clientinstance->releaseMouse();

	static float animation = 0.f;
	animation = Utils::Math::animate((enabled && !unvisible) ? 1.f : 0.f, animation, Client::deltaTime * 10.f);

	Utils::ImGuiRender::setDrawList(ImGui::GetForegroundDrawList());

	ImVec4 windowrect = ImVec4(0, 0, Client::windowsize.x, Client::windowsize.y);
	Utils::ImGuiRender::setBlurStreangth(blurs * animation);
	Utils::ImGuiRender::fillBlurRectangle(windowrect);
	Utils::ImGuiRender::setColor(Utils::Color::getColor(3.f, 800.f, 0.1f * animation));
	Utils::ImGuiRender::setSecondColor(Utils::Color::getColor(3.f, 0.f, 0.f));
	Utils::ImGuiRender::fillGradientOpaqueRectangle(windowrect);

	auto now = Utils::Time::getMs();
	
	switch (style) {
	case 0: {
		static ImVec2 pos = ImVec2(Client::windowsize.x / 2, Client::windowsize.y / 2);

		ImVec4 rect = ImVec4(pos.x - (380.f * animation), pos.y - (275.f * animation), pos.x + (380.f * animation), pos.y + (275.f * animation));

		ImVec4 hoverrect = ImVec4(
			rect.x,
			rect.y,
			rect.x + 100.f,
			rect.y + 60.f
		);

		static bool hovering = false;
		if ((enabled && !unvisible) && Utils::ImGuiRender::isHoveringRect(hoverrect) && ImGui::IsMouseDown(0)) {
			hovering = true;
		}

		if ((enabled && !unvisible) && hovering) {
			if (!ImGui::IsMouseDown(0))
				hovering = false;

			pos = ImVec2(Client::mousex + 340.f, Client::mousey + 235.f);
		}


		static float heightMods = 0.f;

		ImVec4 rightrect = ImVec4(rect.x, rect.y, rect.x + (200.f * animation), rect.w);

		Utils::ImGuiRender::setRound(20.f);
		Utils::ImGuiRender::setBlurStreangth(10.f * animation);
		Utils::ImGuiRender::fillBlurRectangle(rect);
		if (theme == 0)
			Utils::ImGuiRender::setColor(ImColor(0.07f, 0.1f, 0.15f, opacity * animation));
		else if (theme == 1)
			Utils::ImGuiRender::setColor(ImColor(1.f, 1.f, 1.f, opacity * animation));
		Utils::ImGuiRender::fillRectangle(rect);

		Utils::ImGuiRender::setSize(100.f);
		Utils::ImGuiRender::setThickness(300.f);
		Utils::ImGuiRender::fillShadowRectangle(rect);

		Utils::ImGuiRender::setColor(ImColor(0.07f, 0.07f, 0.07f, 0.4f * animation / 2));
		Utils::ImGuiRender::pushClip(ImVec4(rightrect.x, rightrect.y, rightrect.z - (20.f * animation), rightrect.w));
		Utils::ImGuiRender::fillRectangle(rightrect);
		Utils::ImGuiRender::popClip();

		static std::vector<Categorystruct> catlist;
		static Category catselected;

		int catselectedlength = 0;
		for (Mod* mod : Client::modlist) {
			if (mod->category == catselected) {
				catselectedlength++;
			}
		}

		static bool savedtolastscroll = false;
		static float tolastscroll = 0.f;
		if (Client::mousescrolling) {
			if (!Client::mousedirection) {
				if (!savedtolastscroll) {
					tolastscroll = catlist[catselected].scroll;
					savedtolastscroll = true;
				}
				if (catlist[catselected].scroll < tolastscroll - 115.f) {
					savedtolastscroll = false;
					Client::mousescrolling = false;
				}

				catlist[catselected].scroll = Utils::Math::animate(tolastscroll - 125.f, catlist[catselected].scroll, Client::deltaTime * (scrollspeed * 20.f));
			}
			else {
				if (savedtolastscroll) {
					tolastscroll = catlist[catselected].scroll;
					savedtolastscroll = false;
				}
				if (catlist[catselected].scroll > tolastscroll + 115.f) {
					savedtolastscroll = true;
					Client::mousescrolling = false;
				}

				if (catlist[catselected].scroll < 0.f) {
					catlist[catselected].scroll = Utils::Math::animate(tolastscroll + 125.f, catlist[catselected].scroll, Client::deltaTime * (scrollspeed * 20.f));
				}
			}
		}


		Utils::ImGuiRender::setFont(ImGui::GetIO().Fonts->Fonts[1 + (4 * interfaceMod->font)]);
		Utils::ImGuiRender::setSize(1.8f * animation);
		ImVec2 logopos = ImVec2(rect.x + 20.f, rect.y + 20.f);
		ImVec2 verpos = ImVec2(rect.x + (20.f + Utils::ImGuiRender::getTextSize(Client::clientName).x), rect.y + 15.f);
		Utils::ImGuiRender::setColor(ImColor(1.f, 1.f, 1.f, animation));
		Utils::ImGuiRender::drawText(Client::clientName, logopos);
		Utils::ImGuiRender::setSize(1.2f * animation);
		int vindex = 0;

		for (char c : Client::clientVersion) {
			std::stringstream ss;
			ss << c;

			Utils::ImGuiRender::setColor(Utils::Color::getColor(3.f, 40.f * vindex, animation));
			Utils::ImGuiRender::drawText(ss.str(), verpos);

			verpos.x += Utils::ImGuiRender::getTextSize(ss.str()).x;
			vindex++;
		}

		if (catlist.empty()) {
			for (Mod* mod : Client::modlist) {
				if (std::ranges::find_if(catlist, [&](const Categorystruct& item) {
					return item.cat == mod->category;
					}) == catlist.end()) {
					catlist.push_back({ mod->category, mod->category == Category::RENDER ? 1.f : 0.f });
				}
			}
		}

		int index = 0;
		float nextHeight = 0.f;
		for (Categorystruct& cat : catlist) {
			std::string str = _("Unknown");
			std::string ostr = _("");
			switch (cat.cat) {
			case Category::COMBAT:
				str = Datas::Language::get().module.render.clickgui.combat_category;
				ostr = _("a");
				break;
			case Category::RENDER:
				str = Datas::Language::get().module.render.clickgui.render_category;
				ostr = _("g");
				break;
			case Category::MOVEMENT:
				str = Datas::Language::get().module.render.clickgui.movement_category;
				ostr = _("b");
				break;
			case Category::PLAYER:
				str = Datas::Language::get().module.render.clickgui.player_category;
				ostr = _("c");
				break;
			case Category::EXPLOIT:
				str = Datas::Language::get().module.render.clickgui.exploit_category;
				ostr = _("a");
				break;
			case Category::GHOST:
				str = Datas::Language::get().module.render.clickgui.ghost_category;
				ostr = _("f");
				break;
			case Category::OTHER:
				str = Datas::Language::get().module.render.clickgui.other_category;
				ostr = _("e");
				break;
			}

			Utils::ImGuiRender::setSize(1.1f * animation);

			ImVec2 sstrsize = Utils::ImGuiRender::getTextSize(_(" "));

			Utils::ImGuiRender::setFont(ImGui::GetIO().Fonts->Fonts[0 + (4 * interfaceMod->font)]);
			ImVec2 strsize = Utils::ImGuiRender::getTextSize(str);

			Utils::ImGuiRender::setFont(ImGui::GetIO().Fonts->Fonts[12]);
			ImVec2 ostrsize = Utils::ImGuiRender::getTextSize(ostr);

			ImVec2 catpos = ImVec2(logopos.x + sstrsize.x + ((sstrsize.x / 2) * cat.animation), rect.y + ((100.f + (50.f * index)) * animation));
			ImVec4 catrect = ImVec4(logopos.x, catpos.y - (5.f * animation), catpos.x + (strsize.x + sstrsize.x + ostrsize.x) + (sstrsize.x * animation), catpos.y + (strsize.y + (5.f * animation)));

			cat.animation = Utils::Math::animate(cat.cat == catselected ? 1.f : 0.f, cat.animation, Client::deltaTime * 2.5f);

			Utils::ImGuiRender::setColor(Utils::Color::getColor(3.f, 40 * index, opacity * (cat.animation * animation)));

			Utils::ImGuiRender::setRound(10.f);
			Utils::ImGuiRender::fillRectangle(catrect);
			Utils::ImGuiRender::setThickness(100.f);
			Utils::ImGuiRender::fillShadowRectangle(catrect);

			if (ImGui::GetIO().MousePos.x >= catrect.x && ImGui::GetIO().MousePos.y >= catrect.y && ImGui::GetIO().MousePos.x < catrect.z && ImGui::GetIO().MousePos.y < catrect.w) {
				if (ImGui::IsMouseClicked(0)) {
					catselected = cat.cat;
					cat.animation = 0.f;
					nextHeight = 0.f;
				}

				Utils::ImGuiRender::setColor(ImColor(1.f, 1.f, 1.f, animation));
			}
			else {
				if (catselected == cat.cat)
					Utils::ImGuiRender::setColor(ImColor(1.f, 1.f, 1.f, animation));
				else
					Utils::ImGuiRender::setColor(ImColor(0.6f, 0.6f, 0.6f, animation));
			}

			int sindex = 0;
			for (char s : ostr + str) {
				std::stringstream ss;
				ss << s;

				if (sindex == 0)
					Utils::ImGuiRender::setFont(ImGui::GetIO().Fonts->Fonts[12]);
				else
					Utils::ImGuiRender::setFont(ImGui::GetIO().Fonts->Fonts[0 + (4 * interfaceMod->font)]);
				Utils::ImGuiRender::drawText(ss.str(), catpos);

				catpos.x += Utils::ImGuiRender::getTextSize(ss.str()).x + (sindex == 0 ? sstrsize.x : 0.f);
				sindex++;
			}

			index++;
		}

		static std::vector<Modstruct*> list;
		if (list.empty()) {
			for (Mod* mod : Client::modlist) {
				list.push_back(new Modstruct{ mod });
			}
		}

		Utils::ImGuiRender::pushClip(ImVec4(rect.x, rect.y + 10.f, rect.z, rect.w - 10.f));
		int mindex = 0, mindex2 = 0;
		float tempheightmods = 0.f;
		for (Modstruct* modstruct : list) {

			Utils::ImGuiRender::setSize(1.25f * animation);
			ImVec2 namesize = Utils::ImGuiRender::getTextSize(modstruct->mod->name);

			Utils::ImGuiRender::setSize(1.f * animation);
			ImVec2 ssize = Utils::ImGuiRender::getTextSize(_(""));

			int ssettings = 0;
			for (Mod::Setting* setting : modstruct->mod->settings) {
				if (setting->visible)
					ssettings++;
			}

			modstruct->animation = Utils::Math::animate(modstruct->mod->category == catselected ? 1.f : 0.f, modstruct->animation, Client::deltaTime * 5.f);
			if (modstruct->expand) {
				modstruct->height = namesize.y + ((ssize.y + 5.f) * ssettings);
			}

			modstruct->expandanimation = Utils::Math::animate(modstruct->expand ? 1.f : 0.f, modstruct->expandanimation, Client::deltaTime * 5.f);
			modstruct->height *= modstruct->expandanimation;

			ImVec4 modrect_ = ImVec4(
				rightrect.z - (20.f * animation) + (10.f * animation),
				rect.y + (10.f * animation) + ((60.f * (modstruct->mod->category == catselected ? mindex : mindex2)) * animation) + (10.f * (modstruct->mod->category == catselected ? mindex : mindex2)) + catlist[catselected].scroll + nextHeight,
				rect.z - (10.f * animation),
				rect.y + (10.f * animation) + ((60.f * (modstruct->mod->category == catselected ? mindex : mindex2)) * animation) + (10.f * (modstruct->mod->category == catselected ? mindex : mindex2)) + catlist[catselected].scroll + nextHeight + 60.f
			);

			ImVec4 modrect = ImVec4(
				rightrect.z - (20.f * animation) + (10.f * animation),
				rect.y + (10.f * animation) + ((60.f * (modstruct->mod->category == catselected ? mindex : mindex2)) * animation) + (10.f * (modstruct->mod->category == catselected ? mindex : mindex2)) + catlist[catselected].scroll + nextHeight,
				rect.z - (10.f * animation),
				rect.y + (10.f * animation) + ((60.f * ((modstruct->mod->category == catselected ? mindex : mindex2) + 1) * animation)) + (10.f * (modstruct->mod->category == catselected ? mindex : mindex2)) + catlist[catselected].scroll + nextHeight
			);

			modrect.w += modstruct->height;

			if (modstruct->mod->category == catselected)
				nextHeight += modstruct->height;

			if (enabled && Utils::ImGuiRender::isHoveringRect(modrect)) {
				if (ImGui::IsMouseClicked(1)) {
					modstruct->expand = !modstruct->expand;
					Utils::Audio::playmc(_("random.pop"), 1.f, modstruct->expand ? 1.f : 0.8f);
				}
			}

			if (theme == 0)
				Utils::ImGuiRender::setColor(ImColor(0.07f, 0.07f, 0.07f, opacity * (modstruct->animation * animation)));
			else if (theme == 1)
				Utils::ImGuiRender::setColor(ImColor(1.f, 1.f, 1.f, opacity * (modstruct->animation * animation)));

			Utils::ImGuiRender::setRound(10.f);
			Utils::ImGuiRender::pushClip(modrect);

			Utils::ImGuiRender::fillRectangle(modrect);
			if (enabled && ((rect.w > modrect.y + 10.f) && (rect.y < modrect.y + 10.f)) && Utils::ImGuiRender::isHoveringRect(modrect_)) {
				if (ImGui::IsMouseClicked(0)) {
					if (modstruct->mod != interfaceMod && modstruct->mod->category == catselected) {
						modstruct->mod->enabled = !modstruct->mod->enabled;
						modstruct->mod->enabled ? modstruct->mod->onEnabled() : modstruct->mod->onDisabled();

						for (Mod* mod2 : Client::modlist) {
							if (!mod2->enabled && mod2->onlyenabled) continue;

							modstruct->mod->enabled ? mod2->onAnyEnabled() : mod2->onAnyDisabled();
						}
					}
				}
			}


			if (theme == 0)
				Utils::ImGuiRender::setColor(modstruct->mod->enabled ? Utils::Color::getColor(3.f, 40 * mindex, modstruct->animation * animation) : ImColor(1.f, 1.f, 1.f, modstruct->animation * animation));
			else if (theme == 1)
				Utils::ImGuiRender::setColor(modstruct->mod->enabled ? Utils::Color::getColor(3.f, 40 * mindex, modstruct->animation * animation) : ImColor(0.2f, 0.2f, 0.2f, modstruct->animation * animation));

			ImVec2 pos = ImVec2(modrect.x + 10.f, modrect.y + 5.f);
			ImVec2 descriptionpos = ImVec2(pos.x, pos.y + namesize.y);
			for (char s : modstruct->mod->name) {
				std::stringstream ss;
				ss << s;

				if (theme == 0)
					Utils::ImGuiRender::setColor(modstruct->mod->enabled ? Utils::Color::getColor(3.f, 40 * mindex, modstruct->animation * animation) : ImColor(1.f, 1.f, 1.f, modstruct->animation * animation));
				else if (theme == 1)
					Utils::ImGuiRender::setColor(modstruct->mod->enabled ? Utils::Color::getColor(3.f, 40 * mindex, modstruct->animation * animation) : ImColor(0.2f, 0.2f, 0.2f, modstruct->animation * animation));

				Utils::ImGuiRender::setSize(1.25f * animation);
				Utils::ImGuiRender::drawText(ss.str(), pos);
				pos.x += Utils::ImGuiRender::getTextSize(ss.str()).x;
			}

			Utils::ImGuiRender::setColor(ImColor(0.6f, 0.6f, 0.6f, modstruct->animation * animation));
				Utils::ImGuiRender::setSize(1.1f * animation);
			Utils::ImGuiRender::drawText(modstruct->mod->description, descriptionpos);

			if (modstruct->expand && modstruct->mod->category == catselected) {
				int index = 0;
				for (Setting* setting : modstruct->mod->settings) {
					if (!setting->visible) continue;

					Utils::ImGuiRender::setSize(1.1f * animation);
					ImVec2 namesize = Utils::ImGuiRender::getTextSize(setting->name);
					if (theme == 0)
						Utils::ImGuiRender::setColor(ImColor(1.f, 1.f, 1.f, modstruct->animation * (animation * modstruct->expandanimation)));
					else if (theme == 1)
						Utils::ImGuiRender::setColor(ImColor(0.2f, 0.2f, 0.2f, modstruct->animation * (animation * modstruct->expandanimation)));

					switch (setting->type) {
					case 0: {
						ImVec2 pos = ImVec2(descriptionpos.x + 5.f, descriptionpos.y + (namesize.y + 10.f) + ((ssize.y + 5.f) * index));
						ImVec4 settingrect = ImVec4(pos.x - 1.f, pos.y - 1.f, pos.x + namesize.x + 11.f, pos.y + namesize.y + 1.f);
						ImVec2 circlepos = ImVec2(pos.x + namesize.x + 10.f, pos.y + (namesize.y / 2) + 2.5f);

						if (enabled && Utils::ImGuiRender::isHoveringRect(settingrect)) {
							if (ImGui::IsMouseClicked(0)) {
								*(bool*)setting->ptr = !*(bool*)setting->ptr;
							}
						}

						Utils::ImGuiRender::drawText(setting->name, pos);
						Utils::ImGuiRender::setSize(3.f * animation + 1.f);
						Utils::ImGuiRender::setColor(Utils::Color::getColor(1.f, 0, (modstruct->animation * (animation * modstruct->expandanimation)) * opacity));
						if (*(bool*)setting->ptr) {
							Utils::ImGuiRender::fillCircle(circlepos);
							Utils::ImGuiRender::fillShadowCircle(circlepos);
						}
						break;
					}
					case 1: {
						ImVec2 pos = ImVec2(descriptionpos.x + 5.f, descriptionpos.y + (namesize.y + 10.f) + ((ssize.y + 5.f) * index));

						std::string max = _("");
						for (std::string list : setting->list) {
							if (max.length() < list.length())
								max = list;
						}

						ImVec4 settingrect = ImVec4(pos.x - 1.f, pos.y - 1.f, pos.x + namesize.x + Utils::ImGuiRender::getTextSize(":" + max).x + 1.f, pos.y + namesize.y + 1.f);

						if (enabled && Utils::ImGuiRender::isHoveringRect(settingrect)) {
							if (ImGui::IsMouseClicked(0)) {
								if (*(int*)setting->ptr == *(int*)setting->max)
									*(int*)setting->ptr = 0;
								else
									*(int*)setting->ptr = *(int*)setting->ptr + 1;
							}
							else if (ImGui::IsMouseClicked(1)) {
								if (*(int*)setting->ptr == *(int*)0)
									*(int*)setting->ptr = *(int*)setting->max;
								else
									*(int*)setting->ptr = *(int*)setting->ptr - 1;
							}
						}

						Utils::ImGuiRender::drawText(setting->name + _(":"), pos);
						pos.x += Utils::ImGuiRender::getTextSize(setting->name + _(":")).x + 2.5f;
						Utils::ImGuiRender::drawText(setting->list[*(int*)setting->ptr], pos);

						Utils::ImGuiRender::setSize(5.f);
						break;
					}
					case 2: {
						ImVec2 pos = ImVec2(descriptionpos.x + 5.f, descriptionpos.y + (namesize.y + 10.f) + ((ssize.y + 5.f) * index));
						ImVec4 barrect = ImVec4(pos.x + namesize.x + 10.f, pos.y + (namesize.y / 2) - 2.5f, pos.x + namesize.x + 10.f + ((setting->size * (*(float*)setting->max - *(float*)setting->min) * animation)), pos.y + (namesize.y / 2) + 2.5f);

						std::stringstream ss;
						ss.precision(2);
						ss << std::fixed << *(float*)setting->ptr;

						Utils::ImGuiRender::setSize(1.1f * animation);
						ImVec2 ptrSize = Utils::ImGuiRender::getTextSize(ss.str());

						ImVec4 inputrect = ImVec4((pos.x + (barrect.z - barrect.x) + namesize.x + 20.f) - 2.5f, pos.y - 2.5, (pos.x + (barrect.z - barrect.x) + namesize.x + 20.f) + ptrSize.x + 2.5f, pos.y + ptrSize.y + 2.5f);
						ImVec2 circlepos = ImVec2(barrect.x + ((*(float*)setting->ptr - *(float*)setting->min) * (setting->size * animation)), pos.y + (namesize.y / 2));

						if (enabled && Utils::ImGuiRender::isHoveringRect(barrect)) {
							if (ImGui::IsMouseDown(0)) {
								setting->holding = true;
							}
							else {
								setting->holding = false;
							}
						}

						if (!setting->inputing) {
							if (enabled && Utils::ImGuiRender::isHoveringRect(inputrect)) {
								if (ImGui::IsMouseClicked(0) && !inputing) {
									setting->lastclicked = now;
									setting->clicked++;
									if (setting->clicked >= 2) {
										setting->inputing = true;

										setting->inputs = ss.str();

										inputing = true;
									}
								}
								else {
									if (now - setting->lastclicked >= 500.f) {
										setting->clicked = 0;
									}
								}
							}
							else {
								setting->clicked = 0;
							}
						}
						else {
							setting->holding = false;

							if (!Utils::ImGuiRender::isHoveringRect(inputrect) && ImGui::IsMouseClicked(0)) {
								setting->inputing = false;
								setting->clicked = 0;
								inputing = false;
								inputs.clear();
							}

							Utils::ImGuiRender::setColor(Utils::Color::getColor(1.f, 0, (modstruct->animation * (animation * modstruct->expandanimation)) * (opacity * 0.2f)));
							Utils::ImGuiRender::setRound(0.f);
							Utils::ImGuiRender::fillRectangle(inputrect);

							for (int key : inputs) {
								if (key == '0') setting->inputs += _("0");
								else if (key == '1') setting->inputs += _("1");
								else if (key == '2') setting->inputs += _("2");
								else if (key == '3') setting->inputs += _("3");
								else if (key == '4') setting->inputs += _("4");
								else if (key == '5') setting->inputs += _("5");
								else if (key == '6') setting->inputs += _("6");
								else if (key == '7') setting->inputs += _("7");
								else if (key == '8') setting->inputs += _("8");
								else if (key == '9') setting->inputs += _("9");
								else if (key == VK_OEM_PERIOD) setting->inputs += _(".");
								else if (key == VK_BACK) {
									if (setting->inputs.length() != 1)
										setting->inputs.pop_back();
									else
										setting->inputs = _("0");
								}
							}

							float value = std::stof(setting->inputs);
							if (value > *(float*)setting->max) {
								*(float*)setting->ptr = *(float*)setting->max;
							}
							else {
								*(float*)setting->ptr = value;
							}

							if (Client::keymaps[VK_RETURN]) {
								setting->inputing = false;
								setting->clicked = 0;
								inputing = false;
								inputs.clear();
							}
						}

						if (!ImGui::IsMouseDown(0))
							setting->holding = false;

						if (!enabled)
							setting->holding = false;

						if (setting->holding) {
							*(float*)setting->ptr = Utils::Math::animate(
								(((ImGui::GetIO().MousePos.x - (pos.x + namesize.x + 10.f) + (*(float*)setting->min * setting->size))) / setting->size), *(float*)setting->ptr, Client::deltaTime * 5.f);
							if (*(float*)setting->ptr < *(float*)setting->min)
								*(float*)setting->ptr = *(float*)setting->min;
							else if (*(float*)setting->ptr > *(float*)setting->max)
								*(float*)setting->ptr = *(float*)setting->max;
						}

						if (theme == 0)
							Utils::ImGuiRender::setColor(ImColor(1.f, 1.f, 1.f, modstruct->animation * (animation * modstruct->expandanimation)));
						else if (theme == 1)
							Utils::ImGuiRender::setColor(ImColor(0.2f, 0.2f, 0.2f, modstruct->animation * (animation * modstruct->expandanimation)));

						Utils::ImGuiRender::drawText(setting->name, pos);
						if (theme == 0)
							Utils::ImGuiRender::setColor(ImColor(0.09f, 0.09f, 0.09f, (modstruct->animation * (animation * modstruct->expandanimation)) * opacity));
						else if (theme == 1)
							Utils::ImGuiRender::setColor(ImColor(0.8f, 0.8f, 0.8f, (modstruct->animation * (animation * modstruct->expandanimation)) * opacity));
						Utils::ImGuiRender::fillRectangle(barrect);
						pos.x += (barrect.z - barrect.x) + namesize.x + 20.f;

						Utils::ImGuiRender::setSize(1.1f * animation);
						if (theme == 0)
							Utils::ImGuiRender::setColor(ImColor(1.f, 1.f, 1.f, modstruct->animation * (animation * modstruct->expandanimation)));
						else if (theme == 1)
							Utils::ImGuiRender::setColor(ImColor(0.f, 0.f, 0.f, modstruct->animation * (animation * modstruct->expandanimation)));
						Utils::ImGuiRender::drawText(ss.str(), pos);
						Utils::ImGuiRender::setSize(4.f * animation + 1.f);
						Utils::ImGuiRender::setColor(Utils::Color::getColor(1.f, 0, (modstruct->animation * (animation * modstruct->expandanimation)) * opacity));

						Utils::ImGuiRender::fillCircle(circlepos);

						Utils::ImGuiRender::setThickness(100.f);
						Utils::ImGuiRender::fillShadowCircle(circlepos);
						break;
					}
					case 3: {
						ImVec2 pos = ImVec2(descriptionpos.x + (60.f) + 2.5f, descriptionpos.y + (namesize.y + 10.f) + ((ssize.y + 5.f) * index));
						ImVec4 bar1 = ImVec4(descriptionpos.x, pos.y + (namesize.y / 2) - 1.f, descriptionpos.x + 60.f, pos.y + (namesize.y / 2) + 1.f);
						ImVec4 bar2 = ImVec4(pos.x + namesize.x + 2.5f, bar1.y, pos.x + namesize.x + (60.f + 2.5f), bar1.w);

						Utils::ImGuiRender::drawText(setting->name, pos);

						Utils::ImGuiRender::fillRectangle(bar1);
						Utils::ImGuiRender::fillRectangle(bar2);
						break;
					}
					}

					index++;
				}
			}



			if (modstruct->mod->category == catselected)
				mindex++;
			else
				mindex2++;

			tempheightmods += (modrect.w - modrect.y);

			Utils::ImGuiRender::popClip();
		}

		heightMods = tempheightmods;

		Utils::ImGuiRender::popClip();
	}
	}
}

auto ClickGui::onKeyboard(int key, bool* held, bool* cancel) -> void {
	if (!enabled || unvisible) return;

	if (GetAsyncKeyState(VK_ESCAPE) & 0x8000) {
		enabled = false;
		onDisabled();

		for (Mod* mod : Client::modlist) {
			if (!mod->enabled && mod->onlyenabled) continue;

			mod->onAnyDisabled();
		}
	}

	if (inputing && *held) {
		inputs.push_back(key);
	}

	*cancel = true;
}

auto ClickGui::onMouse(char button, char state, bool* cancel) -> void {
	if (!enabled || unvisible) return;

	*cancel = true;
}

auto ClickGui::onDisabled() -> void {
	if (Client::clientinstance && Client::screenName == _("hud_screen"))
		Client::clientinstance->grabMouse();
}

auto ClickGui::onClient4() -> void {
	name = Datas::Language::get().module.render.clickgui.name;
	description = Datas::Language::get().module.render.clickgui.description;
}

auto ClickGui::getMode() -> std::string {
	switch (style) {
	case 0:
		return _("Rise");
	}

	return _("Unknown");
}
