#pragma once

#include "classicmode/classicnote.h"
#include "graphics/classicgraphicsmanager.h"
#include "graphics/classicgraphicsfactory.h"
#include "core/timeline.h"
#include "core/spritecontainer.h"

#include "game/arrowelement.h"

#include "graphics/animations/classicflyinganimationscenario.h"
#include "graphics/animations/classicdyinganimationscenario.h"

class ClassicTimelineGraphicsManager : public ClassicGraphicsManager
{
public:
    explicit ClassicTimelineGraphicsManager(const std::shared_ptr<kku::Timeline<ClassicNote>>& timeline,
                                         const std::shared_ptr<ClassicGraphicsFactory>& factory,
                                         const kku::microsec& visibility_offset);

    virtual void input(kku::GameEvent&& input) override;
    virtual void display() const override;
    virtual void update(const kku::microsec& offset) override;

    virtual void update(const kku::microsec& offset, ClassicArrowNote* note) override;
    virtual void draw(const ClassicArrowNote * const note) const override;

protected:
    kku::SpriteContainer<Type, ClassicGraphicsFactory, ClassicNoteGraphics> _sprite_container;
    const std::shared_ptr<const ClassicGraphicsFactory> _factory;

    typedef typename std::set<ClassicNote*>::const_iterator Iterator;

    Iterator _first;
    Iterator _last;

    const std::shared_ptr<kku::Timeline<ClassicNote>> _timeline;
    kku::microsec _back_visibility_offset;
    kku::microsec _last_offset;

    inline bool nothingToDraw() const noexcept;
    inline bool isVisiblyClose(const ClassicNote * const note, const kku::microsec& music_offset) const noexcept;
    void fetchFirstNote(const kku::microsec& offset);
    void fetchLastNote(const kku::microsec& offset);
};
