<?php

namespace App\Admin\Controllers;

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

/**
 * 行政区划
 *
 * @property SysRegionService $service
 */
class SysRegionController extends AdminController
{
	protected string $serviceName = SysRegionService::class;

	public function list()
	{
		$crud = $this->baseCRUD()
			->filterTogglable(false)
			->headerToolbar([
				$this->createButton('dialog'),
				...$this->baseHeaderToolBar()
			])
			->columns([
				amis()->TableColumn('id', 'ID')->sortable(),
				amis()->TableColumn('cityName', 'CityName'),
				amis()->TableColumn('parentId', 'ParentId')->sortable(),
				amis()->TableColumn('shortName', 'ShortName'),
				amis()->TableColumn('depth', 'Depth')->sortable(),
				amis()->TableColumn('cityCode', 'CityCode'),
				amis()->TableColumn('zipCode', 'ZipCode'),
				amis()->TableColumn('mergerName', 'MergerName'),
				amis()->TableColumn('longitude', 'Longitude'),
				amis()->TableColumn('latitude', 'Latitude'),
				amis()->TableColumn('pinyin', 'Pinyin'),
				amis()->TableColumn('isUse', 'IsUse'),
				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('cityName', 'CityName'),
			amis()->TextControl('parentId', 'ParentId'),
			amis()->TextControl('shortName', 'ShortName'),
			amis()->TextControl('depth', 'Depth'),
			amis()->TextControl('cityCode', 'CityCode'),
			amis()->TextControl('zipCode', 'ZipCode'),
			amis()->TextControl('mergerName', 'MergerName'),
			amis()->TextControl('longitude', 'Longitude'),
			amis()->TextControl('latitude', 'Latitude'),
			amis()->TextControl('pinyin', 'Pinyin'),
			amis()->TextControl('isUse', 'IsUse'),
		]);
	}

	public function detail()
	{
		return $this->baseDetail()->body([
			amis()->TextControl('id', 'ID')->static(),
			amis()->TextControl('cityName', 'CityName')->static(),
			amis()->TextControl('parentId', 'ParentId')->static(),
			amis()->TextControl('shortName', 'ShortName')->static(),
			amis()->TextControl('depth', 'Depth')->static(),
			amis()->TextControl('cityCode', 'CityCode')->static(),
			amis()->TextControl('zipCode', 'ZipCode')->static(),
			amis()->TextControl('mergerName', 'MergerName')->static(),
			amis()->TextControl('longitude', 'Longitude')->static(),
			amis()->TextControl('latitude', 'Latitude')->static(),
			amis()->TextControl('pinyin', 'Pinyin')->static(),
			amis()->TextControl('isUse', 'IsUse')->static(),
			amis()->TextControl('created_at', admin_trans('admin.created_at'))->static(),
			amis()->TextControl('updated_at', admin_trans('admin.updated_at'))->static(),
		]);
	}
}