#ifndef FORMTXDUFAULTPROFILE_H
#define FORMTXDUFAULTPROFILE_H

#include <QWidget>
#include <QListWidgetItem>
#include <QTableWidgetItem>
#include <QStyledItemDelegate>
#include <QStyleOptionViewItem>

#include "BaseWidget.h"
#include "DataTypeDef.h"
#include "OcppSettings/ChargingProfiles/DialogLimitEdit.h"
#include "OcppSettings/ChargingProfiles/DialogWeekDayDetail.h"

namespace Ui {
class FormTxDufaultProfile;
}

class FormTxDufaultProfile : public BaseWidget
{
    Q_OBJECT

public:
    explicit FormTxDufaultProfile(BaseWidget *parent = nullptr);
    ~FormTxDufaultProfile();

    bool returnParent() override;

    charging_profiles_detail_info_t profile_info() const;
    void setProfile_info(charging_profiles_detail_info_t newProfile_info);

private:
    void initWidget();
    void initConnect();
    void initComboBox();
    void initStackLevelComboBox();
    void initTableWidget();
    void initListWidget();

    void refreshData();
    void refreshGeneralData();
    void refreshDailyData();
    void refreshWeeklyData();
    void refreshDefaultData();
    void appendRowTableWidget(const QString& startTime,
                              const QString& limitType,
                              const QString& limit);

    bool updateData();

    QList<charging_schedule_period_info_t> getDayOfWeekLimitList(const QList<charging_schedule_period_info_t>& dataList,
                                                                 const QString& startTime,
                                                                 const int& curDay);

    bool isDayOfWeek(const QString& startTime, const int& curDay, const int& seconds);
    void updateWeekPeriodList(QList<charging_schedule_period_info_t>& dataList,
                              const QList<charging_schedule_period_info_t>& newDataList,
                              const QString& startTime,
                              const int& curDay);
    int indexOfWeekPeriodList(const QList<charging_schedule_period_info_t>& dataList,
                              const charging_schedule_period_info_t& data);

private slots:
    void dialyTableWidgetClicked(QTableWidgetItem* item);
    void weekdayTableWidgetDoubleClicked(QListWidgetItem* item);
    void addBtnClicked();
    void deleteBtnClicked();

protected:
    void showEvent(QShowEvent* event) override;

private:
    Ui::FormTxDufaultProfile *ui;
    charging_profiles_detail_info_t m_profile_info;
    QScopedPointer<DialogLimitEdit> m_limit_dialog;
    QScopedPointer<DialogWeekDayDetail> m_weekday_dialog;
};

#endif // FORMTXDUFAULTPROFILE_H
