<?php


namespace App\Components\DataGrids;


use App\Model\Facades\GameFacade;
use App\Model\Translator;
use Kdyby\Doctrine\QueryBuilder;
use Ublaboo\DataGrid\DataGrid;

class GamesDataGrid extends BaseDataGrid
{
    /** @var GameFacade */
    protected $gameFacade;

    /**
     * GamesDataGridFactory constructor.
     * @param Translator $translator
     * @param GameFacade $gameFacade
     */
    public function __construct(Translator $translator, GameFacade $gameFacade)
    {
        parent::__construct($translator);
        $this->gameFacade = $gameFacade;
    }

    protected function setupDataSource() : QueryBuilder
    {
        return $this->gameFacade->getGameReader()->getGridDataSource();
    }

    protected function setupColumns(DataGrid $grid)
    {
        $this->columnNamePreset($grid);
        $grid->addColumnText('version', 'Version', 'gameData.version');
        $grid->addColumnText('publisher', 'Publisher', 'gameData.publisher.name')
            ->setSortable('p.name')
            ->setSortableResetPagination();
        $grid->addColumnText('studio', 'Studio', 'gameData.studio.name')
            ->setSortable('s.name')
            ->setSortableResetPagination();

        $grid->getColumn('name')->getElementPrototype('th')->class('col-xs-4');
        $grid->getColumn('publisher')->getElementPrototype('th')->class('col-xs-4');
        $grid->getColumn('studio')->getElementPrototype('th')->class('col-xs-4');
        $grid->getColumn('version')->getElementPrototype('th')->class('fit-column no-break');
    }

    protected function setupActions(DataGrid $grid)
    {
        $grid->addAction('detail', 'detail', 'Homepage:', ['siteId' => 'id'])->setClass('btn btn-danger btn-xs');
    }


}