<?php

namespace Modules\User\Http\Controllers\Admin\Selectable;

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

class Identities extends Selectable
{

    public $model = Identity::class;

    public static function display(): Closure
    {
        return function ($value) {
            if (is_array($value)) {
                return implode(';', array_column($value, 'name'));
            }

            return optional($this->identities)->name;
        };
    }

    public function make()
    {
        $this->column('id', '#ID#');
        $this->column('name', '身份名称');
        $this->column('status', '状态')->bool();
        $this->column('created_at', '时间');

        $this->filter(function (Filter $filter) {
            $filter->like('name', '身份名称');
        });
    }

}
