#include <QApplication>
#include <QFile>
#include <QQuickWindow>  // 关键头文件
#include <QTextStream>

#include "backendapimanager.h"
#include "fireWidget/firingwidget.h"
#include "logger.h"
#include "loginwindow.h"
#include "mainwindow.h"

int main(int argc, char *argv[]) {
    QApplication app(argc, argv);

    QQuickWindow::setSceneGraphBackend("software");  // 兼容性： 禁用GPU

    // 加载 QSS 文件
    QFile styleFile(":/qss/qss/tableview.qss");
    if (styleFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
        QTextStream stream(&styleFile);
        QString styleSheet = stream.readAll();
        app.setStyleSheet(styleSheet);
        styleFile.close();
    }
    // // 获取屏幕信息
    // QScreen *screen = QGuiApplication::primaryScreen();
    // QRect screenGeometry = screen->geometry();
    // int screenWidth = screenGeometry.width();
    // int screenHeight = screenGeometry.height();

    // logger
    Logger::getInstance("application.log");

    Logger::getInstance().setMaxFileSize(2 * 1024 * 1024);  // 2 MB
    Logger::getInstance().setMaxBackupFiles(3);             // Keep 3 backup files
    Logger::getInstance().info("Application started from main.");

    backendAPIManager::initialize(apiBackendUrl.toString());

    // MainWindow w;
    //  Page w;
    //  pageTest w;
    LoginWindow w;
    // loginWindow.show();
    // 设置应用程序图标
    app.setWindowIcon(QIcon(":/icons/icons/l634z-aceaj-001.ico"));
    // w.resize(screenWidth * 1, screenHeight * 0.95);
    // firingWidget w;
    w.show();
    return app.exec();
}
