#include "core/appContext.h"
#include "core/track/Track.h"
#include "gui/mainWindow/mainWindow.h"

#include <iostream>
#include <quokka_gfx.h>
#include <sdi_toolBox/desktop/msw/win32Console.h>

using namespace std;
//--------------------------------------------------------------
int main(int argc, char *argv[])
{
  // Enable debug console for Windows platform
#ifdef DEBUG
  sdi_toolBox::desktop::msw::Win32Console::initConsole();
  // cout << "Debug mode enabled" << endl;
#endif

  // Main initialization
  AppContext appContext;

  // appContext.m_hServer->enable("127.0.0.1", 4000);

  // track.loadFromFile(R"(c:\Users\sschn\dev\projects\gitea.hub.saturnux.com\volaTile\do4.mid)");
  // track.loadFromFile(R"(c:\Users\sschn\dev\projects\gitea.hub.saturnux.com\volaTile\gameUP.mid)");
  appContext.player->loadFile(R"(c:\Users\sschn\dev\projects\gitea.hub.saturnux.com\volaTile\export.mid)");
  ////track.debug();

  //const auto     trackDuration  = track::Seconds(5);
  //auto           startTime      = track::Seconds();
  //constexpr auto stepInterval   = chrono::milliseconds(100);

  //track::ActiveNotes notes;     // Instance to hold the active notes at each time step with limited memory allocation overhead
  //while (startTime < trackDuration)
  //{
  //  const auto notesProxy = appContext.player->getNotes();
  //  notesProxy.getActiveNotesAt(startTime, WindowDuration, notes);

  //  ostringstream notesDisplay;
  //  notesDisplay << "Time: " << startTime << "\n";

  //  // Display the active notes for the current time step
  //  notesDisplay << "Active Notes:\n";
  //  for (const auto &note : notes.playing)
  //  {
  //    notesDisplay << format("{}{} ",
  //                           note.name,
  //                           note.octave);  
  //  }
  //  notesDisplay << "\n";

  //  // Display the upcoming notes for the current time step
  //  notesDisplay << "Upcoming Notes:\n";
  //  for (const auto &note : notes.upcoming)
  //  {
  //    notesDisplay << format("{}{} ",
  //                           note.name,
  //                           note.octave);  
  //  }
  //  notesDisplay << "\n";

  //  cout << notesDisplay.str() << endl;
  //  // Increase the start time by the step interval for the next iteration
  //  startTime += stepInterval;
  //}

  // Create an instance of the GUI application class
  quokka_gfx::Application app;
  const auto             &winManager = app.GetWindowManager();

  // Create and show the main window
  const auto mainWindow = new MainWindow(appContext, app);
  mainWindow->Show();

  // Start the main event loop
  cout << "System ready !" << endl;
  app.Run();

  return 0;
}
//--------------------------------------------------------------
