#include <UIGearsQtLib/UIGQLabel.h>
#include <UIGearsQtLib/UIGQProgressBar.h>
#include <UIGearsQtLib/UIGQPushButton.h>
#include <UIGearsQtLib/UIGQSlider.h>
#include <UIGearsQtLib/UIGearsQtLib.h>

#include <QtCore/QDir>
#include <QtWidgets/QApplication>
#include <QtWidgets/QLabel>
#include <QtWidgets/QVBoxLayout>

namespace
{
void loadTrialTheme()
{
    const QString themeDir = QDir(QCoreApplication::applicationDirPath()).filePath(QStringLiteral("theme1"));
    if (!QDir(themeDir).exists())
    {
        return;
    }

    const QByteArray nativePath = QDir::toNativeSeparators(themeDir).toLocal8Bit();
    UIGQtLib::uigLoadThemeDir(nativePath.constData());
}
}

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

    UIGQtLib::init();
    UIGQtLib::UIGGlobalConfig config;
    config.globalFontFamily = QStringLiteral("Microsoft YaHei");
    config.buttonFadeEnabled = true;
    UIGQtLib::uigSetGlobalConfig(config);
    loadTrialTheme();

    QWidget window;
    window.setWindowTitle(QStringLiteral("Qt-UI WidgetKit demo_code"));
    window.resize(560, 360);

    QVBoxLayout* layout = new QVBoxLayout(&window);
    layout->setContentsMargins(24, 24, 24, 24);
    layout->setSpacing(14);

    UIGQtLib::UIGQLabel* title = new UIGQtLib::UIGQLabel(&window);
    title->setText(QStringLiteral("WidgetKit static library integration"));
    title->setColor(QColor(31, 41, 55));
    layout->addWidget(title);

    QLabel* hint = new QLabel(QStringLiteral("Built from ../include and ../lib/UIGearsQtLib.lib"), &window);
    layout->addWidget(hint);

    UIGQtLib::UIGQProgressBar* progress = new UIGQtLib::UIGQProgressBar(&window);
    progress->setRange(0, 100);
    progress->setValue(42);
    progress->setShowText(true);
    layout->addWidget(progress);

    UIGQtLib::UIGQSlider* slider = new UIGQtLib::UIGQSlider(&window, Qt::Horizontal);
    slider->setRange(0, 100);
    slider->setValue(progress->value());
    layout->addWidget(slider);
    QObject::connect(slider, &QSlider::valueChanged, progress, &QProgressBar::setValue);

    UIGQtLib::UIGQPushButton* button = new UIGQtLib::UIGQPushButton(&window);
    button->setText(QStringLiteral("Advance"));
    layout->addWidget(button);
    QObject::connect(button, &QPushButton::clicked, progress, [progress]() {
        progress->setValue((progress->value() + 10) % 101);
    });

    window.show();
    const int result = app.exec();
    UIGQtLib::shutdown();
    return result;
}
