#ifndef DIALOGWEEKDAYDETAIL_H
#define DIALOGWEEKDAYDETAIL_H

#include <QLabel>
#include <QDialog>
#include <QTableWidgetItem>

#include "DataTypeDef.h"
#include "DialogLimitEdit.h"

namespace Ui {
class DialogWeekDayDetail;
}

struct GeneralInfo {
    int curDay;
    QString startTime;
    QString chargingRateUnit;
};

class DialogWeekDayDetail : public QDialog
{
    Q_OBJECT

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

    GeneralInfo getGeneralInfo() const;
    void setGeneralInfo(const GeneralInfo &newGeneralInfo);

    void setInfo_list(const QList<charging_schedule_period_info_t> &newInfo_list);

    QList<charging_schedule_period_info_t> info_list() const;

private:
    void initWidget();
    void setBackground();
    void initTableWidget();
    void initConnect();

    void refreshData();
    void refreshTitles(const int& dayOfWeek);
    void updateData(const charging_schedule_period_info_t& info, const int& index);

    void appendTableWidgetItem(const QString& startPeriod, const QString& limit, const QString& chargingRateUnit);

    bool isExistByStartPeriod(const int& startPeriod);

    void centerWindow();

signals:
    void valueChanged();

private slots:
    void onItemDoubleClicked(QTableWidgetItem* item);
    void addBtnClicked();
    void deleteBtnClicked();

protected:
    void showEvent(QShowEvent* event) override;

private:
    Ui::DialogWeekDayDetail *ui;
    QLabel* m_background;
    GeneralInfo generalInfo;
    QList<charging_schedule_period_info_t> m_info_list;
    QSharedPointer<DialogLimitEdit> m_limit_dialog;
};

#endif // DIALOGWEEKDAYDETAIL_H
