#include "MainAppMenu.h"

#include "AppMenu.h"
#include "GameSettingsAppMenu.h"
#include "SettingsMainAppMenu.h"
#include "InfoAppMenu.h"
#include "../PlayerCursor.h"

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


MainAppMenu::MainAppMenu(std::shared_ptr<MenuStack> menuStack, std::shared_ptr<Settings> settings, std::shared_ptr<sf::RenderWindow> renderWindow) :
    AppMenu(menuStack, settings, renderWindow),
    playerCursor({1, 1, 1}) {

}

void MainAppMenu::computeFrame() {
    this->updateMetaBinds();
    this->playerCursor.updatePosition();

    if (this->enterReleased) {
        if (this->playerCursor.getPosition().y == 0) {
            this->menuStack->push(std::make_shared<GameSettingsAppMenu>(this->menuStack, this->settings, this->renderWindow));
        }
        if (this->playerCursor.getPosition().y == 1) {
            this->menuStack->push(std::make_shared<SettingsMainAppMenu>(this->menuStack, this->settings, this->renderWindow));
        }
        if (this->playerCursor.getPosition().y == 2) {
            this->menuStack->push(std::make_shared<InfoAppMenu>(this->menuStack, this->settings, this->renderWindow));
        }
    }
    if (this->escReleased) {
        this->menuStack->pop();
    }
}

void MainAppMenu::drawFrame() const {
    this->renderWindow->clear(sf::Color(200, 200, 200));

    sf::Text text(this->pressStartFont, "", this->settings->getWindowSizeMultiplier() * 2);
    text.setFillColor(sf::Color(0, 0, 0));
    text.setOutlineColor(sf::Color(255, 255, 255));

    this->placeTitle(text, {}, "JMINOS", 10.f, {});

    this->placeTitle(text, this->playerCursor, "PLAY", 20.f, sf::Vector2u{0, 0});
    this->placeTitle(text, this->playerCursor, "SETTINGS", 30.f, sf::Vector2u{0, 1});
    this->placeTitle(text, this->playerCursor, "INFO", 40.f, sf::Vector2u{0, 2});
    
    this->renderWindow->display();
}
