<?php

namespace App\Admin\Actions\Grid;

use Dcat\Admin\Contracts\LazyRenderable;
use Dcat\Admin\Grid;
use Dcat\Admin\Grid\RowAction;
use Dcat\Admin\Traits\LazyWidget;
use App\Models\UserRechargeRecord as UserRechargeRecordModel;

class UserRechargeRecord extends RowAction implements LazyRenderable
{
    use LazyWidget;

    /**
     * @return string
     */
    protected $title = '充值记录';

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

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

        return Grid::make(UserRechargeRecordModel::with(['user', 'combo']), function (Grid $grid) use ($id) {
            $grid->model()->where('user_id', $id)->orderByDesc('created_at');
            $grid->column('id')->sortable();

            $grid->column('pay_id', '订单号');
            $grid->column('combo.name', '充值套餐');
            $grid->column('price', admin_trans('user-recharge-record.fields.price'))->label('danger');
            $grid->column('platform', '所属平台')->display(function () {
                return $this->user->info->platform;
            })->using(config('global.platform'))->label([1 => 'primary', 2 => 'success']);
            $grid->column('gold', admin_trans('user-recharge-record.fields.gold'))->label('info');
            $grid->column('gift', admin_trans('user-recharge-record.fields.gift'))->label('primary');
            // $grid->column('pay_id');
            $grid->column('created_at', '充值时间')->sortable();

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

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