#include "classictimelinegraphicsmanager.h"

#include "editor/mockelement.h"
#include "game/arrowelement.h"

ClassicTimelineGraphicsManager::ClassicTimelineGraphicsManager(const std::shared_ptr<kku::Timeline<ClassicNote>>& timeline,
                                                               const std::shared_ptr<ClassicGraphicsFactory>& factory,
                                                               const kku::microsec& visibility_offset) :
    ClassicGraphicsManager(visibility_offset),
    _sprite_container({Type::UP, Type::DOWN,
                      Type::LEFT, Type::RIGHT},
                      factory),
    _factory(factory),
    _timeline(timeline)
{
}

void ClassicTimelineGraphicsManager::input(kku::GameEvent&& input)
{
    (void)input;
}

void ClassicTimelineGraphicsManager::display() const
{
    if (nothingToDraw())
        return;
}

void ClassicTimelineGraphicsManager::update(const kku::microsec &offset)
{
    fetchLastNote(offset);
    fetchFirstNote(offset);

    updateVisibleNotes(offset);
}

void ClassicTimelineGraphicsManager::display(const std::vector<ArrowElement>& elements) const
{
    for (std::size_t i = 0; i < elements.size(); ++i)
    {
        const auto& sprite = elements[i].sprite;

        if (i >= 1)
        {
            //const auto& neighbor_sprite = elements[i - 1].sprite;

            //const auto c1 = neighbor_sprite->trailPosition();
            //const auto c2 = sprite->trailPosition();

            //_render_target->draw(makeLine(c1, c2));
        }

        sprite->display();
    }
}

void ClassicTimelineGraphicsManager::setGraphics(std::vector<ArrowElement>& elements, kku::TimeRange &&range)
{
    (void)elements; (void)range;
}

void ClassicTimelineGraphicsManager::display(const std::vector<MockElement>& elements) const
{
    for (std::size_t i = 0; i < elements.size(); ++i)
    {
        const auto& sprite = elements[i].sprite;

        if (i >= 1)
        {
            //const auto& neighbor_sprite = elements[i - 1].sprite;

            //const auto c1 = neighbor_sprite->trailPosition();
            //const auto c2 = sprite->trailPosition();

            //_render_target->draw(makeLine(c1, c2));
        }

        sprite->display();
    }
}

void ClassicTimelineGraphicsManager::setGraphics(std::vector<MockElement>& elements, kku::TimeRange &&range)
{
    (void)elements; (void)range;
}

/*sf::VertexArray ClassicSceneGraphicsSFML::makeLine(const kku::Point& c1, const kku::Point& c2) const
{
    sf::VertexArray line(sf::LinesStrip, 2);
    line[0].color = sf::Color::Yellow;
    line[0].position = {c1.x + 10, c1.y};
    line[1].color = sf::Color::Blue;
    line[1].position = {c2.x + 10, c2.y};

    return line;
}*/

void ClassicTimelineGraphicsManager::updateVisibleNotes(const kku::microsec &offset)
{
    (void)offset;
}

void ClassicTimelineGraphicsManager::fetchFirstNote(const kku::microsec& offset)
{
    (void)offset; // ????
}

void ClassicTimelineGraphicsManager::fetchLastNote(const kku::microsec& offset)
{
    (void)offset; // ????
}

bool ClassicTimelineGraphicsManager::nothingToDraw() const noexcept
{
    return true;
}

bool ClassicTimelineGraphicsManager::isVisiblyClose(const ClassicNote * const note, const kku::microsec& music_offset) const noexcept
{
    return note && music_offset;
}
