<?php

namespace App\DataTables;

use App\Models\User;
use Yajra\DataTables\Facades\DataTables;

class StaffDataTable
{
    public function render($request)
    {
        $query = User::with('roles');

        return DataTables::of($query)
            ->addColumn('roles', function (User $user) {
                return $user->roles->pluck('name')->map(fn ($name) => '<span class="badge bg-secondary me-1">'.e($name).'</span>')->implode(' ');
            })
            ->addColumn('actions', function (User $user) {
                return view('admin.staff.partials.actions', compact('user'))->render();
            })
            ->rawColumns(['roles', 'actions'])
            ->make(true);
    }
}
