#include "client/gui/OptionsMenu.h"

#include "client/gui/FPSMenu.h"
#include <SDL2/SDL.h>
#include <imgui.h>

namespace blitz {
namespace gui {

OptionsMenu::OptionsMenu(GuiWidget* parent, Client* client) : GuiWidget(parent, client) {
	AddWidget(std::make_unique<FPSMenu>(this, client));
}

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

	if (!IsEnabled())
		return;

	const static int paddingHeight = 40;
	const static int startPos = 15;

	static bool showFPS = false;
	static bool vsync = true;

	SetNextWindowFullScreen();

	ImGui::Begin("OptionsWindow", nullptr, GetWindowFullScreenFlags());
	{
		ImGui::SetCursorPosX(startPos);
		ImGui::SetCursorPosY(100);

		if (ImGui::Checkbox("AFFICHER LES FPS", &showFPS)) {
			m_SubWidgets[0]->SetState(showFPS);
		}

		if (ImGui::Checkbox("VSync", &vsync)) {
			SDL_GL_SetSwapInterval(vsync);
		}

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

}  // namespace gui
}  // namespace blitz
