#include "ScreenViews.h"
#include "Client.h"

#include "Hook/MinecraftUIRenderContexts.h"

#include "Utils/MathUtils.h"

#include "Datas/UserDatas.h"

void Hooks::ScreenViews::callback_setupandrender(ScreenView* arg_1, MinecraftUIRenderContext* arg_2) {
	for (Mod* mod : Client::modlist) {
		if (!mod->enabled && mod->onlyenabled) continue;

		mod->onSetupAndRender();
	}

	static bool hooked = false;
	if (!hooked) {
		Hooks::MinecraftUIRenderContexts::Init(arg_2);

		hooked = true;
	}

	glm::vec2 screensize = arg_2->getClientInstance()->getGuiData()->getScreenSize();
	Client::clientinstance = arg_2->getClientInstance();

	{
		static bool get = false;
		if (!get) {
			Client::windowsize = ImVec2(screensize.x, screensize.y);
			get = true;
		}
		else {
			Client::windowsize.x = Utils::Math::animate(screensize.x, Client::windowsize.x, Client::deltaTime);
			Client::windowsize.y = Utils::Math::animate(screensize.y, Client::windowsize.y, Client::deltaTime);
		}
		Client::syncwindowsize = ImVec2(screensize.x, screensize.y);
	}

	Client::screenview = arg_1;
	Client::deltaTime = arg_1->getDeltaTime();
	Client::rawscreenName = arg_1->getVisualTree()->getUIControl()->getName();
	if (Client::rawscreenName != _("debug_screen") && Client::rawscreenName != _("toast_screen")) {
		Client::oldscreenName = Client::rawscreenName;
	}

	Client::screenName = arg_2->getClientInstance()->getScreenName();
	Client::guiScale = arg_2->getClientInstance()->getGuiData()->getGuiScale();

	screenview_setupandrender(arg_1, arg_2);
}
