#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::Text("Creer une partie");

		ImGui::NewLine();

		ImGui::InputText("Pseudo", m_Client->GetConfig()->GetPseudo().data(), m_Client->GetConfig()->GetPseudo().size());

		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, m_Client->GetConfig()->GetPseudo().data())) {
				Disable();
			}
		}

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

}  // namespace gui
}  // namespace blitz
