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

function formConfig(props: { paragraphList?: any[], enumList?: { [key: string]: any }, paymentType: any, paymentCategory: any, isGlobalConfig: boolean }): ProFormColumnsType<{
    name: string;
    state: string;
}>[] {
    let { paragraphList, enumList, paymentType, paymentCategory, isGlobalConfig } = props
    let {getEnum} = useModel('global')
    return [
        {
            title: '付费方式',
            dataIndex: 'paymentType',
            valueType: 'radio',
            fieldProps: {
                onChange: (e) => {
                    let value = e.target.value
                    paymentType[1](value)
                }
            },
            formItemProps: {
                style: { marginBottom: 10 },
                rules: [
                    {
                        required: true,
                        message: '此项为必填项',
                    },
                ],
            },
            valueEnum: () => {
                return getEnum("PAYMENT_TYPE","map") 
            }
        },
        {
            title: '收费类型',
            dataIndex: 'paymentOption',
            valueType: 'radio',
            formItemProps: {
                style: { marginBottom: 10 },
                rules: [
                    {
                        required: true,
                        message: '此项为必填项',
                    },
                ],
            },
            hideInForm: paymentType[0] != 2,
            valueEnum: () => {
                return getEnum("PAYMENT_OPTION","map")  
            }
        },
        {
            title: '收费货币',
            dataIndex: 'paymentCategory',
            valueType: 'radio',
            fieldProps: {
                onChange: (e) => {
                    let value = e.target.value
                    paymentCategory[1](value)
                }
            },
            formItemProps: {
                style: { marginBottom: 10 },
                rules: [
                    {
                        required: true,
                        message: '此项为必填项',
                    },
                ],
            },
            hideInForm: paymentType[0] == 0,
            valueEnum: () => {
                return getEnum("PAYMENT_CATEGORY","map")   
            }
        },
        {//单本
            title: '付费起始段落',
            dataIndex: 'beginPayParagraphNo',
            valueType: 'select',
            fieldProps: {
                showSearch: true, placeholder: '请选择开始收费段落'
            },
            formItemProps: {
                style: { marginBottom: 15 },
                rules: [
                    {
                        required: true,
                        message: '此项为必填项',
                    },
                ],
            },
            hideInForm: paymentType[0] != 2 || isGlobalConfig,//单本书
            valueEnum: () => {
                return new Map(paragraphList?.map(item => [item.paragraphNo, item.content]))
            }
        },
        {//全局
            title: '付费起始段落',
            dataIndex: 'beginPayNo',
            valueType: 'digit',
            fieldProps: {
                placeholder: '请输入收费段落'
            },
            width: 200,
            formItemProps: {
                style: { marginBottom: 15 },
                rules: [
                    {
                        required: true,
                        message: '此项为必填项',
                    },
                ],
            },
            hideInForm: paymentType[0] != 2 || !isGlobalConfig,//单本书
        },
        {
            title: 'VIP阅读',
            dataIndex: 'vipFree',
            valueType: 'segmented',
            formItemProps: {
                style: { marginBottom: 15 },
                rules: [
                    {
                        required: true,
                        message: '此项为必填项',
                    },
                ],
            },
            hideInForm: paymentType[0] == 0 || isGlobalConfig,
            valueEnum: () => {
                return getEnum("VIP_FREE","map")   
            }
        },
        {
            title: '收费金额',
            dataIndex: 'paymentAmount',
            valueType: 'money',
            hideInForm: paymentCategory[0] == 1,
            fieldProps: {
                addonAfter: "元"
            },
            formItemProps: {
                style: { marginBottom: 15 },
                rules: [
                    {
                        required: true,
                        message: '此项为必填项',
                    },
                ],
            },
        },
        {
            title: '收费书币',
            dataIndex: 'paymentCoin',
            valueType: 'digit',
            hideInForm: paymentCategory[0] == 0,
            fieldProps: {
                addonAfter: "书币"
            },
            formItemProps: {
                style: { marginBottom: 15 },
                rules: [
                    {
                        required: true,
                        message: '此项为必填项',
                    },
                ],
            },
        },
        {
            title: '备注',
            dataIndex: 'remark',
            valueType: 'textarea',
            hideInForm: isGlobalConfig,
            formItemProps: {
                style: { marginBottom: 15 },
            },
        }
    ]
}

export default formConfig