import { FormSchema } from '/@/components/Table';

const getVersionSelect = () => {
    return new Promise((resolve) => {
        resolve([
            {
                label: '版本1',
                value: '版本1'
            },
            {
                label: '版本2',
                value: '版本2'
            }
        ])
    })
}
export const formSchema: FormSchema[] = [
    {
        field: 'FID',
        label: '版本id',
        component: 'Input',
        ifShow: false
    },
    {
        field: 'addType',
        label: '版本添加',
        component: 'RadioGroup',
        ifShow: true,
        required: true,
        defaultValue: '0',
        componentProps({ formActionType }) {
            const { updateSchema } = formActionType;
            return {
                options: [
                    {
                        label: '新增版本',
                        value: '0'
                    },
                    {
                        label: '已有版本',
                        value: '1'
                    }
                ],
                onChange(event: ChangeEvent) {
                    if ((event.target as HTMLInputElement).value === "0") {
                        updateSchema({ field: 'VERSION_NAME', ifShow: true })
                        updateSchema({ field: 'VERSION_NAME_1', ifShow: false })
                    } else {
                        updateSchema({ field: 'VERSION_NAME', ifShow: false })
                        updateSchema({ field: 'VERSION_NAME_1', ifShow: true })
                    }
                },
                disabled: false
            };
        },
    },
    {
        field: 'VERSION_NAME',
        label: '版本名称',
        component: 'Input',
        ifShow: true,
        required: true,
        componentProps: {
            maxLength: 36,
            placeholder: '请输入版本名称',
            disabled: false
        },
    },
    {
        field: 'VERSION_NAME_1',
        label: '版本名称',
        component: 'ApiSelect',
        ifShow: false,
        required: true,
        componentProps: {
            api: getVersionSelect,
            placeholder: '请选择版本名称',
            disabled: false
        },
    },
    {
        field: 'VERSION_NO',
        label: '版本号',
        component: 'Input',
        ifShow: true,
        required: false,
        componentProps: {
            maxLength: 36,
            placeholder: '自动生成版本号',
            disabled: true
        },
    },
    {
        field: 'VERSION_DISP',
        label: '备注',
        component: 'Input',
        ifShow: true,
        componentProps: {
            maxLength: 255,
            disabled: false
        },
        dynamicRules: () => {
            return [
                {
                    required: false,
                    validator: (_, value) => {
                        if (String(value).length > 255) {
                            return Promise.reject('字数不超过255个字');
                        }
                        return Promise.resolve();
                    },
                },
            ];
        },
    }
];