<?php

namespace App\Admin\Controllers;

use App\Models\MemberUser;
use App\Services\MemberUserService;
use Slowlyo\OwlAdmin\Controllers\AdminController;

/**
 * 用户管理
 *
 * @property MemberUserService $service
 */
class MemberUserController extends AdminController
{
	protected string $serviceName = MemberUserService::class;

	public function list()
	{
		$crud = $this->baseCRUD()
			->filterTogglable(false)
			->headerToolbar([
				$this->createButton('dialog'),
				...$this->baseHeaderToolBar()
			])
			->columns([
				amis()->TableColumn('id', 'ID')->sortable(),
				amis()->TableColumn('mobile', '手机号'),
				amis()->TableColumn('password', '密码'),
				amis()->TableColumn('nickname', '昵称'),
				amis()->TableColumn('avatar', '头像'),
				amis()->TableColumn('gender', '性别'),
				amis()->TableColumn('register_area', '注册地(行政区划代码)'),
				
				amis()->TableColumn('state', '状态')->tpl('${' . admin_dict()->getValue('state.open', '未知') . '}'),
				amis()->TableColumn('created_at', admin_trans('admin.created_at'))->type('datetime')->sortable(),
				
				amis()->TableColumn('updated_at', admin_trans('admin.updated_at'))->type('datetime')->sortable(),
				$this->rowActions('dialog')
			]);

		return $this->baseList($crud);
		
	}

	public function form($isEdit = false)
	{
		return $this->baseForm()->body([
			amis()->TextControl('mobile', '手机号'),
			amis()->TextControl('password', '密码'),
			amis()->TextControl('nickname', '昵称'),
			amis()->TextControl('avatar', '头像'),
			amis()->TextControl('gender', '性别'),
			amis()->TextControl('register_area', '注册地(行政区划代码)'),
			amis()->TextControl('state', '状态'),
		]);
	}

	public function detail()
	{
		return $this->baseDetail()->body([
			amis()->TextControl('id', 'ID')->static(),
			amis()->TextControl('mobile', '手机号')->static(),
			amis()->TextControl('password', '密码')->static(),
			amis()->TextControl('nickname', '昵称')->static(),
			amis()->TextControl('avatar', '头像')->static(),
			amis()->TextControl('gender', '性别')->static(),
			amis()->TextControl('register_area', '注册地(行政区划代码)')->static(),
			amis()->TextControl('state', '状态')->static(),
			amis()->TextControl('created_at', admin_trans('admin.created_at'))->static(),
			amis()->TextControl('updated_at', admin_trans('admin.updated_at'))->static(),
		]);
	}
}