#include "ordertypeform.h"
#include "ui_ordertypeform.h"


OrderTypeForm::OrderTypeForm(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::OrderTypeForm)
{
    ui->setupUi(this);
    _order_id = "";
    _order_status = DefaultOrder;
    _refund_status = DefaultOrder;
    _order_type = DefaultOrderType;
}

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

void OrderTypeForm::InitShow(QString order_id, int order_status, int refund_status, int order_type)
{
    _order_id = order_id;
    _order_status = order_status;
    _refund_status = refund_status;
    _order_type = order_type;

    if(_order_type == AppointmentTakeout || _order_type == AppointmentDining || _order_type == AppointmentInvite)
    {
        ui->ordertypelabel_type->setStyleSheet("#ordertypelabel_type{ border-image: url(:yy.png)}");
    }

    int ordertype = GetOrderStatus();

    SetNameStyle(ordertype);

}

void OrderTypeForm::SetNameStyle(int status)
{
    switch (status) {
    case NewOrder:
        ui->ordertypelabel_name->setText(QString::fromUtf8("\xE6\x96\xB0\xE8\xAE\xA2\xE5\x8D\x95"));
        ui->ordertypelabel_name->setStyleSheet("#ordertypelabel_name{border:1px solid rgba(236,67,56,1);border-radius:4px;color:rgba(236,67,56,1);}");
        break;
    case FirmOrder:
        ui->ordertypelabel_name->setText(QString::fromUtf8("\xE5\x88\xB6\xE4\xBD\x9C\xE4\xB8\xAD"));
        ui->ordertypelabel_name->setStyleSheet("#ordertypelabel_name{border:1px solid rgba(25,166,119,1);border-radius:4px;color:rgba(25,166,119,1);}");
        break;
    case CancelOrder:
    case CompleteRefundOrder:
    case ApprovalRefundOrder:
        ui->ordertypelabel_name->setText(QString::fromUtf8("\xE5\xB7\xB2\xE9\x80\x80\xE5\x8D\x95"));
        ui->ordertypelabel_name->setStyleSheet("#ordertypelabel_name{border:1px solid rgba(170,170,170,1);border-radius:4px;color:rgba(170,170,170,1);}");
        break;
    case DispatchingOrder:
        ui->ordertypelabel_name->setText(QString::fromUtf8("\xE9\x85\x8D\xE9\x80\x81\xE4\xB8\xAD"));
        ui->ordertypelabel_name->setStyleSheet("#ordertypelabel_name{border:1px solid rgba(25,108,166,1);border-radius:4px;color:rgba(25,108,166,1);}");
        break;
    case InDevelopment:
        ui->ordertypelabel_name->setText(QString::fromUtf8("\xE5\xAE\x8C\xE6\x88\x90\xE4\xB8\xAD"));
        ui->ordertypelabel_name->setStyleSheet("#ordertypelabel_name{border:1px solid rgba(25,108,166,1);border-radius:4px;color:rgba(25,108,166,1);}");
        break;
    case ApplicationRefundOrder:
    case ApplicationPartialRefundOrder:
        ui->ordertypelabel_name->setText(QString::fromUtf8("\xE9\x9C\x80\xE9\x80\x80\xE5\x8D\x95"));
        ui->ordertypelabel_name->setStyleSheet("#ordertypelabel_name{border:1px solid rgba(236,67,56,1);border-radius:4px;color:rgba(236,67,56,1);}");
        break;
    case CompleteOrder:
    case ServiceOrder:
        ui->ordertypelabel_name->setText(QString::fromUtf8("\xE5\xB7\xB2\xE5\xAE\x8C\xE6\x88\x90"));
        ui->ordertypelabel_name->setStyleSheet("#ordertypelabel_name{border:1px solid rgba(170,170,170,1);border-radius:4px;color:rgba(170,170,170,1);}");
        break;
    default:
        ui->ordertypelabel_name->setText(QString::fromUtf8("\xE6\x97\xA0\xE6\x95\x88\xE5\x8D\x95"));
        ui->ordertypelabel_name->setStyleSheet("#ordertypelabel_name{border:1px solid rgba(170,170,170,1);border-radius:4px;color:rgba(170,170,170,1);}");
        break;
    }
}

void OrderTypeForm::on_orderstatus_changed(int order_status, int refund_status)
{

}

int OrderTypeForm::order_type() const
{
    return _order_type;
}

int OrderTypeForm::refund_status() const
{
    return _refund_status;
}

int OrderTypeForm::GetOrderStatus() const
{
    if(_refund_status == ApplicationRefundOrder ||
            _refund_status == ApplicationPartialRefundOrder ||
           _refund_status == CompleteRefundOrder ||
            _refund_status == ApprovalRefundOrder)
        return _refund_status;
    else
        return _order_status;
}

int OrderTypeForm::order_status() const
{
    return _order_status;
}

QString OrderTypeForm::order_id() const
{
    return _order_id;
}
