import React from "react"
import style from './index.less'
import { Statistic } from "antd"
import { gameClassifyEnum } from "@/components/QueryForm/const"
import { version } from "../../components/TableData"
import moment from "moment"

function columnsNature12(rechargeTrendHandle: (data: any) => void): { label: string, fieldSHow?: { label: string, saveField: string, defaultValue: any[], data: any[] }, data: any[] }[] {

    const getFieldDta = () => {
        let defaultValue = [  // 默认展示字段
            { label: '充值人数', key: 'rechargeUserCount', type: '付费趋势' },
            { label: '充值金额', key: 'rechargeMoney', type: '付费趋势' },
            { label: '增', key: 'increase', type: '付费趋势' },
            { label: '回', key: 'back', type: '付费趋势' },
            { label: '倍', key: 'multiples', type: '付费趋势' },
        ]
        let mySelectFieldData = localStorage.getItem(`myAdFieldConfig${version}_游戏每日数据`)
        let newSelectFieldData: any = {}
        if (mySelectFieldData) {
            newSelectFieldData = JSON.parse(mySelectFieldData).date_field
        } else {
            newSelectFieldData = defaultValue
        }
        return newSelectFieldData
    }

    let defaultStart = 14
    // 总付费趋势
    const zC = Array(90).fill('').map((_item: string, index: number) => {
        let field = `amountD${index + 1}Trend`
        let data = {
            title: `D${index + 1}`,
            dataIndex: `D${index + 1}`,
            label: "付费趋势",
            align: "center",
            width: 110,
            render: (a: any, b: any) => {
                let date1 = moment()
                if (b?.costDate === '总计') {
                    if (b?.beginDay) {
                        date1 = moment(b?.beginDay)
                    } else {
                        date1 = moment()
                    }
                } else {
                    date1 = moment(b.costDate)
                }
                let dt = moment()
                let day = dt.diff(date1, 'day');
                let fieldData = getFieldDta()
                if (fieldData?.length > 0 && index <= day) {
                    let data: any = {}
                    let keyS: string[] = fieldData?.map((item: any) => item.key)
                    switch (fieldData[0].type) {
                        case '付费趋势':
                            if (b?.[field]) {
                                data = b?.[field]
                                return <div className={style.dbox}>
                                    {keyS?.includes('rechargeUserCount') && <span style={{ color: '#d81b60', fontWeight: 600 }}>充人：<span>{data?.rechargeUserCount}</span></span>}
                                    {keyS?.includes('rechargeMoney') && <span style={{ color: '#0f538a', fontWeight: 600 }}>充金：<span><Statistic value={data?.rechargeMoney || 0} valueStyle={{ color: '#0f538a', fontWeight: 600 }} /></span></span>}
                                    {keyS?.includes('increase') && <span style={{ color: 'rgb(12,130,16)', fontWeight: 600 }}>增：<span>{(data?.increase * 100)?.toFixed(2)}%</span></span>}
                                    {keyS?.includes('back') && <span style={{ color: '#ff5722', fontWeight: 600 }}>回：<span>{(data?.back * 100)?.toFixed(2)}%</span></span>}
                                    {keyS?.includes('multiples') && <span style={{ color: '#d81b60', fontWeight: 600 }}>倍：<span>{data?.multiples?.toFixed(2)}</span></span>}
                                </div>
                            }
                            return '--'
                    }
                }
                return '--'
            },
        }
        if (index < 30) {
            data['default'] = defaultStart + index
        }
        return data
    })
    const zM = [4, 5, 6, 7, 8, 9, 10, 11, 12].map((index, num) => {
        let field = `amountM${index}Trend`
        let data = {
            title: `M${index}`,
            dataIndex: `M${index}`,
            label: "付费趋势",
            align: "center",
            width: 110,
            render: (a: any, b: any) => {
                let date1 = moment()
                if (b?.costDate === '总计') {
                    if (b?.beginDay) {
                        date1 = moment(b?.beginDay)
                    } else {
                        date1 = moment()
                    }
                } else {
                    date1 = moment(b.costDate)
                }
                let dt = moment()
                let day = dt.diff(date1, 'day');
                let fieldData = getFieldDta()
                if (fieldData?.length > 0 && index * 30 <= day) {
                    let data: any = {}
                    let keyS: string[] = fieldData?.map((item: any) => item.key)
                    switch (fieldData[0].type) {
                        case '付费趋势':
                            if (b?.[field]) {
                                data = b?.[field]
                                return <div className={style.dbox}>
                                    {keyS?.includes('rechargeUserCount') && <span style={{ color: '#d81b60', fontWeight: 600 }}>充人：<span>{data?.rechargeUserCount}</span></span>}
                                    {keyS?.includes('rechargeMoney') && <span style={{ color: '#0f538a', fontWeight: 600 }}>充金：<span><Statistic value={data?.rechargeMoney || 0} valueStyle={{ color: '#0f538a', fontWeight: 600 }} /></span></span>}
                                    {keyS?.includes('increase') && <span style={{ color: 'rgb(12,130,16)', fontWeight: 600 }}>增：<span>{(data?.increase * 100)?.toFixed(2)}%</span></span>}
                                    {keyS?.includes('back') && <span style={{ color: '#ff5722', fontWeight: 600 }}>回：<span>{(data?.back * 100)?.toFixed(2)}%</span></span>}
                                    {keyS?.includes('multiples') && <span style={{ color: '#d81b60', fontWeight: 600 }}>倍：<span>{data?.multiples?.toFixed(2)}</span></span>}
                                </div>
                            }
                            return '--'
                    }
                }
                return '--'
            },
        }
        // data['default'] = defaultStart + 90 + num
        return data
    })



    return [
        {
            label: '游戏信息',
            data: [
                {
                    title: '推广游戏名称', dataIndex: 'gameName', label: '游戏信息', align: 'center', width: 70, default: 2,
                    render: (a: string) => a || '--'
                },
                {
                    title: '推广游戏应用类型', dataIndex: 'gameClassify', label: '游戏信息', align: 'center', width: 80,
                    render: (a: string, b?: any) => (<span>{gameClassifyEnum[a]}</span>)
                }
            ]
        },
        {
            label: '时间',
            data: [
                { title: '日期', dataIndex: 'costDate', label: '时间', align: 'center', width: 90, default: 1 },
            ]
        },
        {
            label: '消耗',
            data: [
                {
                    title: '消耗', dataIndex: 'cost', label: '消耗', align: 'center', width: 90, sorter: true, default: 3,
                    render: (a: string) => <Statistic value={a || 0} />
                }
            ]
        },
        {
            label: '用户数据',
            data: [
                { title: '注册人数', dataIndex: 'regNum', label: '用户数据', align: 'center', width: 70, default: 4, sorter: true },
                { title: '注册成本', dataIndex: 'regCost', label: '用户数据', align: 'center', width: 70, default: 5, sorter: true }
            ]
        },
        {
            label: '付费数据',
            data: [
                { title: '首日新用户充值次数', dataIndex: 'firstNewUserAmountCount', label: '付费数据', align: 'center', width: 70, sorter: true },
                { title: '首日新用户充值人数', dataIndex: 'firstNewUserAmountNum', label: '付费数据', align: 'center', width: 70, default: 6, sorter: true },
                {
                    title: '首日新用户充值金额', dataIndex: 'firstNewUserAmount', label: '付费数据', align: 'center', width: 70, default: 7, sorter: true,
                    render: (a: string) => <Statistic value={a || 0} />
                },
                { title: '老用户充值次数', dataIndex: 'oldUserCount', label: '付费数据', align: 'center', width: 70, sorter: true },
                { title: '老用户充值人数', dataIndex: 'oldUserNum', label: '付费数据', align: 'center', width: 70, sorter: true },
                {
                    title: '老用户充值金额', dataIndex: 'oldUserAmount', label: '付费数据', align: 'center', width: 70, sorter: true,
                    render: (a: string) => <Statistic value={a || 0} />
                },
                { title: '账面充值次数', dataIndex: 'amountCount', label: '付费数据', align: 'center', width: 70, sorter: true },
                { title: '账面充值人数', dataIndex: 'amountNum', label: '付费数据', align: 'center', width: 70, sorter: true },
                {
                    title: '账面充值金额', dataIndex: 'amount', label: '付费数据', align: 'center', width: 70, sorter: true,
                    render: (a: string) => <Statistic value={a || 0} />
                },
                { title: '新用户累计充值次数', dataIndex: 'newUserTotalAmountCount', label: '付费数据', align: 'center', width: 70, sorter: true },
                { title: '新用户累计充值人数', dataIndex: 'newUserTotalAmountNum', label: '付费数据', align: 'center', width: 70, default: 8, sorter: true },
                {
                    title: '新用户累计充值金额', dataIndex: 'newUserTotalAmount', label: '付费数据', align: 'center', width: 70, default: 9, sorter: true,
                    render: (a: string) => <Statistic value={a || 0} />
                },
                {
                    title: '首日ROI', dataIndex: 'firstRoi', label: '付费数据', align: 'center', width: 70, sorter: true, default: 10,
                    render: (a: number) => <Statistic value={a ? a * 100 : 0} precision={2} valueStyle={!a ? {} : a >= 1 ? { color: 'red' } : { color: '#0f990f' }} suffix="%" />
                },
                {
                    title: '总ROI', dataIndex: 'totalRoi', label: '付费数据', align: 'center', width: 70, sorter: true, default: 11,
                    render: (a: number) => <Statistic value={a ? a * 100 : 0} precision={2} valueStyle={!a ? {} : a >= 1 ? { color: 'red' } : { color: '#0f990f' }} suffix="%" />
                },
                {
                    title: '首日付费率', dataIndex: 'firstAmountRate', label: '付费数据', align: 'center', width: 70, sorter: true,
                    render: (a: number) => <Statistic value={a ? a * 100 : 0} precision={2} valueStyle={!a ? {} : a >= 1 ? { color: 'red' } : { color: '#0f990f' }} suffix="%" />
                },
                {
                    title: '至今付费率', tips: '至今付费率（总）=新用户累计充值人数/注册人数', dataIndex: 'todayAmountRate', label: '付费数据', align: 'center', width: 80, sorter: true,
                    render: (a: number) => <Statistic value={a ? a * 100 : 0} precision={2} valueStyle={!a ? {} : a >= 1 ? { color: 'red' } : { color: '#0f990f' }} suffix="%" />
                },
                {
                    title: '新用户付费比', dataIndex: 'newUserRate', label: '付费数据', align: 'center', width: 70, sorter: true,
                    render: (a: number) => <Statistic value={a ? a * 100 : 0} precision={2} valueStyle={!a ? {} : a >= 1 ? { color: 'red' } : { color: '#0f990f' }} suffix="%" />
                },
                {
                    title: '首日客单价', dataIndex: 'firstAvgAmount', label: '付费数据', align: 'center', width: 70, sorter: true,
                    render: (a: string) => <Statistic value={a || 0} />
                },
                {
                    title: '首日充值成本', dataIndex: 'firstNewUserRechargeCost', label: '付费数据', align: 'center', width: 70, default: 12, sorter: true,
                    render: (a: string) => <Statistic value={a || 0} />
                },
                {
                    title: '总充值成本', dataIndex: 'totalRechargeCost', label: '付费数据', align: 'center', width: 70, default: 13, sorter: true,
                    render: (a: string) => <Statistic value={a || 0} />
                },
                {
                    title: '至今客单价', tips: '至今客单价（总）=新用户累计充值金额/新用户累计充值次数', dataIndex: 'todayAvgAmount', label: '付费数据', align: 'center', width: 80, sorter: true,
                    render: (a: string) => <Statistic value={a || 0} />
                },
                {
                    title: '账面客单价', dataIndex: 'avgAmount', label: '付费数据', align: 'center', width: 70, sorter: true,
                    render: (a: string) => <Statistic value={a || 0} />
                },
                {
                    title: '复充率', tips: '复充率（总）=新用户复充人数/新用户累计充值人数（新用户复充人数为累计充值次数n≥2）', dataIndex: 'userAgainRate', label: '付费数据', align: 'center', width: 80, sorter: true,
                    render: (a: number) => <Statistic value={a ? a * 100 : 0} precision={2} valueStyle={!a ? {} : a >= 1 ? { color: 'red' } : { color: '#0f990f' }} suffix="%" />
                },

                {
                    title: '单日付费100+人数', dataIndex: 'hundredUserNum', label: '付费数据', align: 'center', width: 90, sorter: true,
                    render: (a: string) => <Statistic value={a || 0} />
                },
                {
                    title: '单日付费100+成本', dataIndex: 'hundredUserNumCost', label: '付费数据', align: 'center', width: 90, sorter: true,
                    render: (a: string) => <Statistic value={a || 0} precision={2} />
                },
                {
                    title: '首日创角人数', dataIndex: 'firstRoleNum', label: '付费数据', align: 'center', width: 80, sorter: true,
                    render: (a: string) => <Statistic value={a || 0} />
                },
                {
                    title: '创角人数', dataIndex: 'roleNum', label: '付费数据', align: 'center', width: 70, sorter: true,
                    render: (a: string) => <Statistic value={a || 0} />
                },
                {
                    title: '新用户累计创角人数', dataIndex: 'newUserTotalRoleNum', label: '付费数据', align: 'center', width: 85, sorter: true,
                    render: (a: string) => <Statistic value={a || 0} />
                },
                {
                    title: '首日创角人数成本', dataIndex: 'firstRoleNumCost', label: '付费数据', align: 'center', width: 80, sorter: true,
                    render: (a: string) => <Statistic value={a || 0} precision={2} />
                },
                {
                    title: '创角人数成本', dataIndex: 'roleNumCost', label: '付费数据', align: 'center', width: 75, sorter: true,
                    render: (a: string) => <Statistic value={a || 0} precision={2} />
                },
                {
                    title: '新用户累计创角人数成本', dataIndex: 'newUserTotalRoleNumCost', label: '付费数据', align: 'center', width: 90, sorter: true,
                    render: (a: string) => <Statistic value={a || 0} precision={2} />
                },
                {
                    title: '首日创角率', dataIndex: 'firstRoleNumRate', label: '付费数据', align: 'center', width: 75, sorter: true,
                    render: (a: number) => <Statistic value={a ? a * 100 : 0} precision={2} valueStyle={!a ? {} : a >= 1 ? { color: 'red' } : { color: '#0f990f' }} suffix="%" />
                },
                {
                    title: '创角率', dataIndex: 'roleNumRate', label: '付费数据', align: 'center', width: 75, sorter: true,
                    render: (a: number) => <Statistic value={a ? a * 100 : 0} precision={2} valueStyle={!a ? {} : a >= 1 ? { color: 'red' } : { color: '#0f990f' }} suffix="%" />
                },
                {
                    title: '新用户累计创角率', dataIndex: 'newUserTotalRoleNumRate', label: '付费数据', align: 'center', width: 90, sorter: true,
                    render: (a: number) => <Statistic value={a ? a * 100 : 0} precision={2} valueStyle={!a ? {} : a >= 1 ? { color: 'red' } : { color: '#0f990f' }} suffix="%" />
                },
                {
                    title: '新增注册ARPPU', dataIndex: 'regUserArpu', label: '付费数据', align: 'center', width: 70, sorter: true,
                    render: (a: string) => <Statistic value={a || 0} />
                },
                {
                    title: '首日付费ARPPU', dataIndex: 'firstAmountArpu', label: '付费数据', align: 'center', width: 70, sorter: true,
                    render: (a: string) => <Statistic value={a || 0} />
                },
                {
                    title: '至今付费ARPPU', dataIndex: 'todayAmountArpu', label: '付费数据', align: 'center', width: 70, sorter: true,
                    render: (a: string) => <Statistic value={a || 0} />
                },
                {
                    title: '账面ARPPU', dataIndex: 'amountArpu', label: '付费数据', align: 'center', width: 70, sorter: true,
                    render: (a: string) => <Statistic value={a || 0} />
                }
            ]
        },
        {
            fieldSHow: {
                label: '付费趋势区间字段展示',
                saveField: 'date_field',
                defaultValue: [  // 默认展示字段
                    { label: '充值人数', key: 'rechargeUserCount', type: '付费趋势' },
                    { label: '充值金额', key: 'rechargeMoney', type: '付费趋势' },
                    { label: '增', key: 'increase', type: '付费趋势' },
                    { label: '回', key: 'back', type: '付费趋势' },
                    { label: '倍', key: 'multiples', type: '付费趋势' },
                ],
                data: [
                    {
                        label: '付费趋势',
                        data: [
                            { label: '充值人数', key: 'rechargeUserCount', type: '付费趋势' },
                            { label: '充值金额', key: 'rechargeMoney', type: '付费趋势' },
                            { label: '增', key: 'increase', type: '付费趋势' },
                            { label: '回', key: 'back', type: '付费趋势' },
                            { label: '倍', key: 'multiples', type: '付费趋势' },
                        ]
                    }
                ]
            },
            label: '总付费趋势',
            data: [
                ...zC,
                ...zM,
                {
                    title: "总",
                    dataIndex: "total",
                    label: "付费趋势",
                    align: "center",
                    width: 110,
                    default: 44,
                    render: (a: any, b: any) => {
                        let fieldData = getFieldDta()
                        if (fieldData?.length > 0) {
                            let data: any = {}
                            let keyS: string[] = fieldData?.map((item: any) => item.key)
                            switch (fieldData[0].type) {
                                case '付费趋势':
                                    if (b?.amountSumTrend) {
                                        data = b?.amountSumTrend
                                        return <div className={style.dbox}>
                                            {keyS?.includes('rechargeUserCount') && <span style={{ color: '#d81b60', fontWeight: 600 }}>充人：<span>{data?.rechargeUserCount}</span></span>}
                                            {keyS?.includes('rechargeMoney') && <span style={{ color: '#0f538a', fontWeight: 600 }}>充金：<span><Statistic value={data?.rechargeMoney || 0} valueStyle={{ color: '#0f538a', fontWeight: 600 }} /></span></span>}
                                            {keyS?.includes('increase') && <span style={{ color: 'rgb(12,130,16)', fontWeight: 600 }}>增：<span>{(data?.increase * 100)?.toFixed(2)}%</span></span>}
                                            {keyS?.includes('back') && <span style={{ color: '#ff5722', fontWeight: 600 }}>回：<span>{(data?.back * 100)?.toFixed(2)}%</span></span>}
                                            {keyS?.includes('multiples') && <span style={{ color: '#d81b60', fontWeight: 600 }}>倍：<span>{data?.multiples?.toFixed(2)}</span></span>}
                                        </div>
                                    }
                                    return '--'
                            }
                        }
                        return '--'
                    },
                }]
        },
        {
            label: '操作',
            data: [
                {
                    title: '操作',
                    dataIndex: 'cz',
                    label: '操作',
                    default: 45,
                    align: 'center',
                    width: 75,
                    render: (a: number, b: any) => {
                        if (b?.costDate === '总计') {
                            return '--'
                        }
                        return b?.gameId ? <a onClick={() => rechargeTrendHandle(b)}>复充趋势</a> : '--'
                    },
                }
            ]
        }
    ]
}

export default columnsNature12