#include <SFML/Graphics.hpp>
#include <cmath>
#include <vector>
#include <string>
#include <memory>
#include "sfline.hpp"
#include "node.hpp"
#include <iostream>

using std::cout, std::endl;

std::shared_ptr<Node> createSkillTree()
{
    std::shared_ptr<Node> root  {new LightningSkillNode({400, 500})};
    std::shared_ptr<Node> a     {new ShurikenSkillNode({200, 400})};
    std::shared_ptr<Node> b     {new BombSkillNode({400, 400})};
    std::shared_ptr<Node> c     {new EyeSkillNode({600, 400})};
    root->addChild(a);
    root->addChild(b);
    root->addChild(c);

    a->addChild(std::shared_ptr<Node>{new ShieldSkillNode({100, 200})});
    a->addChild(std::shared_ptr<Node>{new SwordSkillNode({200, 200})});
    a->addChild(std::shared_ptr<Node>{new EarthquakeSkillNode({300, 200})});

    b->addChild(std::shared_ptr<Node>{new HandSkillNode({400, 200})});
    b->addChild(std::shared_ptr<Node>{new MeteoriteSkillNode({500, 200})});
    std::shared_ptr<Node> e {new BombSkillNode({600, 200})};
    b->addChild(e);
    e->addChild(std::shared_ptr<Node>{new WindSkillNode({500, 100})});
    e->addChild(std::shared_ptr<Node>{new SwordSkillNode({600, 100})});
    c->addChild(std::shared_ptr<Node>{new EyeSkillNode({700, 200})});

    return root;
}


int main()
{
    sf::ContextSettings settings;
    settings.antialiasingLevel = 8;
    sf::RenderWindow window(sf::VideoMode(1000, 800), "Skill Tree", sf::Style::Close, settings);
    window.setFramerateLimit(60);

    std::shared_ptr<Node> root = createSkillTree();
    root->unblock();

    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();


            if (event.type == sf::Event::MouseButtonPressed)
            {
                sf::Vector2f mouseCoords = window.mapPixelToCoords({event.mouseButton.x, event.mouseButton.y});
                root->onMousePressed(mouseCoords);
            }
        }


        window.clear(sf::Color::Black);
        root->draw(window);
        window.display();
    }

    return 0;
}
