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

function formConfig(props: { paragraphList?: any[], enumList?: { [key: string]: any }, paymentType: any[] }): ProFormColumnsType<{
    name: string;
    state: string;
}>[] {
    let { paragraphList, enumList, paymentType } = props
    // console.log("paragraphList",paragraphList)
    return [
        {
            title: '开始付费段落',
            dataIndex: 'beginPayChapterNo',
            valueType: 'select',
            fieldProps: {
                showSearch: true, placeholder: '请选择开始收费段落'
            },
            formItemProps: {
                style: { marginBottom: 15 },
                rules: [
                    {
                        required: true,
                        message: '此项为必填项',
                    },
                ],
            },
            valueEnum: () => {
                return new Map(paragraphList?.map(item => [item.chapterNo, item.chapterName]))
            }
        },
        {
            title: 'VIP阅读',
            dataIndex: 'vipFree',
            valueType: 'segmented',
            formItemProps: {
                style: { marginBottom: 15 },
            },
            valueEnum: () => {
                let arr = enumList?.VIP_FREE?.values
                return new Map(arr?.map(({ value, description }: any) => [value, description]))
            }
        },
        {
            title: '付费方式',
            dataIndex: 'paymentType',
            valueType: 'checkbox',
            fieldProps: {
                onChange: (value) => {
                    paymentType[1](value)
                }
            },
            formItemProps: {
                style: { marginBottom: 15 },
            },
            valueEnum: () => {
                let arr = enumList?.PAYMENT_TYPE?.values
                let obj = {}
                if (paymentType?.[0]?.includes('0')) {
                    obj = { "1": { disabled: true }, '2': { disabled: true }, '3': { disabled: true } }
                }
                if (paymentType?.[0]?.join().match(/[123]/g)) {
                    obj = { "0": { disabled: true } }
                }
                let enumObj = convertEnumArr(arr, obj)
                return enumObj
            }
        },
        {
            title: '收费金额',
            dataIndex: 'paymentAmount',
            valueType: 'money',
            hideInForm: !paymentType?.[0]?.includes('2'),
            formItemProps: {
                style: { marginBottom: 15 },
            },
        },
        {
            title: '收费书币',
            dataIndex: 'paymentCoin',
            valueType: 'digit',
            hideInForm: !paymentType?.[0]?.join().match(/[13]/g),
            formItemProps: {
                style: { marginBottom: 15 },
            },
        },
        {
            title: '备注',
            dataIndex: 'remark',
            valueType: 'textarea',
            formItemProps: {
                style: { marginBottom: 15 },
            },
        }
    ]
}

export default formConfig