#include "directsaleform.h"
#include "ui_directsaleform.h"

DirectSaleForm::DirectSaleForm(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::DirectSaleForm)
{
    ui->setupUi(this);
    m_shopItem = QSharedPointer<DirectSaleItem>(new DirectSaleItem);

    m_binder.setData(m_shopItem.data());
    m_binder.registerBinding(ui->name);
    m_binder.registerBinding(ui->unitPrice);
    m_binder.registerBinding(ui->count);

    QList<ComboData> vt;
    vt << ComboData(Enums::NONE,tr("None"))
       << ComboData(Enums::HIGH,tr("High"))
       << ComboData(Enums::FIRST_LOWER,tr("First Lower"))
       << ComboData(Enums::SECOND_LOWER,tr("Second Lower"));

    m_binder.registerBinding(ui->vatType, vt);
    m_binder.bindToUi();
}

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

QSharedPointer<IShopItem> DirectSaleForm::shopItem() const
{
    return m_shopItem;
}

void DirectSaleForm::on_buttonBox_rejected()
{
    this->reject();
}

void DirectSaleForm::on_buttonBox_accepted()
{
    m_binder.bindToData();
    this->accept();
}
