#ifndef CONFIGURATIONPAGE_H
#define CONFIGURATIONPAGE_H

#include <QWidget>
#include <QLabel>

#include "bmsinterface.h"
#include "debugprintpage.h"

namespace Ui {
class ConfigurationPage;
}

class ConfigurationPage : public QFrame
{
    Q_OBJECT

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

    enum ElementsPixelsPositions {
     PosSerialNumber = 0
    ,PosConfiguration = 240
    ,PosSoc = 490
    ,PosRestrictions = 770
    ,PosCellsConfiguration = 1150
    ,PosBalancingConfiguration = 1580
    ,PosOutputsSetting = 1860
    ,PosClaibrateZero = 2840
    };

    BMSInterface *bms() const;
    void setDieBieMS(BMSInterface *dieBieMS);
    void setDebugPrintPage(DebugPrintPage *page) {
        mPageDebugPrint = page;
    }

signals:
    void loadParams();
    void sendMessage(QString message);

    void showMessageDialog(const QString &title, const QString &msg, bool isGood, bool richText);

    //void sigBmsconfUpdateRequested();
    //void sigBmsconfUpdateRequestDefault();
    //void sigBmsconfUpdated();
    //void sigBmsconfStored();

private slots:
    void showStatusInfo(QString info, bool isGood);
    void onTimerSlot();

    void onBmsconfUpdatedOrStored();

    void onPbReadDefaultSettingsFromFileClicked();
    void onPbReadCurrentSettingsFromBmsClicked();
    void onPbWriteCurrentValuesToBmsClicked();
    void onPbWriteToNonVolatileBmsMemoryClicked();


    /*
    //void on_pbLoadSettingsFromFile_clicked();
    //void on_pbLoadCurrentSettingsFromBms_clicked();
    void on_pbWriteToNonVolatileBmsMemory_clicked();
    //void on_pbWriteCurrentValuesToBms_clicked();

    //void bmsconfUpdated();

    void on_pbReadDefaultSettingsFromFile_clicked();

    void on_pbReadCurrentSettingsFromBms_clicked();

    void on_pbWriteCurrentValuesToBms_clicked();
    */

private:
    Ui::ConfigurationPage *ui;

    BMSInterface *mDieBieMS;

    DebugPrintPage *mPageDebugPrint;

    void initTimerForStatusBar();
    void initTimerForProgressBar();
    void initTimerForOneSecondDelayAfterButtonClick();

    void onStartPercents();
    void onStopPercents();
    void onFinishPercents();

    void         processPercents();
    double       mSeconds = 0;
    const double mMaxSecs = 200;
    QTimer *mTimer;
    int mStatusInfoTime = 0;
    QTimer *mTimerProgress;
    QTimer *mOneSecondWait;
    bool mIsOneSedondPassed = true;
    bool mIsOperationFinished = true;

    void setPositionInPixelsToScrollTo(int positionInPixelsToScrollTo);
    void checkIfButtonTextFitsInButton();

    /*
    DebugPrintPage *mPageDebugPrint;

    QTimer *mTimer;
    int mStatusInfoTime;

    bool mMcConfRead = false;

    void setPositionInPixelsToScrollTo(int positionInPixelsToScrollTo);
    void checkIfButtonTextFitsInButton();
    */

};

#endif // CONFIGURATIONPAGE_H
