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

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

    const getFieldDta = () => {
        let defaultValue = [  // 默认展示字段
            { label: '新用户人数', key: 'regNum', type: 'D1~Dn' },
            { label: '创角人数', key: 'roleNum', type: 'D1~Dn' },
            { label: '活跃人数', key: 'activeNum', type: 'D1~Dn' },
            { label: '付费人数', key: 'amountNum', type: 'D1~Dn' },
            { label: '付费金额', key: 'amount', type: 'D1~Dn' },
            { label: '滚服人数', key: 'rollServerNum', type: 'D1~Dn' },
            { label: '滚服付费人数', key: 'rollServerAmountNum', type: 'D1~Dn' },
            { label: '滚服付费金额', key: 'rollServerAmount', type: 'D1~Dn' },
            { label: '滚服（付费金额）占比', key: 'rollServerAmountRate', type: 'D1~Dn' },
        ]
        let mySelectFieldData = localStorage.getItem(`myAdFieldConfig${version}_区服数据`)
        let newSelectFieldData: any = {}
        if (mySelectFieldData) {
            newSelectFieldData = JSON.parse(mySelectFieldData).date_field
        } else {
            newSelectFieldData = defaultValue
        }
        return newSelectFieldData
    }

    let defaultStart = 13
    const day = Array(90).fill('').map((_item: string, index: number) => {
        let field = `da${index + 1}Trend`
        let data = {
            title: `D${index + 1}`,
            dataIndex: field,
            label: "D1~Dn",
            align: "center",
            width: 120,
            children: [{
                title: `新创角`,
                dataIndex: field,
                key: 'newCreate',
                align: "center",
                width: 140,
                render: (a: any, b: any) => {
                    let date1 = moment()
                    if (b?.gameName === '总计') {
                        if (b?.dt) {
                            date1 = moment(b?.dt)
                        } 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 'D1~Dn':
                                if (b?.[field]) {
                                    data = b?.[field]
                                    return <div className={style.dbox}>
                                        {keyS?.includes('regNum') && <span style={{ color: '#2f54eb', fontWeight: 600 }}>新用户人数：<span>{data?.regNum}</span></span>}
                                        {keyS?.includes('roleNum') && <span style={{ color: '#722ed1', fontWeight: 600 }}>创角人数：<span>{data?.roleNum}</span></span>}
                                        {keyS?.includes('activeNum') && <span style={{ color: '#eb2f96', fontWeight: 600 }}>活跃人数：<span>{data?.activeNum}</span></span>}
                                        {keyS?.includes('amountNum') && <span style={{ color: '#d81b60', fontWeight: 600 }}>付费人数：<span>{data?.amountNum}</span></span>}
                                        {keyS?.includes('amount') && <span style={{ color: '#0f538a', fontWeight: 600 }}>付费金额：<span><Statistic value={data?.amount || 0} valueStyle={{ color: '#0f538a', fontWeight: 600 }} /></span></span>}
                                    </div>
                                }
                                return '--'
                        }
                    }
                    return '--'
                },
            }, {
                title: `滚服`,
                dataIndex: field,
                key: 'gf',
                align: "center",
                width: 150,
                render: (a: any, b: any) => {
                    let date1 = moment()
                    if (b?.gameName === '总计') {
                        if (b?.dt) {
                            date1 = moment(b?.dt)
                        } 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 'D1~Dn':
                                if (b?.[field]) {
                                    data = b?.[field]
                                    return <div className={style.dbox}>
                                        {keyS?.includes('rollServerNum') && <span style={{ color: '#13c2c2', fontWeight: 600 }}>滚服人数：<span>{data?.rollServerNum}</span></span>}
                                        {keyS?.includes('rollServerAmountNum') && <span style={{ color: '#faad14', fontWeight: 600 }}>滚服付费人数：<span>{data?.rollServerAmountNum}</span></span>}
                                        {keyS?.includes('rollServerAmount') && <span style={{ color: '#0f538a', fontWeight: 600 }}>滚服付费金额：<span><Statistic value={data?.rollServerAmount || 0} valueStyle={{ color: '#0f538a', fontWeight: 600 }} /></span></span>}
                                        {keyS?.includes('rollServerAmountRate') && <span style={{ color: 'rgb(12,130,16)', fontWeight: 600 }}>滚服占比：<span>{(data?.rollServerAmountRate * 100)?.toFixed(2)}%</span></span>}
                                    </div>
                                }
                                return '--'
                        }
                    }
                    return '--'
                },
            }]
        }
        data['default'] = defaultStart + index
        return data
    })

    let defaultStartM = 103
    let month = [4, 5, 6, 7, 8, 9, 10, 11, 12].map((item, index) => {
        let field = `m${item}Trend`
        let data = {
            title: `M${item}`,
            dataIndex: field,
            label: "D1~Dn",
            children: [{
                title: `新创角`,
                dataIndex: field,
                key: 'newCreate',
                align: "center",
                width: 140,
                render: (a: any, b: any) => {
                    let date1 = moment()
                    if (b?.gameName === '总计') {
                        if (b?.dt) {
                            date1 = moment(b?.dt)
                        } else {
                            date1 = moment()
                        }
                    } else {
                        date1 = moment(b.dt)
                    }
                    let dt = moment()
                    let day = dt.diff(date1, 'day');
                    let fieldData = getFieldDta()
                    if (fieldData?.length > 0 && item * 30 <= day) {
                        let data: any = {}
                        let keyS: string[] = fieldData?.map((item: any) => item.key)
                        switch (fieldData[0].type) {
                            case 'D1~Dn':
                                if (b?.[field]) {
                                    data = b?.[field]
                                    return <div className={style.dbox}>
                                        {keyS?.includes('regNum') && <span style={{ color: '#2f54eb', fontWeight: 600 }}>新用户人数：<span>{data?.regNum}</span></span>}
                                        {keyS?.includes('roleNum') && <span style={{ color: '#722ed1', fontWeight: 600 }}>创角人数：<span>{data?.roleNum}</span></span>}
                                        {keyS?.includes('activeNum') && <span style={{ color: '#eb2f96', fontWeight: 600 }}>活跃人数：<span>{data?.activeNum}</span></span>}
                                        {keyS?.includes('amountNum') && <span style={{ color: '#d81b60', fontWeight: 600 }}>付费人数：<span>{data?.amountNum}</span></span>}
                                        {keyS?.includes('amount') && <span style={{ color: '#0f538a', fontWeight: 600 }}>付费金额：<span><Statistic value={data?.amount || 0} valueStyle={{ color: '#0f538a', fontWeight: 600 }} /></span></span>}
                                    </div>
                                }
                                return '--'
                        }
                    }
                    return '--'
                },
            }, {
                title: `滚服`,
                dataIndex: field,
                key: 'gf',
                align: "center",
                width: 150,
                render: (a: any, b: any) => {
                    let date1 = moment()
                    if (b?.gameName === '总计') {
                        if (b?.dt) {
                            date1 = moment(b?.dt)
                        } else {
                            date1 = moment()
                        }
                    } else {
                        date1 = moment(b.dt)
                    }
                    let dt = moment()
                    let day = dt.diff(date1, 'day');
                    let fieldData = getFieldDta()
                    if (fieldData?.length > 0 && item * 30 <= day) {
                        let data: any = {}
                        let keyS: string[] = fieldData?.map((item: any) => item.key)
                        switch (fieldData[0].type) {
                            case 'D1~Dn':
                                if (b?.[field]) {
                                    data = b?.[field]
                                    return <div className={style.dbox}>
                                        {keyS?.includes('rollServerNum') && <span style={{ color: '#13c2c2', fontWeight: 600 }}>滚服人数：<span>{data?.rollServerNum}</span></span>}
                                        {keyS?.includes('rollServerAmountNum') && <span style={{ color: '#faad14', fontWeight: 600 }}>滚服付费人数：<span>{data?.rollServerAmountNum}</span></span>}
                                        {keyS?.includes('rollServerAmount') && <span style={{ color: '#0f538a', fontWeight: 600 }}>滚服付费金额：<span><Statistic value={data?.rollServerAmount || 0} valueStyle={{ color: '#0f538a', fontWeight: 600 }} /></span></span>}
                                        {keyS?.includes('rollServerAmountRate') && <span style={{ color: 'rgb(12,130,16)', fontWeight: 600 }}>滚服占比：<span>{(data?.rollServerAmountRate * 100)?.toFixed(2)}%</span></span>}
                                    </div>
                                }
                                return '--'
                        }
                    }
                    return '--'
                },
            }]
        }
        data['default'] = defaultStartM + index
        return data
    })

    month.push({
        title: `总`,
        dataIndex: 'totalTrend',
        label: "D1~Dn",
        align: "center",
        default: 112,
        children: [{
            title: `新创角`,
            dataIndex: 'totalTrend',
            key: 'newCreate',
            align: "center",
            width: 140,
            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 'D1~Dn':
                            if (b?.['totalTrend']) {
                                data = b?.['totalTrend']
                                return <div className={style.dbox}>
                                    {keyS?.includes('regNum') && <span style={{ color: '#2f54eb', fontWeight: 600 }}>新用户人数：<span>{data?.regNum}</span></span>}
                                    {keyS?.includes('roleNum') && <span style={{ color: '#722ed1', fontWeight: 600 }}>创角人数：<span>{data?.roleNum}</span></span>}
                                    {keyS?.includes('activeNum') && <span style={{ color: '#eb2f96', fontWeight: 600 }}>活跃人数：<span>{data?.activeNum}</span></span>}
                                    {keyS?.includes('amountNum') && <span style={{ color: '#d81b60', fontWeight: 600 }}>付费人数：<span>{data?.amountNum}</span></span>}
                                    {keyS?.includes('amount') && <span style={{ color: '#0f538a', fontWeight: 600 }}>付费金额：<span><Statistic value={data?.amount || 0} valueStyle={{ color: '#0f538a', fontWeight: 600 }} /></span></span>}
                                </div>
                            }
                            return '--'
                    }
                }
                return '--'
            },
        }, {
            title: `滚服`,
            dataIndex: 'totalTrend',
            key: 'gf',
            align: "center",
            width: 150,
            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 'D1~Dn':
                            if (b?.['totalTrend']) {
                                data = b?.['totalTrend']
                                return <div className={style.dbox}>
                                    {keyS?.includes('rollServerNum') && <span style={{ color: '#13c2c2', fontWeight: 600 }}>滚服人数：<span>{data?.rollServerNum}</span></span>}
                                    {keyS?.includes('rollServerAmountNum') && <span style={{ color: '#faad14', fontWeight: 600 }}>滚服付费人数：<span>{data?.rollServerAmountNum}</span></span>}
                                    {keyS?.includes('rollServerAmount') && <span style={{ color: '#0f538a', fontWeight: 600 }}>滚服付费金额：<span><Statistic value={data?.rollServerAmount || 0} valueStyle={{ color: '#0f538a', fontWeight: 600 }} /></span></span>}
                                    {keyS?.includes('rollServerAmountRate') && <span style={{ color: 'rgb(12,130,16)', fontWeight: 600 }}>滚服占比：<span>{(data?.rollServerAmountRate * 100)?.toFixed(2)}%</span></span>}
                                </div>
                            }
                            return '--'
                    }
                }
                return '--'
            },
        }],
    } as any)

    return [
        {
            label: '时间',
            data: [
                {
                    title: '开服时间', dataIndex: 'dt', label: '时间', align: 'center', width: 90, default: 4, sorter: true,
                    render: (a: any, b: any) => {
                        if (b.gameName === '总计') {
                            return '--'
                        }
                        return a
                    }
                },
            ]
        },
        {
            label: '游戏信息',
            data: [
                {
                    title: '游戏名称', dataIndex: 'gameName', label: '游戏信息', align: 'center', width: 90, default: 1,
                    render: (a: string) => (<WidthEllipsis value={a} />)
                },
                { title: '游戏ID', dataIndex: 'gameId', label: '游戏信息', align: 'center', width: 90 },
                {
                    title: '游戏应用类型', dataIndex: 'classify', label: '游戏信息', align: 'center', width: 80, default: 2,
                    render: (a: string) => (<WidthEllipsis value={gameClassifyEnum[a]} />)
                },
                {
                    title: '区服名称', dataIndex: 'serverName', label: '游戏信息', align: 'center', width: 90, default: 3,
                    render: (a: string) => (<WidthEllipsis value={a} />)
                },
                { title: '区服ID', dataIndex: 'serverId', label: '游戏信息', align: 'center', width: 90 },
            ]
        },
        {
            label: '数据',
            data: [
                {
                    title: '新用户人数', dataIndex: 'totalRegNum', label: '数据', align: 'center', width: 70, sorter: true, default: 5,
                    render: (a: number) => <Statistic value={a || 0} />
                },
                {
                    title: '创角人数', dataIndex: 'totalRoleNum', label: '数据', align: 'center', width: 70, sorter: true, default: 6,
                    render: (a: number) => <Statistic value={a || 0} />
                },
                {
                    title: '滚服人数', dataIndex: 'outTotalNum', label: '数据', align: 'center', width: 70, sorter: true, default: 7,
                    render: (a: number) => <Statistic value={a || 0} />
                },
                {
                    title: '滚服付费人数', dataIndex: 'outTotalAmountNum', label: '数据', align: 'center', width: 70, sorter: true, default: 8,
                    render: (a: number) => <Statistic value={a || 0} />
                },
                {
                    title: '滚服付费金额', dataIndex: 'outTotalAmount', label: '数据', align: 'center', width: 70, sorter: true, default: 9,
                    render: (a: number) => <Statistic value={a || 0} />
                },
                {
                    title: '付费人数', dataIndex: 'totalAmountNum', label: '数据', align: 'center', width: 70, sorter: true, default: 10,
                    render: (a: number) => <Statistic value={a || 0} />
                },
                {
                    title: '付费金额', dataIndex: 'totalAmount', label: '数据', align: 'center', width: 70, sorter: true, default: 11,
                    render: (a: number) => <Statistic value={a || 0} />
                },
                {
                    title: '滚服（付费金额）占比', dataIndex: 'outTotalRate', label: '数据', align: 'center', width: 90, sorter: true, default: 12,
                    render: (a: number) => <Statistic value={a ? a * 100 : 0} precision={2} valueStyle={!a ? {} : a >= 1 ? { color: 'red' } : { color: '#0f990f' }} suffix="%" />
                },
            ]
        },
        {
            // fieldSHow: {
            //     label: 'D1~Dn区间字段展示',
            //     saveField: 'date_field',
            //     defaultValue: [  // 默认展示字段
            //         { label: '新用户人数', key: 'regNum', type: 'D1~Dn' },
            //         { label: '创角人数', key: 'roleNum', type: 'D1~Dn' },
            //         { label: '活跃人数', key: 'activeNum', type: 'D1~Dn' },
            //         { label: '付费人数', key: 'amountNum', type: 'D1~Dn' },
            //         { label: '付费金额', key: 'amount', type: 'D1~Dn' },
            //         { label: '滚服人数', key: 'rollServerNum', type: 'D1~Dn' },
            //         { label: '滚服付费人数', key: 'rollServerAmountNum', type: 'D1~Dn' },
            //         { label: '滚服付费金额', key: 'rollServerAmount', type: 'D1~Dn' },
            //         { label: '滚服（付费金额）占比', key: 'rollServerAmountRate', type: 'D1~Dn' },
            //     ],
            //     data: [
            //         {
            //             label: 'D1~Dn',
            //             data: [
            //                 { label: '新用户人数', key: 'regNum', type: 'D1~Dn' },
            //                 { label: '创角人数', key: 'roleNum', type: 'D1~Dn' },
            //                 { label: '活跃人数', key: 'activeNum', type: 'D1~Dn' },
            //                 { label: '付费人数', key: 'amountNum', type: 'D1~Dn' },
            //                 { label: '付费金额', key: 'amount', type: 'D1~Dn' },
            //                 { label: '滚服人数', key: 'rollServerNum', type: 'D1~Dn' },
            //                 { label: '滚服付费人数', key: 'rollServerAmountNum', type: 'D1~Dn' },
            //                 { label: '滚服付费金额', key: 'rollServerAmount', type: 'D1~Dn' },
            //                 { label: '滚服（付费金额）占比', key: 'rollServerAmountRate', type: 'D1~Dn' },
            //             ]
            //         }
            //     ]
            // },
            label: 'D1~Dn',
            data: [
                ...day,
                ...month
            ]
        }
    ]
}

export default columns12