#include "client/gui/MainMenu.h"
#include "client/gui/CreateGameMenu.h"
#include "client/gui/JoinGameMenu.h"
#include "client/gui/OptionsMenu.h"

#include <imgui.h>

namespace blitz {
namespace gui {

MainMenu::MainMenu(Client* client) : GuiWidget(nullptr, client) {
	Enable();
	AddWidget(std::make_unique<CreateGameMenu>(this, client));
	AddWidget(std::make_unique<JoinGameMenu>(this, client));
	AddWidget(std::make_unique<OptionsMenu>(this, client));
}

void MainMenu::Render() {
	GuiWidget::Render();

	if (!IsEnabled())
		return;

	SetNextWindowFullScreen();

	ImGui::Begin("Fullscreen window", nullptr, GetWindowFullScreenFlags());
	{
		auto displaySize = ImGui::GetIO().DisplaySize;
		const static ImVec2 buttonSize = {500, 150};
		const static int paddingHeight = 20;
		const static int frameRounding = 40;

		float centerX = displaySize.x / 2 - buttonSize.x / 2;
		float centerY = displaySize.y / 2 - buttonSize.y / 2;

		ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, frameRounding);

		ImGui::SetCursorPosX(centerX);
		ImGui::SetCursorPosY(centerY - buttonSize.y - paddingHeight);
		if (ImGui::Button("CREER UNE PARTIE", buttonSize)) {
			Disable();
			m_SubWidgets[CREATE_MENU]->Enable();
		}

		ImGui::SetCursorPosX(centerX);
		ImGui::SetCursorPosY(centerY);
		if (ImGui::Button("REJOINDRE UNE PARTIE", buttonSize)) {
			Disable();
			m_SubWidgets[JOIN_MENU]->Enable();
		}

		ImGui::SetCursorPosX(centerX);
		ImGui::SetCursorPosY(centerY + buttonSize.y + paddingHeight);
		if (ImGui::Button("OPTIONS", buttonSize)) {
			Disable();
			m_SubWidgets[OPTION_MENU]->Enable();
		}

		ImGui::PopStyleVar();
	}
	ImGui::End();
}

}  // namespace gui
}  // namespace blitz
