#include "ui/CompressionFormatCombo.h"

#include <imgui.h>

namespace bmp2tile::ui
{

bool DrawCompressionFormatCombo(const char* label, CompressionFormat& format, bool (*supports)(CompressionFormat))
{
    bool changed = false;
    if (ImGui::BeginCombo(label, CompressionFormatName(format)))
    {
        for (int i = 0; i <= static_cast<int>(CompressionFormat::STM); ++i)
        {
            const auto candidate = static_cast<CompressionFormat>(i);
            if (!supports(candidate)) continue;

            const bool isSelected = (candidate == format);
            if (ImGui::Selectable(CompressionFormatName(candidate), isSelected))
            {
                format = candidate;
                changed = true;
            }
            if (isSelected) ImGui::SetItemDefaultFocus();
        }
        ImGui::EndCombo();
    }
    return changed;
}

}  // namespace bmp2tile::ui
