#ifndef AMMTASKSWIDGET_H
#define AMMTASKSWIDGET_H

#include <QWidget>
#include <QTreeWidget>
#include <QDomNode>
#include "module.h"
#include "connectortoserver.h"
#include "tasktreepreparation.h"
#include "dialogchekertask.h"
#include "dialoglistsubproc.h"

namespace Ui {
class AMMtasksWidget;
}

class AMMtasksWidget : public QWidget
{
    Q_OBJECT

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

public:
    void deactivate();
    void waitAnimationWidgetShowWithPlay();

    void setDocsActualed(bool flActualed);

public:
    void resizeEvent(QResizeEvent *event) override;
    void closeDlgCheckTask();
    void closeDlgListSubProc();
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();    
    void on_btnOnlyActive_clicked(); //AMM

    void on_treeWidgetDoubleClicked(QTreeWidgetItem *item, int column);


    void on_btnDocsUpdating_clicked();

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

    void slot_UpdateTasksAMMforTrainee(int trainee_id);

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


    void loadTasksAMM(bool flRequestFirst = true);
    void assignTaskAMMtoTrainee();

    bool selectSubProcForAssignTaskAMM(TaskAmmFim taskNew, QList<SubProc>* listSubProc);

    void setCurrentTask(int id);

Q_SIGNALS:
    void signal_prepareAMMListItems(QByteArray array, bool flOnlyActive, bool flRequestFirst);
    void signal_prepareAMMListItemsForTrainee(QList<TaskAmmFim> listTask);

    void signal_stopParserPreparation();

    void signal_countTasksAMMforTraineeChanged(int trainee_id, int count);

public Q_SLOTS:
    void slot_AMMlistItemsReady(QList<QTreeWidgetItem*> listItems);
public slots:
    void slot_UpdateSubProcForDMCode(QString dmCode);

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

    int idTraineeSelected;

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

    DialogChekerTask* dlgCheckerTask;

    DialogListSubProc* dlgListSubProc;

    bool flOnlyActive; //AMM

    int lastCurrentID;

    TaskAmmFim lastSelectedTask;
};

#endif // AMMTASKSWIDGET_H
