#include "input_string.hpp"

#include <misc/cpp/imgui_stdlib.h>
#include <misc/cpp/imgui_stdlib.cpp>

namespace game::util::imgui
{
  bool input_string(const char* label, std::string& value, ImGuiInputTextFlags flags)
  {
    auto changed = ImGui::InputText(label, &value, flags);
    return ImGui::IsItemDeactivatedAfterEdit() ||
           (changed && (flags & ImGuiInputTextFlags_EnterReturnsTrue));
  }

  bool input_string_multiline(const char* label, std::string& value, const ImVec2& size, ImGuiInputTextFlags flags)
  {
    return input_string_multiline_result(label, value, size, flags).committed;
  }

  InputStringResult input_string_multiline_result(const char* label, std::string& value, const ImVec2& size,
                                                  ImGuiInputTextFlags flags)
  {
    auto changed = ImGui::InputTextMultiline(label, &value, size, flags);
    return {.changed = changed,
            .committed = ImGui::IsItemDeactivatedAfterEdit() ||
                         (changed && (flags & ImGuiInputTextFlags_EnterReturnsTrue))};
  }
}
