<?php

namespace App\Admin\Controllers;

use App\Admin\Actions\Chat\TeamChatAction;
use App\Admin\Actions\Chat\TeamUser;
use App\Admin\Actions\Users\FollowList;
use App\Admin\Actions\Users\UserAuth;
use App\Admin\Actions\Users\UserChange;
use App\Models\ChatTeam;
use App\Models\User;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;
use Dcat\Admin\Widgets\Modal;

class ChatTeamController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new ChatTeam());
        $grid->model()->with('user.id,name,avatar')->orderByDesc('id');

        $grid->column('id')->sortable();
        $grid->column('user.name');
        $grid->column('user.avatar')->image('', 50);
        $grid->column('group_name');
        $grid->column('GroupId');
        $grid->column('FaceUrl')->image('', 50);
        $grid->column('MemberCount')->display(function ($res) {
            $form = TeamUser::make()->payload(['GroupId' => $this->GroupId]);
            return Modal::make()
                ->lg()
                ->title(trans('chat-team.fields.group_members'))
                ->body($form)
                ->button('<i class="feather icon-align-right"></i> ' . $res);
        });
        $grid->column('updated_at')->sortable();
        $grid->disableRowSelector();
        $grid->disableCreateButton();
        //操作管理
        $grid->actions(function (Grid\Displayers\Actions $actions) {
            $actions->disableView();
            $actions->disableEdit();
            $actions->append(new TeamChatAction($this->GroupId));
        });

        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new ChatTeam(), function (Show $show) {
            $show->field('id');
            $show->field('user_id');
            $show->field('Owner_Account');
            $show->field('group_name');
            $show->field('GroupId');
            $show->field('FaceUrl');
            $show->field('MaxMemberCount');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new ChatTeam(), function (Form $form) {
            $form->display('id');
            $form->text('user_id');
            $form->text('Owner_Account');
            $form->text('group_name');
            $form->text('GroupId');
            $form->text('FaceUrl');
            $form->text('MaxMemberCount');

            $form->display('created_at');
            $form->display('updated_at');
            $form->footer(function ($footer) {
                // 去掉`查看`checkbox
                $footer->disableViewCheck();
                // 去掉`继续编辑`checkbox
                $footer->disableEditingCheck();
                // 去掉`继续创建`checkbox
                $footer->disableCreatingCheck();
            });
        });
    }
}
