<?php

namespace Modules\User\Http\Controllers\Admin;

use App\Admin\Traits\WithUploads;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Modules\User\Http\Controllers\Admin\Selectable\Identities;
use Modules\User\Models\Service;

class ServiceController extends AdminController
{

    use WithUploads;

    public $title = '客服中心';

    public function grid(): Grid
    {
        $grid = new Grid(new Service());

        $grid->disableTools();

        $grid->model()->with(['identities']);

        $grid->column('id', '#ID#');
        $grid->column('name', '姓名');
        $grid->column('mobile', '联系方式');
        $grid->column('status', '状态')->bool();
        $grid->column('identities', '服务身份')
            ->belongsToMany(Identities::class);
        $grid->column('created_at', '创建时间');
        $grid->column('updated_at', '更新时间');

        return $grid;
    }

    public function form(): Form
    {
        $form = new Form(new Service());
        $form->text('name', '姓名')->required();
        $form->mobile('mobile', '联系方式')->required();
        $this->cover($form, 'cover', '客服二维码');
        $form->switch('status', '显示')->default(1);
        $form->belongsToMany('identities', Identities::class, '服务身份');

        return $form;
    }

}
