//
// Created by sundagao on 2026/3/5.
//
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QCommandLineParser>
#include <QDebug>
#include <QQmlContext>
#include "../window-thumbnail-item.h"
#include "../workspace-thumbnail-item.h"
int main(int argc, char *argv[])
{
    QGuiApplication app(argc, argv);
    QGuiApplication::setApplicationName("window-thumbnail-item-test");
    QGuiApplication::setApplicationVersion("1.0");

    QCommandLineParser parser;
    parser.setApplicationDescription("WindowThumbnailItem Test");
    parser.addHelpOption();
    parser.addOption(QCommandLineOption("uuid", "Window UUID", "uuid", ""));
    parser.addOption(QCommandLineOption("output", "Output ID (for workspace)", "outputId", ""));
    parser.addOption(QCommandLineOption("type", "Test type: window or workspace", "type", "window"));
    parser.process(app);

    QString uuid = parser.value("uuid");

    qmlRegisterType<UkuiThumbnail::WindowThumbnailItem>("org.ukui.windowThumbnail.test", 1, 0, "WindowThumbnailItem");
    qmlRegisterType<UkuiThumbnail::WorkspaceThumbnailItem>("org.ukui.windowThumbnail.test", 1, 0, "WorkspaceThumbnailItem");

    QQmlApplicationEngine engine;
    engine.rootContext()->setContextProperty("testUuid", uuid);
    engine.rootContext()->setContextProperty("testOutputId", parser.value("output"));
    engine.rootContext()->setContextProperty("testType", parser.value("type"));

    const QUrl url(QStringLiteral("qrc:/main.qml"));
    QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
                     &app, [url](QObject *obj, const QUrl &objUrl) {
        if (!obj && url == objUrl)
            QCoreApplication::exit(-1);
    }, Qt::QueuedConnection);

    engine.load(url);

    return app.exec();
}