#pragma once

#include <array>
#include <optional>
#include <string>

#include <SDL3/SDL.h>

#include "ui/MenuLayout.h"
#include "ui/UIConstants.h"

struct FontAtlas;

namespace ui {

enum class BottomMenuItem : int {
    Play = 0,
    Cooperate = 1,
    Challenge = 2,
    Level = 3,
    Options = 4,
    Help = 5,
    About = 6,
    Exit = 7,
};

struct Button {
    BottomMenuItem item{};
    SDL_FRect rect{};
    std::string label;
    bool textOnly = true;
};

struct BottomMenu {
    std::array<Button, MENU_BTN_COUNT> buttons{};
};

BottomMenu buildBottomMenu(const MenuLayoutParams& params, int startLevel, bool coopVsAI);

// Draws the cockpit HUD menu (PLAY + 4 bottom items) using existing UIRenderer primitives.
// hoveredIndex: -1..7
// selectedIndex: 0..7 (keyboard selection)
// alphaMul: 0..1 (overall group alpha)
void renderBottomMenu(SDL_Renderer* renderer,
                      FontAtlas* font,
                      const BottomMenu& menu,
                      int hoveredIndex,
                      int selectedIndex,
                      double baseAlphaMul,
                      double flashAddMul);

struct BottomMenuInputResult {
    int hoveredIndex = -1;
    std::optional<BottomMenuItem> activated;
};

// Interprets mouse motion/button input for the bottom menu.
// Expects x/y in the same logical coordinate space used by MenuLayout (the current main loop already provides this).
BottomMenuInputResult handleBottomMenuInput(const MenuLayoutParams& params,
                                            const SDL_Event& e,
                                            float x,
                                            float y,
                                            int prevHoveredIndex,
                                            bool inputEnabled);

} // namespace ui
