#include "FormChargingRecordsItem.h"
#include "ui_FormChargingRecordsItem.h"

#include "LanguageManager.h"

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

    setBackgroundImage();

    connect(LanguageManager::instance(), &LanguageManager::languageChanged, this, [this]() { ui->retranslateUi(this); });
}

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

void FormChargingRecordsItem::setChargingRecordInfo(charging_record_info_t newCharging_record_info)
{
    m_charging_record_info = newCharging_record_info;
    updateShow();
}

void FormChargingRecordsItem::updateShow()
{
    ui->connector_id->setText(QString::number(m_charging_record_info.connector_id));
    ui->transaction_id->setText(QString::number(m_charging_record_info.transactionId));
    ui->start_Datetime->setText(m_charging_record_info.start_Datetime);
    ui->end_Datetime->setText(m_charging_record_info.end_Datetime);
    ui->start_MeterKWh->setText(QString::number(m_charging_record_info.start_MeterKWh));
    ui->end_MeterKWh->setText(QString::number(m_charging_record_info.end_MeterKWh));
}

void FormChargingRecordsItem::setBackgroundImage()
{
    m_background = new QLabel();
    ui->background_layout->addWidget(m_background, 0, 0, ui->background_layout->rowCount(), ui->background_layout->columnCount());

    m_background->setPixmap(QPixmap(":/images/charging/records_background.png"));
    m_background->lower();
    m_background->setScaledContents(true);
    m_background->setAlignment(Qt::AlignCenter);
}
