#include "client/gui/JoinGameMenu.h"

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

namespace blitz {
namespace gui {

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

	SetNextWindowFullScreen();

	static int InputPort = 25565;

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

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

		static char InputAddress[256] = "localhost";
		ImGui::InputText("Adresse", InputAddress, sizeof(InputAddress));

		ImGui::Text("Adresse saisie : %s", InputAddress);

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

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

		if (ImGui::Button("Rejoindre")) {
			utils::LOGD(utils::Format("Adresse saisie : %s, Port saisi : %i", InputAddress, InputPort));

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

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

}  // namespace gui
}  // namespace blitz
