// LevelSelectorState.h - Level selection popup state
#pragma once
#include "State.h"

class LevelSelectorState : public State {
public:
    explicit LevelSelectorState(StateContext& ctx);
    
    void onEnter() override;
    void onExit() override;
    void handleEvent(const SDL_Event& e) override;
    void update(double frameMs) override;
    void render(SDL_Renderer* renderer, float logicalScale, SDL_Rect logicalVP) override;

private:
    int hoveredLevel = -1; // -1 = none, 0..19 = hovered level
    // Cache the latest logical scale/viewport from render() for input conversion
    float lastLogicalScale = 1.0f;
    SDL_Rect lastLogicalVP{0,0,0,0};
    
    // Helper functions
    void drawLevelSelectionPopup(SDL_Renderer* renderer, float logicalScale, SDL_Rect logicalVP);
    bool isMouseInPopup(float mouseX, float mouseY, float& popupX, float& popupY, float& popupW, float& popupH);
    int getLevelFromMouse(float mouseX, float mouseY, float popupX, float popupY, float popupW, float popupH);
    void updateHoverFromMouse(float mouseX, float mouseY);
    void selectLevel(int level);
    void closePopup();
};
