#ifndef CONNECTANDENTERPAGE_H
#define CONNECTANDENTERPAGE_H

#include <QWidget>
#include <QDialog>
#include <QLabel>
#include <QProcess>

#include "bmsinterface.h"

#include "debugprintpage.h"

namespace Ui {
class ConnectAndEnterPage;
}

//class ConnectAndEnterPage : public QDialog
class ConnectAndEnterPage : public QWidget
{
    Q_OBJECT

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

    void initDieBieMS(BMSInterface *);

    void prepareWindowBeforeShow();

    bool    isConnectionPrepared();
    QString portToConnect();

    static const int SERIAL_BAUD_DEFAULT_VAL = 115200;

    BMSInterface *bms() const;
    void          setDieBieMS(BMSInterface *dieBieMS);
    void          setDieBieMSEx(BMSInterface *dieBieMS);
    void setDebugPrintPage(DebugPrintPage *page);


signals:
    void sigConnected();
    void sigReject();

private slots:
    void on_pbExit_clicked();

private slots:
    void showStatusInfo(QString info, bool isGood);
    void showMessageDialog(const QString &title, const QString &msg, bool isGood, bool richText);
    void serialPortNotWritable(const QString &port);
    void bmsconfUpdated();
    void bmsConfigCheckResult(QStringList paramsNotSet);

    void on_pbConnect_clicked();
    void on_pbSerialRefresh_clicked();

    void onComboBoxSerialPortOpened();
    void onComboBoxSerialPortClosed();

    void on_gbWindow_clicked();

    void on_gbHeader_clicked();

    void on_pbLanguage_clicked();

private:
    Ui::ConnectAndEnterPage *ui;
    BMSInterface *           mDieBieMS;
    bool                     mIsConnected;
    // QString mPortForConnection;

    // QLabel *mStatusLabel;
    DebugPrintPage *mPageDebugPrint;


    int  mStatusInfoTime;
    bool mKeyLeft;
    bool mKeyRight;
    bool mMcConfRead;



    bool    waitProcess(QProcess &process, bool block = true, int timeoutMs = 300000);
    QString runCmd(QString cmd, QStringList args);

    void clearPortToConnect();

    void ShowContextMenu(const QPoint &pos);


};

#endif // CONNECTANDENTERPAGE_H
