<?php

namespace App\Admin\Controllers\Area;

use App\Admin\Actions\Area\AddStock;
use App\Admin\Actions\Area\SubStock;
use App\Admin\Selectable\AreaStockAble;
use App\Admin\Selectable\ClerksSelectAble;
use App\Models\Area;
use App\Models\AreaCode;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Exception;
use Modules\Mall\Models\Region;

class CodeController extends AdminController
{

    protected $title = '提货码列表';

    /**
     * Notes:
     *
     * @Author: 玄尘
     * @Date: 2023/1/11 13:44
     * @return Grid
     */
    public function grid(): Grid
    {
        $grid = new Grid(new AreaCode());
        $grid->disableActions();
        $grid->disableCreateButton();


        $grid->filter(function (Grid\Filter $filter) {
            $filter->column(1 / 3, function (Grid\Filter $filter) {
                $filter->like('area.title', '地区名称');
            });
            $filter->column(1 / 3, function (Grid\Filter $filter) {
                $filter->equal('status', '状态')->select(AreaCode::STATUS);
            });
        });

        $grid->model()->with(['area']);

        $grid->column('id', '序号');
        $grid->column('code', '码');
        $grid->column('user.username', '领取用户')
            ->display(function () {
                return $this->user ? $this->user->show_name : '---';
            });
        $grid->column('manage.username', '管理人')
            ->display(function () {
                return $this->manage ? $this->manage->show_name : '---';
            });
        $grid->column('area.title', '地区名称');
        $grid->column('status', '状态')->using(AreaCode::STATUS);
        $grid->column('created_at', '创建时间');


        return $grid;
    }

}
