<?php

namespace App\Admin\Controllers;

use App\Services\MemberAddresseService;
use Slowlyo\OwlAdmin\Controllers\AdminController;

/**
 * 用户地址管理
 *
 * @property MemberAddresseService $service
 */
class MemberAddresseController extends AdminController
{
	protected string $serviceName = MemberAddresseService::class;

	public function list()
	{
		$crud = $this->baseCRUD()
			->filterTogglable(false)
			->headerToolbar([
				$this->createButton('dialog'),
				...$this->baseHeaderToolBar()
			])
			->columns([
				amis()->TableColumn('id', 'ID')->sortable(),
				amis()->TableColumn('user_id', '用户编号'),
				amis()->TableColumn('location', '定位地址'),
				amis()->TableColumn('detail', '详细地址'),
				amis()->TableColumn('province', '省'),
				amis()->TableColumn('city', '市'),
				amis()->TableColumn('district', '区'),
				amis()->TableColumn('longitude', '经度'),
				amis()->TableColumn('latitude', '纬度'),
				amis()->TableColumn('area_code', '行政区划代码'),
				amis()->TableColumn('is_default', '是否默认地址'),
				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('user_id', '用户编号'),
			amis()->TextControl('location', '定位地址'),
			amis()->TextControl('detail', '详细地址'),
			amis()->TextControl('province', '省'),
			amis()->TextControl('city', '市'),
			amis()->TextControl('district', '区'),
			amis()->TextControl('longitude', '经度'),
			amis()->TextControl('latitude', '纬度'),
			amis()->TextControl('area_code', '行政区划代码'),
			amis()->TextControl('is_default', '是否默认地址'),
		]);
	}

	public function detail()
	{
		return $this->baseDetail()->body([
			amis()->TextControl('id', 'ID')->static(),
			amis()->TextControl('user_id', '用户编号')->static(),
			amis()->TextControl('location', '定位地址')->static(),
			amis()->TextControl('detail', '详细地址')->static(),
			amis()->TextControl('province', '省')->static(),
			amis()->TextControl('city', '市')->static(),
			amis()->TextControl('district', '区')->static(),
			amis()->TextControl('longitude', '经度')->static(),
			amis()->TextControl('latitude', '纬度')->static(),
			amis()->TextControl('area_code', '行政区划代码')->static(),
			amis()->TextControl('is_default', '是否默认地址')->static(),
			amis()->TextControl('created_at', admin_trans('admin.created_at'))->static(),
			amis()->TextControl('updated_at', admin_trans('admin.updated_at'))->static(),
		]);
	}
}