#ifndef COUNTERSETTINGFORM_H
#define COUNTERSETTINGFORM_H

#include <QWidget>
#include <QButtonGroup>
#include <QFileDialog>
#include <QDoubleSpinBox>
#include <QCheckBox>
#include "common/ConstCache.h"
#include "common/utils/SettingConfig.h"

namespace Ui {
class CounterSettingForm;
}

class CounterSettingForm : public QWidget
{
    Q_OBJECT

public:
    explicit CounterSettingForm(QWidget *parent = nullptr);
    ~CounterSettingForm();
    void initCounterSelect();

    int getDisplayGroupFlag();

private slots:
    void on_btnSettingClose_clicked();

    void on_btnSetDialog_accepted();
    void on_btnSetDialog_rejected();

    void on_btnSelectDir_clicked();

    void on_selectCounter_currentIndexChanged(int index);
    void onActiveStateChanged();

    void on_btnChanelSetDialog_accepted();

    void on_btnChanelSetDialog_rejected();

private:
    Ui::CounterSettingForm *ui;

    QButtonGroup * flagGroup;
    QButtonGroup * countGroup;

    QVector<QCheckBox *> activeListLeft;
    QVector<QCheckBox *> activeListRight;
    QVector<QLineEdit *> clockListLeft;
    QVector<QLineEdit *> clockListRight;
    QVector<QDoubleSpinBox *> delayListLeft;
    QVector<QDoubleSpinBox *> delayListRight;

    void initDefaultSettings();
    void initChannelSettingTable();
    void clearChannelSettingValue();

    void enableChannel(int index, bool enable);
    bool isChannelSettingUpdated(int index, CounterChannel * channelPtr);

signals:
    void swiftDisplayLoop();
    void swiftDisplayCount();
    void channelSettingSubmit(QJsonArray channelSettings);
};

#endif // COUNTERSETTINGFORM_H
