#include "chooseversiondialog.h"
#include "ui_chooseversiondialog.h"

#include "models/settings.h"
#include "widgets/mainwindow.h"
#include "constants.h"

ChooseVersionDialog::ChooseVersionDialog(LotroDatManager* mgr, QWidget *parent) :
    mgr_(mgr),
    QWidget(parent),
    ui(new Ui::ChooseVersionDialog)
{
//    setWindowModality(Qt::WindowModal);
    ui->setupUi(this);
    ui->wait_widget->hide();
    ui->cancel_widget->show();
}

ChooseVersionDialog::~ChooseVersionDialog()
{
    delete ui;
}

void ChooseVersionDialog::updateFontsSizes()
{
    ui->label_title->setFont(garamond_12pt);
}

void ChooseVersionDialog::resizeEvent(QResizeEvent *event)
{
    updateFontsSizes();
}

void ChooseVersionDialog::show()
{
    QString locale_prefix = Settings::getValue("Lotro/original_locale").toString();
    ui->start_original->setStyleSheet("QWidget#start_original{\n	border: 0;\n	border-image: url(:/buttons/run_" + locale_prefix + ".png);\n}\n\nQWidget#start_original:hover{\n	border: 3px;\n	border-image: url(:/buttons/run_" + locale_prefix + ".png);\n}");
    QWidget::show();
}

void ChooseVersionDialog::on_start_patched_clicked()
{
    ui->wait_widget->show();
    ui->cancel_widget->hide();
    QMetaObject::invokeMethod(mgr_, "startGame", Qt::QueuedConnection, Q_ARG(LOTRO_DAT::DatLocaleManager::LOCALE, LOTRO_DAT::DatLocaleManager::PATCHED));
}

void ChooseVersionDialog::on_start_original_clicked()
{
    ui->wait_widget->show();
    ui->cancel_widget->hide();
    QMetaObject::invokeMethod(mgr_, "startGame", Qt::QueuedConnection, Q_ARG(LOTRO_DAT::DatLocaleManager::LOCALE, LOTRO_DAT::DatLocaleManager::ORIGINAL));
}

void ChooseVersionDialog::on_cancel_clicked()
{
    hide();
    emit cancelled();
}
