#ifndef FIMTASKSWIDGET_H
#define FIMTASKSWIDGET_H

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

namespace Ui {
class FIMtasksWidget;
}

class FIMtasksWidget : public QWidget
{
    Q_OBJECT

private:


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

public:
    void deactivate();
    void setOneTaskFim(TaskAmmFim* task); //FIM
    void waitAnimationWidgetShowWithPlay();

public:
    void resizeEvent(QResizeEvent *event) override;
    void closeDlgCheckTask();
protected:
    void changeEvent(QEvent * event) override;

private Q_SLOTS:
    void on_treeWidgetItemClicked(QTreeWidgetItem *item, int column);
    void on_btnDelete_clicked();
    void on_btnCheck_clicked();
    void on_btnAssignTask_clicked();

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

    void slot_UpdateTasksFIMforTrainee(int trainee_id);    

private:    
    void preparationTreeWidget();
    void reSetHeadTreeWidget();
    void setWidthColumnsTree();
    int calculateWidth_0Column();

    void loadTasksFIM();
    void assignTaskFIMtoTrainee();
    void updateTaskItem(QTreeWidgetItem *itemTask);

    void setCurrentTask(int id);
    void setCurrentParentTask(QTreeWidgetItem *item);

Q_SIGNALS:
    void signal_prepareFIMListItems(QByteArray array);
    void signal_prepareFIMListItemsForTrainee(QList<TaskAmmFim> listTask);

    void signal_stopParserPreparation();

    void signal_countTasksFIMforTraineeChanged(int trainee_id, int count);

public Q_SLOTS:
    void slot_FIMlistItemsReady(QList<QTreeWidgetItem*> listItems);

private:
    Ui::FIMtasksWidget *ui;
    ConnectorToServer* connectorToServer;
    QTreeWidget* treeWidget;
    TypeListTreeAMMFIM type;
    QList<int> listWidthColumn;

    int idTraineeSelected;

    QThread* threadPreparation;
    TaskAMMFIMTreePreparation* taskTreePreparation;
    WaitAnimationWidget *waitAnimationWidget;

    DialogChekerTask* dlgCheckerTask;

    QString userName; //FIM

    int lastCurrentID;
};

#endif // FIMTASKSWIDGET_H
