#include "client/gui/CreateGameMenu.h"

#include "blitz/misc/Format.h"
#include "blitz/misc/Log.h"
#include "client/Client.h"
#include <cmath>
#include <imgui.h>
#include <string>

namespace blitz {
namespace gui {

void CreateGameMenu::Render() {
	if (!IsEnabled())
		return;

	SetNextWindowFullScreen();

	static int InputPort = 0;

	ImGui::Begin("CreateWindow", nullptr, GetWindowFullScreenFlags());
	{
		ImGui::SetCursorPosY(100);

		static char Pseudo[256] = "Pseudo";
		ImGui::InputText("Pseudo", Pseudo, sizeof(Pseudo));

		ImGui::InputInt("Port", &InputPort);

		ImGui::Text("Port saisi : %d", InputPort);

		if (ImGui::Button("Creer")) {
			utils::LOGD(utils::Format("Port saisi : %i", InputPort));

			if (m_Client->CreateGame(InputPort, Pseudo)) {
				Disable();
			}
		}

		if (ImGui::Button("Retour") || ImGui::IsKeyPressed(ImGuiKey_Escape)) {
			Disable();
			m_Parent->Enable();
		}
	}
	ImGui::End();
}

}  // namespace gui
}  // namespace blitz
