<?php

namespace App\Admin\Actions\Grid;

use App\Models\UserConsumeRecord as UserConsumeRecordModel;
use Dcat\Admin\Form\AbstractTool;
use Dcat\Admin\Grid;

class UserConsumeRecord extends AbstractTool
{
    /**
     * @return string
     */
    protected $title = '金币收支';

    public function handle($a = '')
    {
        return $this->getKey();
    }

    public function grid()
    {
        $id = \request()->input('key');

        return Grid::make(new UserConsumeRecordModel(), function (Grid $grid) use ($id) {
            $grid->model()->where('user_id', $id)->orderByDesc('created_at');
            $grid->column('id')->sortable();
            $grid->column('type', admin_trans('user-consume-record.fields.type'))
                ->using(config('global.consume_type'))
                ->label(['success', 'info', 'primary']);
            $grid->column('before', admin_trans('user-consume-record.fields.before'))
                ->label('info');
            $grid->column('change', admin_trans('user-consume-record.fields.change'))
                ->label('danger');
            $grid->column('current', admin_trans('user-consume-record.fields.current'))
                ->label('success');
            $grid->column('remark', admin_trans('user-consume-record.fields.remark'));
            $grid->column('created_at', '消费时间');

            $grid->disableRowSelector();
            $grid->disableActions();
            $grid->disableToolbar();
        });
    }

    public function render()
    {
        return $this->grid();
    }
}
