#ifndef FIMTASKSWIDGET_H
#define FIMTASKSWIDGET_H

#include <QWidget>
#include <QTreeWidget>
#include "tasksAmmFim.h"
#include "connectortoserver.h"

namespace Ui {
class FIMtasksWidget;
}

class FIMtasksWidget : public QWidget
{
    Q_OBJECT

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

private:
    enum ColumnsTree{
        clmn_Title = 0,
        clmn_ID
    };

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

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

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:
    TaskAmmFim* getTaskByID(int id);
    void loadFIMtasksFromXML(QByteArray array);
    void fillTree();

    void preparationTreeWidget();
    void reSetHeadTreeWidget();
    void loadTasksFIM();

    void deleteAllTaskAmmFim();

    void updateTaskItem(QTreeWidgetItem *itemTask);

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

private:
    QString userName;
    QList<TaskAmmFim*> listTaskAmmFim;
    QString loginTraineeSelected;
};

#endif // FIMTASKSWIDGET_H
