<?php

namespace App\Admin\Selectable;

use Encore\Admin\Grid\Filter;
use Encore\Admin\Grid\Selectable;
use Modules\User\Models\User;

class ClerksSelectAble extends Selectable
{

    public $model = User::class;

    public $perPage = 25;

    public static function display(): \Closure
    {
        return function ($value) {

            // 如果`$value`是数组，表示在`collaborators`列中使用，显示用分号`;`分隔的用户`name`字段
            if (is_array($value)) {
                return implode(';', array_column($value, 'show_name'));
            }
            // 否则为`author_id`列使用，直接显示用户的`name`字段
            return optional($this->clerks)->username;
        };
    }

    public function make()
    {
        $this->column('id', 'ID');
        $this->column('username', '手机号');
        $this->column('info.nickname', '昵称');

        $this->filter(function (Filter $filter) {
            $filter->like('username', '手机号');
        });
    }

}
