#include "logger.hpp"
#include "playlist-controller.hpp"
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include <QUrl>
#include <filesystem>

int main(int argc, char *argv[]) {
  qInstallMessageHandler(MessageHandler);
  std::filesystem::path cwd = std::filesystem::current_path();
  Logger::info(cwd.string());

  QGuiApplication app(argc, argv);

  QQmlApplicationEngine engine;

  PlaylistController playlist;
  engine.rootContext()->setContextProperty("playlist", &playlist);

  const QUrl url(QStringLiteral("qrc:/App/ui/main.qml"));

  QObject::connect(
      &engine, &QQmlApplicationEngine::objectCreationFailed, &app,
      []() { QCoreApplication::exit(-1); }, Qt::QueuedConnection);

  engine.load(url);

  Logger::info("Engine loaded");

  playlist.addToQueue("../ui/media/video.mp4");
  playlist.addToQueue("../ui/media/Puta.mp4");

  return app.exec();
}
