<?php
namespace App\Admin\Actions\Chat;
use App\Models\ChatList;
use App\Models\User;
use App\Repositories\ChatTeamUser;
use App\Repositories\ImMessage;
use App\Services\TencentImGroupService;
use App\Services\TencentImMessage;
use Dcat\Admin\Grid;
use Dcat\Admin\Grid\LazyRenderable;

class TeamUser extends LazyRenderable
{
    public function grid(): Grid
    {
        $group_id = $this->payload['GroupId'];

        return Grid::make(new ChatTeamUser($group_id), function (Grid $grid) {
            $grid->column('Member_Account',trans('feeds.fields.user_id'))->display(function ($res){
                $user = User::query()->where('tencent_im_user_id',$res)->first();
                $str = "";
                $str.="<div style='margin-right:10px;text-align: center;display: flex'>";
                $str.='<img data-action="preview-img" src="'.$user->avatar.'" style="max-width:50px;max-height:50px;cursor:pointer" class="img img-thumbnail">';
                $str.='<p style="margin-top: 5px">'.$user->name.'</p>';
                $str.="</div>";
                return $str;
            });
            $grid->column('Role',trans('chat-team.fields.role'))->display(function ($res){
                if($res=='Owner'){
                    $str = trans('chat-team.fields.Owner');
                }elseif($res=='Admin'){
                    $str = trans('chat-team.fields.Admin');
                }else{
                    $str = trans('chat-team.fields.Member');
                }
                return $str;
            });
            $grid->column('JoinTime', trans('chat-team.fields.JoinTime'))->display(function ($res){
                return date('Y-m-d H:i',$res);
            });
            $grid->disableRowSelector();
            $grid->paginate(10);
            $grid->disableActions();
        });
    }
}
