#include "kwaFr_app.h"

#include "gui/mainFrame.h"
#include "misc/logConsoleGUI/logConsoleGUI.h"

#include <chrono>
#include <wx/image.h>

wxIMPLEMENT_APP(kwaFr_app);
using namespace std;
//--------------------------------------------------------------
/* Default destructor */
kwaFr_app::~kwaFr_app()
{
  // Clean up the application context
  m_coreManager.reset();
}
//--------------------------------------------------------------
bool kwaFr_app::OnInit()
{
  // Initialize the application context
  m_coreManager = make_unique<core::CoreManager>();

  // Initialize console
  logConsole = make_unique<sdiTools::logConsoleGUI>();
#ifdef DEBUG
  constexpr auto attachOnly = false;
  // logConsole->initConsole();
#else
  constexpr auto attachOnly = true;
#endif
  logConsole->initConsole(attachOnly);

  // wxWidgets configuration
  wxInitAllImageHandlers();

  // Creating the main frame
  const auto frame = new gui::MainFrame(m_coreManager->getBus());
  frame->Show();

  api::log::postLogMessage(m_coreManager->getBus(), "Application started");
  return true;
}
//--------------------------------------------------------------
int kwaFr_app::OnExit()
{
  // Application exit
  return wxApp::OnExit();
}
//--------------------------------------------------------------
