<?php


namespace App\Components\DataGrids;


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

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

    public function __construct(Translator $translator, GameFacade $gameFacade)
    {
        parent::__construct($translator);
        $this->gameFacade = $gameFacade;
        $this->enableAdder();
    }

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

    protected function setupColumns(DataGrid $grid)
    {
        $this->columnIdPreset($grid);
        $this->columnNamePreset($grid, true);
        $this->columnStatusPreset($grid);

        $grid->getColumn('name')->getElementPrototype('th')->class('col-xs-12');
    }

    public function setupAdder(Container $container)
    {
        $container->addText('name', '');
    }

    protected function processAdder($values)
    {
        $this->gameFacade->getStudioWriter()->createStudio($values->name);
    }

    protected function editName(int $id, string $name)
    {
        $this->gameFacade->getStudioWriter()->editName($id, $name);
    }

    protected function statusChange(int $id, string $status)
    {
        $this->gameFacade->getStudioWriter()->editState($id, $status);
    }
}