#pragma once
#include "events.hpp"
#include "fsm_events.hpp"
#include "simplefsm.hpp"
#include <SFML/Graphics.hpp>

namespace gui {
  namespace routing {
    enum class State {
      START,
      IDLE,
      MOUSE_ACTIVE,
      MOUSE_MOVING,
      MOUSE_DRAGGING
    };

    enum class Event {
      STARTED=0,
      MOUSE_DOWN=1,
      MOUSE_UP=2,
      MOUSE_MOVE=3,
      KEY_PRESS=4
    };

    class Router : public DeadSimpleFSM<State, Event> {
      public:
        sf::Vector2i position;
        sf::Keyboard::Scancode scancode;
        gui::Event $next_event = gui::Event::TICK;
        int move_count = 0;
        int $drag_tolerance = 4;

        void event(Event ev);

        void START(Event ev);
        void IDLE(Event ev);
        void MOUSE_ACTIVE(Event ev);
        void MOUSE_MOVING(Event ev);
        void MOUSE_DRAGGING(Event ev);

        gui::Event process_event(std::optional<sf::Event> ev);

        void set_event(gui::Event ev) {
          $next_event = ev;
        }
    };
  }
}
