<?php

namespace Modules\Mall\Http\Controllers\Admin;

use App\Admin\Traits\WithUploads;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Illuminate\Database\Eloquent\Model;
use Modules\Mall\Models\Express;
use Modules\Mall\Models\Reason;

class ReasonController extends AdminController
{

    use WithUploads;

    protected $title = '退款/货原因';

    protected function grid(): Grid
    {
        $grid = new Grid(new Reason());

        $grid->model()->withCount('shops');

        $grid->filter(function (Grid\Filter $filter) {
            $filter->scope('trashed', '回收站')->onlyTrashed();
        });

        $grid->column('id');
        $grid->column('title', '名称');
        $grid->column('status', '状态')->bool();
        $grid->column('created_at', '创建时间');

        return $grid;
    }

    public function form(): Form
    {
        $form = new Form(new Reason());

        $form->text('title', '名称')->required();
        $form->switch('status', '状态')->default(1);

        return $form;
    }

}