import WidthEllipsis from "@/components/widthEllipsis"
import { Statistic } from "antd"
import React from "react"
import { version } from "../../components/TableData"
import moment from "moment"
import style from '../../extensionData/everyday/index.less'
import { TYPE, gameClassifyEnum } from "@/components/QueryForm/const"

function columns12(): { label: string, fieldSHow?: { label: string, saveField: string, defaultValue: any[], data: any[] }, data: any[] }[] {

    const roiC = Array(29).fill('').map((_item: string, index: number) => {
        let data = {
            title: `${index + 2}日ROI`,
            dataIndex: `roi${index + 2}`,
            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="%" />
        }
        index++;
        return data
    })

    let defaultValue = [  // 默认展示字段
        { label: '充值人数', key: 'rechargeUserCount', type: '付费趋势' },
        { label: '充值金额', key: 'rechargeMoney', type: '付费趋势' },
        { label: '增', key: 'increase', type: '付费趋势' },
        { label: '回', key: 'back', type: '付费趋势' },
        { label: '倍', key: 'multiples', type: '付费趋势' },
    ]
    const getFieldDta = () => {
        let mySelectFieldData = localStorage.getItem(`myAdFieldConfig${version}_推广媒体每日数据`)
        let newSelectFieldData: any = {}
        if (mySelectFieldData) {
            newSelectFieldData = JSON.parse(mySelectFieldData).date_field
        } else {
            newSelectFieldData = defaultValue
        }
        return newSelectFieldData
    }
    // 总付费趋势
    let defaultStart = 19
    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: "时间区间跨度",
            width: 110,
            render: (a: any, b: any) => {
                let date1 = moment()
                if (b?.pitcher === '总计') {
                    if (b?.beginDay) {
                        date1 = moment(b.beginDay)
                    } else {
                        date1 = moment()
                    }
                } else {
                    date1 = moment(b.dt)
                }
                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
    })

    // let mDefaultStart = 109, count = 0
    const Mc = [4, 5, 6, 7, 8, 9, 10, 11, 12].map(index => {
        let field = `amountM${index}Trend`
        let data = {
            title: `M${index}`,
            dataIndex: `M${index}`,
            label: "时间区间跨度",
            width: 110,
            render: (a: any, b: any) => {
                let date1 = moment()
                if (b?.pitcher === '总计') {
                    if (b?.beginDay) {
                        date1 = moment(b.beginDay)
                    } else {
                        date1 = moment()
                    }
                } else {
                    date1 = moment(b.dt)
                }
                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'] = mDefaultStart + count
        // count++;
        return data
    })


    Mc.push({
        title: "总",
        default: 49,
        dataIndex: "amountSumTrend",
        label: "时间区间跨度",
        align: "center",
        width: 110,
        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 (a) {
                            data = a
                            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 '--'
        },
    } as any)

    return [
        {
            label: '基本信息',
            data: [
                {
                    title: '投手', dataIndex: 'pitcher', label: '基本信息', align: 'center', width: 95, default: 1,
                    render: (a: string, b: any) => (<WidthEllipsis value={a} />)
                },
                {
                    title: '推广游戏名称', dataIndex: 'gameName', label: '基本信息', align: 'center', width: 95, default: 2,
                    render: (a: string, b: any) => (<WidthEllipsis value={a} />)
                },
                {
                    title: '推广游戏CP名称', dataIndex: 'gameCp', label: '基本信息', align: 'center', width: 95, default: 3,
                    render: (a: string, b: any) => (<WidthEllipsis value={a} />)
                },
                {
                    title: '推广游戏应用类型', dataIndex: 'gameType', label: '基本信息', align: 'center', width: 95, default: 4,
                    render: (a: string, b: any) => (<WidthEllipsis value={gameClassifyEnum[a]} />)
                },
                {
                    title: '推广媒体', dataIndex: 'accountType', label: '基本信息', align: 'center', width: 95, default: 5,
                    render: (a: string, b: any) => (<WidthEllipsis value={TYPE[a]} />)
                },
                {
                    title: '时间', dataIndex: 'dt', label: '基本信息', align: 'center', width: 110, default: 6, sorter: true,
                    render: (a: string, b: any) => (<WidthEllipsis value={a} />)
                },
                {
                    title: '消耗', dataIndex: 'cost', label: '基本信息', align: 'center', width: 70, default: 7, sorter: true,
                    render: (a: string) => <Statistic value={a || 0} />
                },
                {
                    title: '推广账号数量', dataIndex: 'accountCount', label: '基本信息', align: 'center', width: 80, sorter: true,
                    render: (a: string) => <Statistic value={a || 0} />
                },
                {
                    title: '推广渠道数量', dataIndex: 'agentCount', label: '基本信息', align: 'center', width: 70, sorter: true,
                    render: (a: string) => <Statistic value={a || 0} />
                },
                {
                    title: '推广计划数量', dataIndex: 'planCount', label: '基本信息', align: 'center', width: 70, sorter: true,
                    render: (a: string) => <Statistic value={a || 0} />
                }
            ]
        },
        {
            label: '用户数据',
            data: [
                {
                    title: '注册人数', dataIndex: 'registerNum', label: '用户数据', align: 'center', width: 70, sorter: true, default: 8,
                    render: (a: string) => <Statistic value={a || 0} />
                },
                {
                    title: '注册成本', dataIndex: 'registerCost', label: '用户数据', align: 'center', width: 70, sorter: true, default: 9,
                    render: (a: string) => <Statistic value={a || 0} />
                },
                {
                    title: '创角人数', tips: '包含新老用户创角', dataIndex: 'roleNum', label: '用户数据', align: 'center', width: 70, sorter: true,
                    render: (a: string) => <Statistic value={a || 0} />
                },
                {
                    title: '首日创角人数', dataIndex: 'firstRoleNum', label: '用户数据', align: 'center', width: 70, sorter: true,
                    render: (a: string) => <Statistic value={a || 0} />
                },
                {
                    title: '新用户累计创角人数', dataIndex: 'newUserTotalRoleNum', label: '用户数据', align: 'center', width: 100, sorter: true,
                    render: (a: string) => <Statistic value={a || 0} />
                },
                {
                    title: '首日创角成本', dataIndex: 'firstRoleCost', label: '用户数据', align: 'center', width: 70, sorter: true,
                    render: (a: string) => <Statistic value={a || 0} />
                },
                {
                    title: '新用户累计创角成本', dataIndex: 'newUserTotalRoleCost', label: '用户数据', align: 'center', width: 70, 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: 'firstRoleNum', label: '用户数据', align: 'center', width: 70, sorter: true,
                //     render: (a: string) => <Statistic value={a || 0} />
                // },
                // {
                //     title: '新用户累计创角量', dataIndex: 'newUserTotalRoleNum', label: '用户数据', align: 'center', width: 70, sorter: true,
                //     render: (a: string) => <Statistic value={a || 0} />
                // },
                {
                    title: '首日创角率', dataIndex: 'firstRoleRate', label: '用户数据', align: 'center', width: 70, sorter: true,
                    render: (a: number) => <Statistic value={a ? a * 100 : 0} precision={2} valueStyle={!a ? {} : a >= 50 ? { color: 'red' } : { color: '#0f990f' }} suffix="%" />
                },
                {
                    title: '新用户创角率', tips: '新用户累计创角人数/注册人数', dataIndex: 'newUserTotalRoleRate', label: '用户数据', align: 'center', width: 70, sorter: true,
                    render: (a: number) => <Statistic value={a ? a * 100 : 0} precision={2} valueStyle={!a ? {} : a >= 50 ? { color: 'red' } : { color: '#0f990f' }} suffix="%" />
                }
            ]
        },
        {
            label: '付费数据',
            data: [
                {
                    title: '首日新用户充值次数', dataIndex: 'firstNewUserAmountCount', label: '付费数据', align: 'center', width: 70, sorter: true,
                    render: (a: string) => <Statistic value={a || 0} />
                },
                {
                    title: '首日新用户充值人数', dataIndex: 'firstNewUserAmountNum', label: '付费数据', align: 'center', width: 70, sorter: true, default: 10,
                    render: (a: string) => <Statistic value={a || 0} />
                },
                {
                    title: '首日新用户充值金额', dataIndex: 'firstNewUserAmount', label: '付费数据', align: 'center', width: 70, sorter: true, default: 11,
                    render: (a: string) => <Statistic value={a || 0} />
                },
                {
                    title: '老用户充值次数', dataIndex: 'oldAmountCount', label: '付费数据', align: 'center', width: 70, sorter: true,
                    render: (a: string) => <Statistic value={a || 0} />
                },
                {
                    title: '老用户充值人数', dataIndex: 'oldAmountNum', label: '付费数据', align: 'center', width: 70, sorter: true,
                    render: (a: string) => <Statistic value={a || 0} />
                },
                {
                    title: '老用户充值金额', dataIndex: 'oldAmount', label: '付费数据', align: 'center', width: 70, sorter: true,
                    render: (a: string) => <Statistic value={a || 0} />
                },
                {
                    title: '账面充值次数', dataIndex: 'amountCount', label: '付费数据', align: 'center', width: 70, sorter: true,
                    render: (a: string) => <Statistic value={a || 0} />
                },
                {
                    title: '账面充值人数', dataIndex: 'amountNum', label: '付费数据', align: 'center', width: 70, sorter: true,
                    render: (a: string) => <Statistic value={a || 0} />
                },
                {
                    title: '账面充值金额', dataIndex: 'amount', label: '付费数据', align: 'center', width: 70, sorter: true,
                    render: (a: string) => <Statistic value={a || 0} />
                },
                {
                    title: '新用户累计充值次数', dataIndex: 'buyNewUserTotalAmountCount', label: '付费数据', align: 'center', width: 70, sorter: true,
                    render: (a: string) => <Statistic value={a || 0} />
                },
                {
                    title: '新用户累计充值人数', dataIndex: 'buyNewUserTotalAmountNum', label: '付费数据', align: 'center', width: 70, sorter: true, default: 12,
                    render: (a: string) => <Statistic value={a || 0} />
                },
                {
                    title: '新用户累计充值金额', dataIndex: 'buyNewUserTotalAmount', label: '付费数据', align: 'center', width: 70, sorter: true, default: 13,
                    render: (a: string) => <Statistic value={a || 0} />
                },
                {
                    title: '首日ROI', tips: '首日新用户充值金额/实际消耗', dataIndex: 'firstRoi', label: '付费数据', align: 'center', width: 70, sorter: true, default: 14,
                    render: (a: number) => <Statistic value={a ? a * 100 : 0} precision={2} valueStyle={!a ? {} : a >= 1 ? { color: 'red' } : { color: '#0f990f' }} suffix="%" />
                },
                {
                    title: '毛利额', dataIndex: 'grossProfit', label: '付费数据', align: 'center', width: 70, sorter: true,
                    render: (a: number) => <Statistic value={a} precision={2} valueStyle={a < 0 ? { color: 'red' } : {}} />
                },
                {
                    title: '至今回收率', tips: '新用户累计充值金额/实际消耗', dataIndex: 'todayRoi', 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="%" />
                },
                ...roiC,
                {
                    title: '60日ROI', dataIndex: 'roi60', label: '付费数据', align: 'center', width: 80, sorter: true,
                    render: (a: number) => <Statistic value={a ? a * 100 : 0} precision={2} valueStyle={!a ? {} : a >= 0.9 ? { color: 'red' } : { color: '#0f990f' }} suffix="%" />
                },
                {
                    title: '90日ROI', dataIndex: 'roi90', 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: '180日ROI', dataIndex: 'roi180', 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: '1年ROI', dataIndex: 'roi1yaer', 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: '总ROI', dataIndex: 'todayRoi', label: '付费数据', align: 'center', width: 80, default: 15, 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: 'firstRate', 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: 'todayRate', 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: '新用户付费比', tips: '首日新用户充值人数/账面充值人数', dataIndex: 'newUserAmountRatio', 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: 'firstAvg', label: '付费数据', align: 'center', width: 70, sorter: true,
                    render: (a: string) => <Statistic value={a || 0} />
                },
                {
                    title: '至今客单价', dataIndex: 'buyAvg', label: '付费数据', align: 'center', width: 70, sorter: true,
                    render: (a: string) => <Statistic value={a || 0} />
                },
                {
                    title: '账面客单价', tips: '账面充值金额/账面充值次数', dataIndex: 'paperAvg', label: '付费数据', align: 'center', width: 70, sorter: true,
                    render: (a: string) => <Statistic value={a || 0} />
                },
                {
                    title: '首日充值成本', tips: '实际消耗/首日新用户充值人数', dataIndex: 'firstAmountCost', label: '付费数据', align: 'center', width: 70, sorter: true, default: 16,
                    render: (a: string) => <Statistic value={a || 0} />
                },
                {
                    title: '至今充值成本', dataIndex: 'todayAmountCost', label: '付费数据', align: 'center', width: 70, sorter: true, default: 17,
                    render: (a: string) => <Statistic value={a || 0} />
                },
                {
                    title: '至今复充率', tips: '新用户复充人数/新用户累计充值人数（新用户复充人数为累计值充值次数n≥2）', dataIndex: 'todayAgainRate', 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: '新增注册ARPPU', tips: '新用户累计充值金额/注册人数', dataIndex: 'newRegArpu', label: '付费数据', align: 'center', width: 70, sorter: true, default: 18,
                    render: (a: string) => <Statistic value={a || 0} />
                },
                {
                    title: '首日付费ARPPU', tips: '首日新用户充值金额/首日新用户充值人数', dataIndex: 'firstArpu', label: '付费数据', align: 'center', width: 70, sorter: true,
                    render: (a: string) => <Statistic value={a || 0} />
                },
                {
                    title: '至今付费ARPPU', tips: '新用户累计充值金额/新用户累计充值人数', dataIndex: 'todayArpu', label: '付费数据', align: 'center', width: 70, sorter: true,
                    render: (a: string) => <Statistic value={a || 0} />
                },
                {
                    title: '账面ARPPU', dataIndex: 'paperArpu', label: '付费数据', align: 'center', width: 70, sorter: true,
                    render: (a: string) => <Statistic value={a || 0} />
                }
            ]
        },
        {
            fieldSHow: {
                label: '日期区间字段展示',
                saveField: 'date_field',
                defaultValue,
                data: [
                    {
                        label: '付费趋势',
                        data: defaultValue
                    },
                ]
            },
            label: '时间区间跨度',
            data: [
                ...zC,
                ...Mc
            ]
        }
    ]
}

export default columns12