#include "Login.h"
#include "OriginalWnd/OriginalWnd.h"
#include "ui_Login.h"
#include <QStackedWidget>
#include <qDebug>
#include <QSettings>

Login::Login(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::Login)
{
    ui->setupUi(this);

    initForm();
}

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

void Login::initForm()
{
    QPixmap pixmap(":/images/logo.png");
    QPixmap scaledPixmap = pixmap.scaled(283, 40, Qt::KeepAspectRatio);
    ui->label_logo->setPixmap(scaledPixmap);

    ui->userNameLineEdit->setPlaceholderText("Please enter the account number");
    ui->passLineEdit->setPlaceholderText("Please enter your password");

    connect(ui->userNameLineEdit, &QLineEdit::textChanged, this, &Login::onUserNameChanged);
}

void Login::onUserNameChanged(const QString &userName) {
    QSettings settings("YourCompany_2", "YourAppName_2");
    settings.setValue("userName", userName);
}

void Login::on_SinginButton_clicked()
{
    if (QStackedWidget *parent = qobject_cast<QStackedWidget*>(this->parentWidget())) {
        OriginalWnd *originalWnd = new OriginalWnd(this);
        parent->addWidget(originalWnd);
        parent->setCurrentIndex(parent->indexOf(originalWnd));
    }
}
