#ifndef MPROGRAMMANAGER_H
#define MPROGRAMMANAGER_H

#include <QWidget>
#include <QStyleOption>
#include <QPainter>
#include <QFile>
#include <QAction>
#include <QTreeWidgetItem>
#include <QCheckBox>
#include <QPushButton>
#include <QDebug>
#include <QLabel>
#include <QDateTime>
#include <QList>
#include <QDir>
#include <QFile>
#include <QStandardPaths>
#include <QStringList>
#include <QJsonValue>
#include <QJsonObject>
#include <QJsonDocument>

#include "loappconfig.h"
#include <LoQClass/loqpushbutton.h>
#include <LoUIClass/louimsgboxok.h>
#include <wProgramManager/wnewprogram.h>
#include <wProgramManager/weditprogram.h>

namespace Ui {
class mProgramManager;
}

class mProgramManager : public QWidget
{
    Q_OBJECT

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

public:
    virtual void paintEvent(QPaintEvent *);

protected:
    void isAllChecked();
    QString convertFileSize(int n);
    bool checkIfNameRepeated(const QString &name, QTreeWidgetItem *skip = nullptr);
    QTreeWidgetItem *checkIfProgramChecked();
    bool addProgram(QTreeWidgetItem *item, QString name, QSize res, QString fSize, QString eLast);
    void setProgram(QTreeWidgetItem *item, QString name, QSize res, QString fSize, QString eLast);
    void editHead(QTreeWidgetItem *item, QString name, QSize res, QString remarks);

protected slots:
    void onNewClicked(bool f);
    void onEditClicked(bool f);
    void onDeleteClicked(bool f);
    void onEditHead(QString name, QSize res, QString remarks);
    void onRestoreProgram(const QJsonDocument &pro);
    void onCreateNewProgram(QString name, QSize res, QString remarks);
    void onCheckAll(bool checked);
    void onItemClicked(QTreeWidgetItem *item, int column);
    void onEditProgram(LoQPushButton *obj, bool f);
    void onProgramChanged();

private:
    Ui::mProgramManager *ui;
    QCheckBox       *m_bnSelectAll;
    QTreeWidgetItem *m_itemEditing;
    QString         m_pRoot;
};

#endif // MPROGRAMMANAGER_H
