<?php

namespace App\Admin\Actions\Grid;

use App\Models\UserEpisodesRecord;
use Dcat\Admin\Contracts\LazyRenderable;
use Dcat\Admin\Grid;
use Dcat\Admin\Grid\RowAction;
use Dcat\Admin\Traits\LazyWidget;

class UserEpisodeRecord 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(UserEpisodesRecord::with(['user', 'episodes']), function (Grid $grid) use ($id) {
            $grid->model()->where('user_id', $id)->orderByDesc('created_at');
            $grid->column('id')->sortable();
            $grid->column('episodes.name', '短剧名称')->label('info');
            $grid->column('list_id', '第几集')->label('primary');
            $grid->column('platform', '所属平台')
                ->display(function () {
                    return $this->user->info->platform;
                })
                ->using(config('global.platform'))
                ->label([1 => 'primary', 2 => 'success']);
            $grid->column('price', '金币')->label('danger');
            $grid->column('created_at', '消费时间');

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

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