#include "dialogeditinstructor.h"
#include "ui_dialogeditinstructor.h"

DialogEditInstructor::DialogEditInstructor(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::DialogEditInstructor),
    instructorInput()
{
    ui->setupUi(this);
}

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

void DialogEditInstructor::setInstructor(Instructor instructor)
{
    instructorInput = instructor;

    ui->editName ->setText(instructor.getName());
    ui->editLogin->setText(instructor.getLogin());
    ui->editPassword->setText(instructor.getPassword());

    ui->checkIsAdmin->setChecked(instructor.getIsAdmin());
    ui->checkArchived->setChecked(instructor.getArchived());
    ui->checkLoggedIn->setChecked(instructor.getLoggedIn());

    if(instructor.getIsAdmin())
        ui->editName->setEnabled(false);
    else
        ui->editName->setEnabled(true);
}

Instructor DialogEditInstructor::getInstructor()
{
    Instructor instructor = instructorInput;

    instructor.setName(ui->editName->text());
    instructor.setLogin(ui->editLogin->text());
    instructor.setPassword(ui->editPassword->text());

    instructor.setIsAdmin(ui->checkIsAdmin->isChecked());
    instructor.setArchived(ui->checkArchived->isChecked());
    instructor.setLoggedIn(ui->checkLoggedIn->isChecked());

    return instructor;
}
