#include <iostream>
#include <window/window.hpp>
#include <state/gamestate.hpp>
#include <object/entity.hpp>
#include <object/transform.hpp>
#include <game/agame/player.hpp>
#include <game/agame/background.hpp>
#include <game/agame/hudtext.hpp>
#include <game/gamemanager.hpp>
#include <renderer/renderer.hpp>
#include <renderer/texture.hpp>
#include <renderer/font.hpp>
#include <object/ui/uitextbox.hpp>
#include <game/agame/sampletextbox.hpp>
#include <object/components/boxcollider.hpp>

using namespace Game;

int main() {
    PLNIMP("Letnik3Zadnja - Licenca: LGPLv2.1-only, CC BY-SA 4.0");
    // Prompt for player name before initializing the window/engine
    std::string playerName;
        std::cout << "Vnesi uporabniško ime (pusti prazno za 'Igralec'): ";
    std::getline(std::cin, playerName);
    if (playerName.empty()) playerName = "Igralec";
    Game::GameManager::setSharedData<std::string>("playerName", playerName);

    Window::Window window = Window::Window();
    window.init(1280, 720, "Game Window");

    State::GameState::getInstance().addEntity(std::make_unique<AGame::Background>("BG", std::make_shared<Game::Renderer::Texture>("../resources/bgtest.png", window.getRenderer()->getSDLRenderer()), Object::DEFAULT_TRANSFORM));

    auto* player = dynamic_cast<AGame::Player*>(State::GameState::getInstance().addEntity(std::make_unique<AGame::Player>("Player", std::make_shared<Game::Renderer::Texture>("../resources/l3ladja.png", window.getRenderer()->getSDLRenderer()), Object::DEFAULT_TRANSFORM)));
    if (player) {
        player->addComponent<Object::Components::BoxCollider>();
        player->setShipTexture(std::make_shared<Game::Renderer::Texture>("../resources/l3ladja.png", window.getRenderer()->getSDLRenderer()));
        player->setGroundTexture(std::make_shared<Game::Renderer::Texture>("../resources/l3player.png", window.getRenderer()->getSDLRenderer()));
    }

    State::GameState::getInstance().addEntity(std::make_unique<AGame::HUDText>("HUD", std::make_shared<Game::Renderer::Font>("../resources/roboto.ttf", window.getRenderer()->getSDLRenderer(), 72, "HUDFont"), Object::Transform{0.f, 0.f, 0.f, 1.f, 1.f}, 320.f, 40.f));

    window.run();
    
    return 0;
}