import type { 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 = (types: Array<Codebook>): FormItem[] => {
	return [
		{
			type: 'radio',
			group: 'form',
			config: {
				autoLink: true,
				hasFeedback: false,
				label: '类型',
				name: 'type',
				required: true,
			},
			properties: {
				size: 'default',
				optionType: 'button',
				buttonStyle: 'solid',
				options: types.map((t) => {
					return { value: t.name, label: t.description }
				}),
			},
			rules: [],
		},
		{
			group: 'form',
			type: 'input',
			config: {
				autoLink: true,
				hasFeedback: false,
				label: '上级Key',
				name: 'parentKey',
			},
			properties: {
				size: 'default',
				type: 'text',
				allowClear: true,
				bordered: true,
				showCount: true,
				placeholder: '请输入上级Key',
			},
			rules: [],
		},
		{
			group: 'form',
			type: 'input',
			config: {
				autoLink: true,
				hasFeedback: false,
				label: 'Key',
				name: 'key',
				required: true,
			},
			properties: {
				size: 'default',
				type: 'text',
				allowClear: true,
				bordered: true,
				showCount: true,
				placeholder: '请输入Key',
			},
			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,
				placeholder: '请输入权限名称',
			},
			rules: [],
		},
		{
			type: 'textarea',
			group: 'form',
			config: {
				autoLink: true,
				hasFeedback: false,
				label: '描述',
				name: 'description',
			},
			properties: {
				size: 'default',
				visibilityToggle: true,
				allowClear: true,
				bordered: true,
				showCount: true,
				autoSize: {
					minRows: 3,
					maxRows: 6,
				},
				minRows: 3,
				maxRows: 6,
				placeholder: '请输入权限描述',
			},
			rules: [],
		},
	]
}
