#pragma once

#include "eventBus/eventBus.h"

#include <wx/webview.h>
#include <memory>
#include <wx/wx.h>

// Forward declarations
namespace core
{
class Context;
}
namespace gui
{
class UiEventHandler;
}

// Main application frame
namespace gui
{

//--------------------------------------------------------------
class MainFrame : public wxFrame
  , public eventBus::Node
{
  friend class UiEventHandler;

  using json = nlohmann::ordered_json;

  public:
  MainFrame() = delete;                                        // Default constructor
  virtual ~MainFrame();                                        // Default destructor
  MainFrame(const MainFrame &obj)                = delete;     // Copy constructor
  MainFrame(MainFrame &&obj) noexcept            = delete;     // Move constructor
  MainFrame &operator=(const MainFrame &obj)     = delete;     // Copy assignment operator
  MainFrame &operator=(MainFrame &&obj) noexcept = delete;     // Move assignment operator

  explicit MainFrame(core::Context &ctx);     // Constructor

  protected:
  core::Context                  &m_ctx;                // Application context
  std::unique_ptr<UiEventHandler> m_uiEventHandler;     // UI event handler

  // Controls
  wxWebView *m_browser = nullptr;

  private:
  void createControls();     // Creating controls

  // Events
  void onScriptMessage(wxWebViewEvent &event);     // UI message handler
};
//--------------------------------------------------------------
}     // namespace gui
