import { convertEnumArr } from "@/utils";
import { ProFormColumnsType } from "@ant-design/pro-components";
import { useModel } from "@umijs/max";

function formConfig(): ProFormColumnsType<{
    name: string;
    state: string;
}>[] {
    let {getEnum} = useModel("global")
    return [
        {
            title: '模板名称',
            dataIndex: 'templateName',
            colProps: {
                span: 24
            },
            formItemProps: {
                rules: [
                    {
                        required: true,
                        message: '此项为必填项',
                    },
                ],
            }
        },
        {
            title: '充值模板描述',
            dataIndex: 'templateDescription',
            valueType: 'textarea',
        },
        {
            title: '备注',
            dataIndex: 'remark',
            valueType: 'textarea',
        },
        {
            title: '首充档位',
            dataIndex: 'rechargeConfigList',
            valueType: 'formList',
            fieldProps: {
                creatorButtonProps: {
                    creatorButtonText: "添加一个首充档位配置",
                },
            },
            colProps: {
                span: 24
            },
            columns: [
                {
                    valueType: 'group',
                    colProps: {
                        span: 24
                    },
                    columns: [
                        {
                            title: '类型',
                            dataIndex: 'gearType',
                            valueType: 'select',
                            width: "100%",
                            initialValue: 1,
                            fieldProps: { placeholder: "请选择档位类型" },
                            colProps: {
                                span: 4
                            },
                            formItemProps: {
                                initialValue:2,
                                rules: [
                                    {
                                        required: true,
                                        message: '此项为必填项',
                                    },
                                ],
                            },
                            valueEnum: () => {
                                let map = getEnum("GEAR_TYPE", "map")
                                map.delete(1)
                                return map
                            }
                        },
                        {
                            valueType: 'dependency',
                            name: ['gearType'],
                            columns: ({ gearType }) => {
                                return [
                                    {
                                        title: '价格',
                                        dataIndex: 'price',
                                        valueType: 'money',
                                        width: "100%",
                                        hideInForm: gearType === 3,
                                        fieldProps: { placeholder: "输入价格" },
                                        colProps: {
                                            span: 5
                                        },
                                        formItemProps: {
                                            rules: [
                                                {
                                                    required: true,
                                                    message: '此项为必填项',
                                                },
                                            ],
                                        }
                                    },
                                    {
                                        title: '赠送',
                                        dataIndex: 'gift',
                                        valueType: 'digit',
                                        width: "100%",
                                        hideInForm: gearType !== 1,
                                        fieldProps: { placeholder: "输入赠送书币数" },
                                        colProps: {
                                            span: 5
                                        },
                                        formItemProps: {
                                            rules: [
                                                {
                                                    required: true,
                                                    message: '此项为必填项',
                                                },
                                            ],
                                        }
                                    },
                                    {
                                        title: 'vip天数',
                                        dataIndex: 'vipDays',
                                        valueType: 'select',
                                        width: "100%",
                                        hideInForm: gearType !== 2,
                                        fieldProps: { placeholder: "选择VIP天数" },
                                        colProps: {
                                            span: 4
                                        },
                                        formItemProps: {
                                            rules: [
                                                {
                                                    required: true,
                                                    message: '此项为必填项',
                                                },
                                            ],
                                        },
                                        valueEnum: getEnum("VIP_DAYS","map")
                                    },
                                    {
                                        title: '价格',
                                        width: "100%",
                                        fieldProps: { placeholder: "价格在小说管理设置", disabled: true },
                                        hideInForm: gearType !== 3,
                                        colProps: {
                                            span: 5
                                        }
                                    },
                                    {
                                        title: '文案',
                                        dataIndex: 'description',
                                        width: "100%",
                                        fieldProps: { placeholder: "输入展示文案" },
                                        hideInForm: gearType !== 3,
                                        colProps: {
                                            span: 5
                                        },
                                        formItemProps: {
                                            rules: [
                                                {
                                                    required: true,
                                                    message: '此项为必填项',
                                                },
                                            ],
                                        }
                                    },
                                    {
                                        title: '角标',
                                        dataIndex: 'subscript',
                                        width: "100%",
                                        fieldProps: { placeholder: "右上角角标文案" },
                                        colProps: {
                                            span: 5
                                        }
                                    },
                                    {
                                        title: '底色',
                                        dataIndex: "color",
                                        valueType: "radioButton",
                                        width: "100%",
                                        initialValue: false,
                                        colProps: {
                                            span: 4
                                        },
                                        valueEnum:getEnum("COLOR","map")
                                    }
                                ]
                            }

                        },
                    ]
                }
            ]
        },
        {
            title: '非首充档位',
            dataIndex: 'rechargeConfigList1',
            valueType: 'formList',
            fieldProps: {
                creatorButtonProps: {
                    creatorButtonText: "添加一个非首充档位配置",
                },
            },
            colProps: {
                span: 24
            },
            columns: [
                {
                    valueType: 'group',
                    colProps: {
                        span: 24
                    },
                    columns: [
                        {
                            title: '类型',
                            dataIndex: 'gearType',
                            valueType: 'select',
                            width: "100%",
                            initialValue: 1,
                            fieldProps: { placeholder: "请选择档位类型" },
                            colProps: {
                                span: 4
                            },
                            formItemProps: {
                                initialValue:2,
                                rules: [
                                    {
                                        required: true,
                                        message: '此项为必填项',
                                    },
                                ],
                            },
                            valueEnum: () => {
                                let map = getEnum("GEAR_TYPE", "map")
                                map.delete(1)
                                return map
                            }
                        },
                        {
                            valueType: 'dependency',
                            name: ['gearType'],
                            columns: ({ gearType }) => {
                                return [
                                    {
                                        title: '价格',
                                        dataIndex: 'price',
                                        valueType: 'money',
                                        width: "100%",
                                        hideInForm: gearType === 3,
                                        fieldProps: { placeholder: "输入价格" },
                                        colProps: {
                                            span: 5
                                        },
                                        formItemProps: {
                                            rules: [
                                                {
                                                    required: true,
                                                    message: '此项为必填项',
                                                },
                                            ],
                                        }
                                    },
                                    {
                                        title: '赠送',
                                        dataIndex: 'gift',
                                        valueType: 'digit',
                                        width: "100%",
                                        hideInForm: gearType !== 1,
                                        fieldProps: { placeholder: "输入赠送书币数" },
                                        colProps: {
                                            span: 5
                                        },
                                        formItemProps: {
                                            rules: [
                                                {
                                                    required: true,
                                                    message: '此项为必填项',
                                                },
                                            ],
                                        }
                                    },
                                    {
                                        title: 'vip天数',
                                        dataIndex: 'vipDays',
                                        valueType: 'select',
                                        width: "100%",
                                        hideInForm: gearType !== 2,
                                        fieldProps: { placeholder: "选择VIP天数" },
                                        colProps: {
                                            span: 4
                                        },
                                        formItemProps: {
                                            rules: [
                                                {
                                                    required: true,
                                                    message: '此项为必填项',
                                                },
                                            ],
                                        },
                                        valueEnum:getEnum("VIP_DAYS","map")
                                    },
                                    {
                                        title: '价格',
                                        width: "100%",
                                        fieldProps: { placeholder: "价格在小说管理设置", disabled: true },
                                        hideInForm: gearType !== 3,
                                        colProps: {
                                            span: 5
                                        }
                                    },
                                    {
                                        title: '文案',
                                        dataIndex: 'description',
                                        width: "100%",
                                        fieldProps: { placeholder: "输入展示文案" },
                                        hideInForm: gearType !== 3,
                                        colProps: {
                                            span: 5
                                        },
                                        formItemProps: {
                                            rules: [
                                                {
                                                    required: true,
                                                    message: '此项为必填项',
                                                },
                                            ],
                                        }
                                    },
                                    {
                                        title: '角标',
                                        dataIndex: 'subscript',
                                        width: "100%",
                                        fieldProps: { placeholder: "右上角角标文案" },
                                        colProps: {
                                            span: 5
                                        }
                                    },
                                    {
                                        title: '底色',
                                        dataIndex: "color",
                                        valueType: "radioButton",
                                        width: "100%",
                                        initialValue: false,
                                        colProps: {
                                            span: 4
                                        },
                                        valueEnum: getEnum("COLOR","map")
                                    }
                                ]
                            }

                        },
                    ]
                }
            ]
        },
        {
            title: '激活当前模板',
            dataIndex: 'activateTemplate',
            valueType: 'switch',
            formItemProps: { layout: 'horizontal' },
            colProps: { offset: 19 }
        },
    ]
}

export default formConfig