#include <QScrollBar>
#include "tabdialogmessenger.h"
#include "msgwidget.h"


TabDialogMessenger::TabDialogMessenger(QString login , QString userId, QWidget *parent):
    QListWidget(parent),
    login(""),
    userId("")
{
    this->userId = userId;
    this->login = login;

    setWordWrap(true);
    setVerticalScrollBarPolicy(Qt::ScrollBarPolicy::ScrollBarAlwaysOn);
}

TabDialogMessenger::~TabDialogMessenger()
{

}

void TabDialogMessenger::addMsgWidgetLocal(QString text, QString timeStr)
{
    QListWidgetItem *listWidgetItem = new QListWidgetItem();
    QString avatar = ":/resources/icons/instructor.png";

    int widthW = width();
    int widthSB = verticalScrollBar()->size().width();
    //TODO Времянка
    widthW = 450;
    widthSB = 17;

    MsgWidget *msgWidget = new MsgWidget(avatar, MsgWidget::AligneAvatar::Left,
                                      widthW - widthSB);

    addItem(listWidgetItem);
    setItemWidget(listWidgetItem, msgWidget);

    msgWidget->setText(text);
    msgWidget->setTime(timeStr);

    //Корректировка высоты item
    listWidgetItem->setSizeHint (QSize(10, msgWidget->height()));

    scrollToItem(listWidgetItem);
}

void TabDialogMessenger::addMsgWidgetRemote(QString text, QString timeStr)
{
    QListWidgetItem *listWidgetItem = new QListWidgetItem();
    QString avatar = ":/resources/icons/trainee.png";

    int widthW = width();
    int widthSB = verticalScrollBar()->size().width();
    //TODO Времянка
    widthW = 450;
    widthSB = 17;

    MsgWidget *msgWidget = new MsgWidget(avatar, MsgWidget::AligneAvatar::Right,
                                      widthW - widthSB);

    addItem(listWidgetItem);
    setItemWidget(listWidgetItem, msgWidget);

    msgWidget->setText(text);
    msgWidget->setTime(timeStr);

    //Корректировка высоты item
    listWidgetItem->setSizeHint (QSize(10, msgWidget->height()));

    scrollToItem(listWidgetItem);
}
