<?php

namespace App\Admin\Selectable;

use App\Models\Feedback;
use App\Models\Tag;
use Encore\Admin\Grid\Filter;
use Encore\Admin\Grid\Selectable;

class SeleteFeedback extends Selectable
{
    public $model = Feedback::class;

    public function make()
    {
        $this->column('id');
        $this->column('content');
        $this->column('handler');
        $this->column('mobile', '头像');
        $this->column('created_time');

        $this->filter(function (Filter $filter) {
            $filter->like('content');
        });
    }
    public static function display(){
        return function ($value) {
            // 如果`$value`是数组，表示在`collaborators`列中使用，显示用分号`;`分隔的用户`name`字段
            if (is_array($value)) {
                return implode(';', array_column($value, 'name'));
            }

            // 否则为`author_id`列使用，直接显示用户的`name`字段
            return optional($this->author)->name;
        };
    }
}

class SeleteTag extends Selectable
{
    public $model = Tag::class;

    public function make()
    {
        $this->column('id');
        $this->column('name');

        $this->filter(function (Filter $filter) {
            $filter->like('name');
        });
    }
    public static function display(){
        return function ($value) {
            // 如果`$value`是数组，表示在`collaborators`列中使用，显示用分号`;`分隔的用户`name`字段
            if (is_array($value)) {
                return implode(';', array_column($value, 'name'));
            }

            // 否则为`author_id`列使用，直接显示用户的`name`字段
            return optional($this->author)->name;
        };
    }
}