import { Codebook } from '@/api/api'
import { FormItem, FormConfig } from '@/components/form-render/form-render-types'

export const config: FormConfig = {
	layout: 'horizontal',
	colon: true,
	hideRequiredMark: false,
	labelAlign: 'right',
	scrollToFirstError: false,
	validateOnRuleChange: true,
	labelCol: {
		span: 4,
		offset: 0,
	},
}

export const formItems = (levels: Codebook[]): FormItem[] => [
	{
		group: 'form',
		type: 'input',
		config: {
			autoLink: true,
			hasFeedback: false,
			label: '类型编码',
			name: 'no',
			required: true,
			help: '格式：一级编码两位组成，00-99取值，只要保证唯一即可；二级编码，四位组成,父级的两位+00-99取值，只要保证唯一即可；',
		},
		properties: {
			size: 'default',
			type: 'text',
			allowClear: true,
			bordered: true,
			showCount: true,
		},
		rules: [],
	},
	{
		group: 'form',
		type: 'input',
		config: {
			autoLink: true,
			hasFeedback: false,
			label: '上级编码',
			name: 'parentNo',
		},
		properties: {
			size: 'default',
			type: 'text',
			allowClear: true,
			bordered: true,
			showCount: true,
		},
		rules: [],
	},
	{
		type: 'select',
		group: 'form',
		config: {
			autoLink: true,
			hasFeedback: false,
			label: '类型级别',
			name: 'level',
			required: true,
		},
		properties: {
			size: 'default',
			allowClear: false,
			autoClearSearchValue: true,
			autofocus: false,
			bordered: true,
			defaultActiveFirstOption: true,
			dropdownMatchSelectWidth: true,
			labelInValue: false,
			showSearch: false,
			options: levels.map((item) => {
				return { value: item.name, label: item.description }
			}),
		},
		rules: [],
	},
	{
		group: 'form',
		type: 'input',
		config: {
			autoLink: true,
			hasFeedback: false,
			label: '类型名称',
			name: 'name',
			required: true,
		},
		properties: {
			size: 'default',
			type: 'text',
			allowClear: true,
			bordered: true,
			showCount: true,
		},
		rules: [],
	},
]
