#ifndef CTRLADVANCEDPANEL_H
#define CTRLADVANCEDPANEL_H

#include "wDevicesManager/ledcard.h"
#include "communication/hpptclient.h"
#include "base/loemptydialog.h"
#include <QLineEdit>
#include <QTextEdit>
#include <QJsonObject>
#include <QGroupBox>
#include <QRadioButton>
#include <QCheckBox>
#include <QFile>
#include <QThread>

class CtrlAdvancedPanel : public QWidget {
    Q_OBJECT
public:
    explicit CtrlAdvancedPanel(QWidget *parent = nullptr,QList<LedCard *> *m_pLedlist=nullptr);
    ~CtrlAdvancedPanel();
protected:
    void showEvent(QShowEvent *event) override;
    void init();
    void changeEvent(QEvent *) override;
    void transUi();

    void keyReleaseEvent(QKeyEvent *) override;
    void mouseReleaseEvent(QMouseEvent *) override;

protected slots:
    void On0degrees();
    void On90degrees();
    void On180degrees();
    void On270degrees();
    void OnSendMinBrightness();
    void OnSendMaxBrightness();
    void OnGetMinBrightness();
    void OnGetMaxBrightness();
    void OnSendCustomJson();
signals:
    void sigSend(QJsonObject &,QString);
    void sigSetTipTextContent(QString);
protected slots:
    void DeletePostingDlg();
    void OnProHttpResponse(QString url, QString postMD5, QByteArray data);
    void OnProHttpResponseAll(QString url, QString postMD5, QByteArray data);
    void OnSetRealtimeServer();
    void OnClearRealtimeServer();
    void OnStartConfigLedScreenSoft();
    void OnRestart();
    void OnFpgaUpgrade();
    void OnFpgaVerCheck();
    void OnSyncFpgaVer();
    void slotUploadFinished();
    void slotUploadFpgaFinished();
    void slotUploadProgress(qint64 A,qint64 B);
    void OnM80Set();
    void OnM80Refresh();
    void OnM80Restore();
    void OnSetTaxiTopScreen();
    void OnReadbackTaxiTopScreen();
    void OnOpenAdb();
private:
    QList<LedCard *> *m_pLedlist=nullptr;
    LedCard   *m_pLedCard = nullptr;
    HpptClient *pHpptClient = nullptr;
    HpptClient *pHpptClientAll = nullptr;
    QString m_strUrl="";
    QString m_strStartUrl="";
    LoEmptyDialog * m_PostingDlg=nullptr;
    QTimer *m_pGetAskTimer=nullptr;
    bool m_passwordOk=false;
    QString m_strUpgradeApkFile="";
    QString m_strUpgradeFpgaFile="";
    QJsonObject mM80Map;
    bool m_lockFlag=true;
    void UpLoadForm(QString Path, QMap<QString,QString> params, QString fileFormName, QFile *uploadFile, int iType);

    QLabel *lbTitle;
    QLabel *lbScreenWidth;
    QLineEdit *fdScreenWidth;
    QLabel *lbScreenHeight;
    QLineEdit *fdScreenHeight;
    QPushButton *btnScreenSet;
    QLabel *lbAlias;
    QLineEdit *fdAlias;
    QPushButton *btnAliasSet;
    QLabel *labelWebServer;
    QComboBox *fdWebServerAddr;
    QLabel *lbCompanyId;
    QLineEdit *fdCompanyId;
    QPushButton *btnWebServerSet;
    QLabel *label;
    QComboBox *comboBox_realtimeServer;
    QPushButton *pushButtonSetREaltimeServer;
    QPushButton *pushButtonClearRealtimerAddress;
    QPushButton *btnApkCheck;
    QPushButton *btnApkUpgrade;
    QComboBox *fdPkg;
    QPushButton *fdUnload;
    QPushButton *btnRunningCheck;
    QPushButton *pushButtonFpgaUpgrade;
    QPushButton *pushButtonFpgaVerCheck;
    QPushButton *pushButtonSyncFpgaVer;
    QPushButton *pushButtonRestart;
    QPushButton *btnClearProg;
    QPushButton *btnGetLog;
    QPushButton *btnSetBack, *btnPlayerBackSet, *btnPlayerBackClear;

    QGroupBox *groupM80;
    QComboBox *fdM80;
    QPushButton *btnM80Set;
    QPushButton *btnM80Refresh;
    QPushButton *btnM80Restore;
    QGroupBox *groupTopLevel;
    QRadioButton *fdTopLevelHL;
    QRadioButton *fdTopLevelLH;
    QPushButton *btnSetTopLevel;
    QPushButton *btnGetTopLevel;
    QPushButton *btnLedSet3;
    QPushButton *btnLedSet4;
    QPushButton *btnBindTaxiIc;

    QGroupBox *groupBoxRotate;
    QRadioButton *radioButton0degrees;
    QRadioButton *radioButton90degrees;
    QRadioButton *radioButton180degrees;
    QRadioButton *radioButton270degrees;
    QGroupBox *groupBoxMinMaxBrightness;
    QLabel *lbMinBright;
    QLineEdit *fdMinBright;
    QLabel *lbMinBrightTip;
    QPushButton *btnMinBrightGet;
    QPushButton *btnMinBrightSet;
    QLabel *label_3;
    QLineEdit *lineEdit_4;
    QLabel *label_5;
    QPushButton *pushButtonReadbackMaxBrightess;
    QPushButton *pushButtonSendMaxBrightness;

    QGroupBox *grpBoxHiddenSettings;
    QPushButton *btnSysUpd;
    QLabel *lbBaudCfg, *lbBaudModel, *lbUart, *lbBaud;
    QPushButton *btnBaudSet, *btnBaudGet;
    QCheckBox *fdIsOpenADB;
    QLabel *lbCustomJson;
    QTextEdit *fdCustomJson;
    QPushButton *btnSendCustomJson;
};

class PlayerBackSendThread : public QThread {
    Q_OBJECT
public:
    PlayerBackSendThread(const QString &file, const QString &ip);
    QString file, ip;
    QString err;
protected:
    void run();
signals:
    void emErr(QString);
};

#endif // CTRLADVANCEDPANEL_H
