#include "try_engine/try_engine.hpp"

#include "content/content.hpp"

#include "layers/gui/browser/navigation/navigation.hpp"
#include "layers/gui/browser/history/history.hpp"
#include "layers/gui/browser/preview/preview.hpp"
#include "layers/gui/dialogs/dialogs.hpp"

namespace rrr 
{
  using event_manager = try_engine::app_event::event;

  class rrr_impl : public try_engine::application
  {
    public:
      rrr_impl(std::string app_name) : try_engine::application{ app_name }
      { 
        // HERE
        // убрать это в релизе
        cnt.set_pwd("/mnt/develop/projects/cpp/rrr/dir_for_tests");
        cnt.fill(); 
      };
      ~rrr_impl() = default;

    public:
      template<typename... Args>
      void push_layer(Args... args) 
      { 
        (args->set_event_manager(&em), ...); 
        (args->set_content(&cnt), ...); 
        try_engine::application::push_layer(args...); 
      }

    private:
      event_manager em;
      content cnt;
  };
}

namespace try_engine
{
  inline application& create()
  {
    static  rrr::rrr_impl e { "rrr.v2" };

    e.push_layer(
      new rrr::layers::gui::history{},
      new rrr::layers::gui::navigation{},
      new rrr::layers::gui::preview{},
      new rrr::layers::gui::dialogs{}
    );

    e.attach_layers();

    return e;
  }
}
