import { FormItem, FormConfig } from '@/components/form-render/form-render-types'
import { TreeDataNode } from 'ant-design-vue/es/vc-tree-select/interface'

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

export const formItems = (
	materialOptions: Array<{ value: string | undefined; label: string | undefined }>,
	required: boolean,
	persons: Array<{ value: string | undefined; label: string | undefined }>,
	types: Array<TreeDataNode>,
): FormItem[] => [
	{
		group: 'form',
		type: 'radio',
		config: {
			autoLink: true,
			hasFeedback: false,
			label: '盘点类型',
			name: 'auditType',
			required: true,
		},
		properties: {
			size: 'default',
			optionType: 'button',
			buttonStyle: 'solid',
			defaultValue: 'SCAN',
			options: [
				{ value: 'SCAN', label: '扫码盘点' },
				{ value: 'MANUAL', label: '人工盘点' },
			],
		},
		rules: [],
	},
	{
		type: 'tree-select',
		group: 'form',
		config: {
			label: '物料类型选择',
			name: 'types',
			required: true,
		},
		properties: {
			size: 'default',
			placeholder: '请选择物料类型',
			multiple: true,
			treeData: types,
		},
		rules: [],
	},
	{
		group: 'form',
		type: 'select',
		hidden: true,
		config: {
			autoLink: true,
			hasFeedback: false,
			label: '物料选择',
			name: 'ids',
			required: true,
		},
		properties: {
			size: 'default',
			mode: 'multiple',
			required: required,
			placeholder: '请选择物料',
			options: materialOptions,
		},
		rules: [],
	},
	{
		group: 'form',
		type: 'select',
		config: {
			autoLink: true,
			hasFeedback: false,
			label: '盘点人员',
			name: 'taker',
			required: true,
		},
		properties: {
			size: 'default',
			type: 'text',
			allowClear: false,
			bordered: true,
			showCount: false,
			options: persons,
			placeholder: '请输入盘点人员',
		},
		rules: [],
	},
	{
		type: 'select',
		group: 'form',
		config: {
			autoLink: true,
			hasFeedback: false,
			label: '审核人员',
			name: 'reviewer',
			required: true,
		},
		properties: {
			size: 'default',
			controls: true,
			placeholder: '请填写审核人员',
			options: persons,
		},
		rules: [],
	},
]
