<?php


namespace App\Components\DataGrids;


use Kdyby\Doctrine\QueryBuilder;
use Ublaboo\DataGrid\DataGrid;

class GamesAdminDataGrid extends GamesDataGrid
{
    protected function setupDataSource() : QueryBuilder
    {
        return $this->gameFacade->getGameReader()->getAdminGridDataSource();
    }

    protected function setupColumns(DataGrid $grid)
    {
        $this->columnIdPreset($grid);
        parent::setupColumns($grid);
        $this->columnStatusPreset($grid);
    }

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

    protected function setupInlineEdit(DataGrid $grid)
    {
        $grid->getColumn('name')
            ->setEditableCallback([$this, 'editNameWrapper'])
            ->setEditableInputType('text', ['class' => 'form-control input-sm']);
    }

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

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