#ifndef AMMTASKSWIDGET_H
#define AMMTASKSWIDGET_H

#include <QWidget>
#include <QTreeWidget>
#include <QDomNode>
#include "module.h"
#include "connectortoserver.h"
#include "taskTreePreparation.h"

namespace Ui {
class AMMtasksWidget;
}

class AMMtasksWidget : public QWidget
{
    Q_OBJECT

public:
    enum TypeList
    {
        listCommon = 0,
        listForTrainee
    };


public:
    explicit AMMtasksWidget(ConnectorToServer* connectorToServer, TypeList type, QWidget *parent = nullptr);
    ~AMMtasksWidget();

public:
    void clearTree()
    {
        treeWidget->clear();
    }

public:
    void resizeEvent(QResizeEvent *event) override;

private Q_SLOTS:
    void on_treeWidget_currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous);
    void on_btnUpdateTasks_clicked();
    void on_btnAssignTaskToTrainee_clicked();

public Q_SLOTS:
    //Слот обработки сигнала необходимости обновления интерфейса
    void slot_NeedUpdateUI();
    //слот обработки сигнала о выборе обучаемого
    void slot_traineeSelected(QString login);

private:
    Module* searchModuleByID(int id);
    void preparationTreeWidget();
    void reSetHeadTreeWidget();
    void loadTasksAMM();

Q_SIGNALS:
    void signal_prepareListItems(QByteArray array, QList<Module*>* listAllModules);
public Q_SLOTS:
    void slot_listItemsReady(QList<QTreeWidgetItem*> listItems);

private:
    Ui::AMMtasksWidget *ui;
    ConnectorToServer* connectorToServer;
    QTreeWidget* treeWidget;
    TypeList type;

private:
    QList<Module*> listAllModules;
    QString loginTraineeSelected;

    QThread* threadPreparation;
    QThread* threadAnimation;
    TaskTreePreparation* taskTreePreparation;
    WaitAnimationWidget *waitAnimationWidget;
};

#endif // AMMTASKSWIDGET_H
