#ifndef __screen
#define __screen

#include <Adafruit_GFX.h>
#include "include/config.h"


class ScreenManager;


enum class Button
{
  Up = 0,
  Menu = 1,
  Down = 2
};


class BaseScreen
{
  public:
    BaseScreen(ScreenManager* screenManager)
    {
      this->screenManager = screenManager;
    }

    virtual ~BaseScreen() {}

    virtual void onShow() = 0;
    virtual void onButton(Button button) = 0;
    virtual void onTick() = 0;

  protected:
    ScreenManager* getScreenManager() { return this->screenManager; }
    Adafruit_GFX* getDisplay();

  private:
    ScreenManager* screenManager;
};



class ScreenManager
{
  public:
    ScreenManager(Adafruit_GFX* display)
    {
      this->display = display;
    }

    inline void tick() { this->getCurrentScreen()->onTick(); }

    inline BaseScreen* getCurrentScreen() { return this->currentScreen; }
    inline Adafruit_GFX* getDisplay() { return this->display; }


    template<class T> void show()
    {
      if (this->currentScreen != nullptr)
      {
        //currentScreen->onHide();
        delete this->currentScreen;
      }

      this->currentScreen = new T(this);
      this->currentScreen->onShow();
    }

  private:
    Adafruit_GFX* display;

    BaseScreen* currentScreen = nullptr;
};

#endif
