#ifndef FORMSTANDBY_H
#define FORMSTANDBY_H

#include <QWidget>
#include <QLabel>
#include <QMap>

#include "DataTypeDef.h"
#include "workspace/home/FormPrice.h"

namespace Ui {
class FormStandby;
}

class FormStandby : public QWidget
{
    Q_OBJECT

public:
    explicit FormStandby(QWidget *parent = nullptr);
    ~FormStandby();

    void setBackground(QLabel* label, const QString& imageUrl);

    void setTips(const QString& tips, int gun_index);

private:
    void initWidget();
    void initConnect();
    void initBackground();

    void initForms();
    void initForms_1();
    void initForms_2();

    void setChargeGunBackground();
    void setChargeProgressBackground();

    QStringList getGunErrorStringList(const QMap<uint8_t, QString>& error);
    bool isError(const QList<uint8_t>& error_list);

    uint8_t getMaxElement(const QList<uint8_t>& state_list);

    // 刷新充电枪图标相关 UI
    void refreshGunType(const QMap<uint8_t, QString>& type, int gun_id);
    void refreshGunType_1(const uint8_t& type, const QString& description);
    void refreshGunType_2(const uint8_t& type, const QString& description);

    //
    void refreshGunState(const QMap<uint8_t, QString>& state, int gun_id);
    void refreshGunState_1(const uint8_t& state);
    void refreshGunState_2(const uint8_t& state);

    void showForm_1(workspace_form_enum form);
    void showForm_2(workspace_form_enum form);

    void setCurrentChargeProgress(const charge_progress_enum& progress, const int& gun_id);
    void setCurrentChargeProgressText(const charge_progress_enum& progress, const int& gun_id);
    charge_progress_enum getChargeProgress(const workspace_form_enum& form);

    void setPlugInTextColor(const int& gun_id, const QString &color);
    void setAuthorizationTextColor(const int& gun_id, const QString &color);
    void setChargingTextColor(const int& gun_id, const QString &color);
    void setFinishedTextColor(const int& gun_id, const QString &color);

    void refreshChargeGunInfo();

    void setRestartVisible(bool visible, const int& gun_id);
    void setPriceVisible(bool visible, const int& gun_id);

private slots:
    void globalsValueChanged(const QString& key, const QVariant& value);

signals:
    void signalGunDetailClicked(int index);
    void signalStopCharge(int index);

private:
    Ui::FormStandby *ui;
    bool                                m_gun_error_1;
    bool                                m_gun_error_2;
    int                                 m_gun_num;

    workspace_form_enum                 m_currentForm;
    workspace_form_enum                 m_prevForm;

    QLabel*                             backgroundImage_1;
    QLabel*                             backgroundImage_2;
    QLabel*                             charge_progress_bg_image_1;
    QLabel*                             charge_progress_bg_image_2;

    QMap<workspace_form_enum, QWidget*> m_formMap_1;
    QMap<workspace_form_enum, QWidget*> m_formMap_2;

    FormPrice*                          m_price;
};

#endif // FORMSTANDBY_H
