#include <app.h>
#include <imgui/imgui.h>
#include "settingsMenu.h"

namespace game {

bool SettingsMenu::Update()
{
    bool shouldExit = false;

    Config *conf = App::GetConfig();

    ImGui::SetNextWindowPos({240, 200}, ImGuiCond_Always);
    ImGui::Begin("Settings", nullptr, {480, 230}, 1, ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse);

    ImGui::SliderFloat("Music volume", &conf->editData.musicVolume, 0, 1);
    ImGui::SliderFloat("Button FX volume", &conf->editData.soundVolume, 0, 1);
    ImGui::Separator();
    if (ImGui::InputFloat("Timing calibration", &conf->editData.calibration, 0.01, 0.01)) {
        conf->editData.calibration = clamp(conf->editData.calibration, -0.2f, 0.2f);
    }
    ImGui::Separator();
    if (ImGui::Button("Save", {150, 32})) {
        conf->SaveEdit();
        shouldExit = true;
    }
    ImGui::SameLine();
    if (ImGui::Button("Load defaults", {150, 32})) {
        conf->LoadDefaultEdit();
    }
    ImGui::SameLine();
    if (ImGui::Button("Cancel", {150, 32})) {
        conf->CancelEdit();
        shouldExit = true;
    }

    ImGui::End();

    return shouldExit;
}

}

