#pragma once

#include "../Settings.h"
#include "../PlayerCursor.h"

#include <stack>
#include <memory>
#include <optional>
#include <SFML/Graphics.hpp>

class AppMenu;
using MenuStack = std::stack<std::shared_ptr<AppMenu>>;


class AppMenu {
    protected:
        std::shared_ptr<MenuStack> menuStack;
        std::shared_ptr<Settings> settings;
        std::shared_ptr<sf::RenderWindow> renderWindow;
        bool enterPressed = false;
        bool enterReleased = false;
        bool escPressed = false;
        bool escReleased = false;
        sf::Font pressStartFont;
    
    public:
        AppMenu(std::shared_ptr<MenuStack> menuStack, std::shared_ptr<Settings> settings, std::shared_ptr<sf::RenderWindow> renderWindow);

        virtual void computeFrame() = 0;

        virtual void drawFrame() const = 0; 

    protected:
        void updateMetaBinds();

        void placeText(sf::Text& text, const std::optional<PlayerCursor>& playerCursor, const sf::String& string, float xPos, float yPos, const std::optional<sf::Vector2u>& cursorPos) const;

        void placeTitle(sf::Text& text, const std::optional<PlayerCursor>& playerCursor, const sf::String& string, float yPos, const std::optional<sf::Vector2u>& cursorPos) const;

        sf::Color getColorOfBlock(Block block, int luminosityShift) const;
};
