#include "detailwidget.h"
#include "ui_detailwidget.h"

#include <QScroller>

#include "campservice.h"

DetailWidget::DetailWidget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::DetailWidget)
{
    ui->setupUi(this);

    m_peopleModel = new AutoTableModel<AddressItem>(this);
    m_servicesModel = new AutoTableModel<ServiceItem>(this);

    m_peopleModel->setTranslations(Context::instance().plugin("CAMP")->translations());
    m_servicesModel->setTranslations(Context::instance().plugin("CAMP")->translations());

    ui->tabPeople->setModel(m_peopleModel);
    ui->tabServices->setModel(m_servicesModel);

    ui->tabPeople->hideColumn(0);
    ui->tabPeople->hideColumn(1);
    ui->tabPeople->hideColumn(6);
    ui->tabPeople->horizontalHeader()->setSectionResizeMode(2, QHeaderView::Stretch);

    ui->tabServices->hideColumn(1);
    ui->tabServices->hideColumn(3);
    ui->tabServices->hideColumn(7);
    ui->tabServices->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
    ui->tabServices->horizontalHeader()->setSectionResizeMode(2, QHeaderView::Stretch);

    QScroller::grabGesture(ui->tabServices, QScroller::LeftMouseButtonGesture);
    QScroller::grabGesture(ui->tabPeople, QScroller::LeftMouseButtonGesture);
}

DetailWidget::~DetailWidget()
{
    delete ui;
}

void DetailWidget::setData(const CampDataPtr &data)
{
    CampService srv;
    srv.loadItems(data);

    m_peopleModel->setData(data->people());
    m_servicesModel->setData(data->services());
}
