#ifndef COMMONVIEW_H
#define COMMONVIEW_H

#include <QTreeWidget>
#include <QTranslator>
#include <QMutex>
#include "instructorsAndTrainees_global.h"
#include "connectortoserver.h"

//Родительский класс представления БД Инструкторов/Обучаемых (самого верхнего уровня)

class CommonView : public QWidget
{
    Q_OBJECT

public:
    enum TypeView
    {
        onlyView,
        control
    };

    enum TypeObject
    {
        objInstructor,
        objTrainee,
        objGroup
    };

protected:
    enum ColumnsTreeUsers{
        clmn_Name = 0,
        clmn_Login,
        clmn_Password,
        clmn_Class,
        clmn_Computer,
        clmn_IP_address,
        clmn_Administrator,
        clmn_Archived,
        clmn_Logged,
        clmn_ID,
        clmn_count
    };

public:
    CommonView(ConnectorToServer* connectorToServer, TypeView type, QWidget *parent = nullptr);
    ~CommonView();

    void resizeEvent(QResizeEvent *event) override;

public:
    void setAdminMode(bool adminMode)
    {
        this->adminMode = adminMode;
    }    
    void activate()
    {
        treeWidget->setEnabled(true);
    }
    void deactivate()
    {
        treeWidget->clear();
        treeWidget->setEnabled(false);
        lastCurrentID = 0;
    }
    void clearSelection()
    {
        treeWidget->clearSelection();
        lastCurrentID = 0;
    }

protected:
    void setArchiveVisible(bool archiveVisible)
    {
        this->archiveVisible = archiveVisible;
    }
    void setNotLoggedInVisible(bool notLoggedInVisible)
    {
        this->notLoggedInVisible = notLoggedInVisible;
    }

    void setItemColorArchive(QTreeWidgetItem* item);
    void setItemColorNoArchive(QTreeWidgetItem* item);

    void setItemColor(QTreeWidgetItem* item, QColor color);

    void preparationTreeWidget();

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

protected:
    void reSetHeadTreeWidget();

protected:
    ConnectorToServer* connectorToServer;
    QTreeWidget* treeWidget;
    QList<int> listWidthColumn;
    QString TypeUserDB;
    QMutex mtxTreeWidget;
    TypeView typeView;
    bool archiveVisible;
    bool notLoggedInVisible;
    bool adminMode;
    bool authComplited;
    int lastCurrentID;
    TypeObject typeObject;

    WaitAnimationWidget *waitAnimationWidget;
};

#endif // COMMONVIEW_H
