#ifndef DEVICEITEM_H
#define DEVICEITEM_H
#include <QTreeWidget>
#include <QDir>
#include <QDateTime>
#include <QJsonObject>
#include <QJsonDocument>
#include <QPushButton>
#include <base/loqtreewidget.h>
#include <device/ledcard.h>
#include <communication/hpptclient.h>
#include <QLabel>
#include <QMap>
#include <base/loemptydialog.h>

enum DeviceTableField {
    DeviceTable_Check = 0,
    DeviceTable_ID,
    DeviceTable_Online,
    DeviceTable_IP,
    DeviceTable_ScreenSize,
    DeviceTable_Remark,
    DeviceTable_Brightness,
    DeviceTable_Power,
    DeviceTable_Password,
    DeviceTable_Info,
    DeviceTable_Screenshot,
    DeviceTable_End,
};

class DeviceItem : public QObject, public QTreeWidgetItem {
    friend class DevicePanel;
    Q_OBJECT
public:
    explicit DeviceItem(LedCard *pLedCard, LoQTreeWidget *parent = nullptr,QWidget *pWnd=nullptr);
     ~DeviceItem();
    void HttpPostByTypeJsonObject(QJsonObject json);
    void OnControlTcpSend(int iProgramIndex);

    void refreshLable();
    void SetMainTabWidgetIndex(int index);
//http获取控制卡信息的函数
    void HttpGetLedCardWidthHeight();
    void HttpGetLedCardRemarkName();
    QPixmap Base64_To_Image(QByteArray bytearray,QString SavePath);

    LedCard *mCard{0};
    QTimer mHeartbeatTimer;
signals:
    void sigOutputInfo(QString);

public slots:
    void DeletePostingDlg();
    void OnProHttpResponse(QString url, QString postMD5, QByteArray data);
    void DeviceItemHttpPost();
protected slots:
    void onReadbackPic();
    void onVerifyLockPassword();
private:
    int m_intIndexFlagOfInfoOrControl=0;
    void SetPasswordItem(LedCard *p);
private:
    QPushButton *m_bnCardDetailInfo = nullptr;//
    QPushButton *m_bnReadbackPic = nullptr;//
    QPushButton *m_bnLock = nullptr;//
    QLabel *m_ImageOnline=nullptr;


    LoQTreeWidget *m_parent = nullptr;
    HpptClient *pHpptClient = nullptr;
    QString m_strUrl="";
    QWidget *m_pWnd=nullptr;
    int m_HeartbeatCount=0;
    LoEmptyDialog * m_PostingDlg=nullptr;
    QTimer *m_pGetAskTimer=nullptr;
};

class ImgDlg : public QDialog {
public:
    explicit ImgDlg(const QByteArray &, QWidget *parent = 0);
    QImage mImg;
public:
    void paintEvent(QPaintEvent *) override;
};
#endif // DEVICEITEM_H