<?php
namespace App\Admin\Actions\Games;
use App\Models\GameUser;
use Dcat\Admin\Grid;
use Dcat\Admin\Grid\LazyRenderable;

class GameMembers extends LazyRenderable
{
    public function grid(): Grid
    {
        $grid = new Grid(new GameUser());
        $grid->model()->with('user:id,name,avatar')->where('game_id',$this->payload['id'])->orderByDesc('id');

        $grid->column('user.id','ID');
        $grid->column('user.name',trans('user.fields.name'));
        $grid->column('user.avatar',trans('user.fields.avatar'))->image('',50);

        $grid->column('level',trans('game-user.fields.level'))->using([
                1=>trans('game-user.fields.red'),
                2=>trans('game-user.fields.white'),
                3=>trans('game-user.fields.blue'),
                4=>trans('game-user.fields.gold')])
            ->label(['gray','red','write','blue','gold']);

        $grid->column('type',trans('game-user.fields.type'))->using([
            1=>trans('game-user.fields.normal'),
            2=>trans('game-user.fields.fictitious')
        ])->label(['gray','green','gray']);

        $grid->column('created_at');
        $grid->quickSearch(['user.name']);
        $grid->paginate(10);
        $grid->disableRowSelector();
        $grid->disableActions();

        return $grid;
    }
}
