#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include "core/modelmanager.h"
#include "base/launcheritem.h"
//#include "KylinItemView/kquickgridview.h"
#include "logger.h"

int main(int argc, char *argv[])
{
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
    QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#endif

    QGuiApplication app(argc, argv);

    QQmlApplicationEngine engine;

#if 0
    ModelManager modelMgr;
    MultiPageModel launcherModel;

    const QString names[9] = {
        "red", "green", "blue",
        "yellow", "gray", "pink",
        "darkBlue", "lightGray", "purple"
    };
    const int types[9] = { 0, 0, 1, 0, 1, 1, 1, 0, 1 };
    for (int page=0; page<3; ++page) {
        PageModel *pModel = new PageModel;
        for (int index=0; index<9; ++index) {
            LauncherItem *item = new LauncherItem;
            item->setName(names[index % 9]);
            item->setType(types[index % 9]);
            item->setPageIndex(page);
            pModel->append(item);
        }
        launcherModel.append(pModel);
    }
    modelMgr.setPageModel(launcherModel);
    engine.rootContext()->setContextProperty("modelManager", &modelMgr);

    qmlRegisterType<LauncherItem>("org.ukui.tablet", 1, 0, "LauncerItem");

    qmlRegisterType<ModelManager>("com.test", 1, 0, "ModelManager");
    qmlRegisterType<KQuickGridView>("com.test", 1, 0, "KGridView");
    qmlRegisterType<LauncherItem>("com.test", 1, 0, "LauncherItem");
    common::QmlLogger logger;
    qInstallMessageHandler(common::Logger::outputMessage);
    engine.rootContext()->setContextProperty("qmlLogger", &logger);
#endif

    ModelManager modelMgr;
    engine.rootContext()->setContextProperty("modelManager", &modelMgr);
    qmlRegisterType<LauncherItem>("org.ukui.tablet", 1, 0, "LauncherItem");
    qmlRegisterType<CategoryItem>("org.ukui.tablet", 1, 0, "CategoryItem");
    const QUrl url(QStringLiteral("qrc:/andApp.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();
}
