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 { getNumber } from "@/utils/utils"

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

    let defaultStart = 10
    const day = Array(90).fill('').map((_item: string, index: number) => {
        let field = `daRetention${index + 1}`
        let data = {
            title: `D${index + 1}`,
            dataIndex: field,
            label: "D1~Dn",
            align: "center",
            width: 150,
            children: [{
                title: `留存率`,
                dataIndex: field,
                key: 'retained',
                align: "center",
                width: 110,
                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');
                    if (index <= day) {
                        let data: any = {}
                        if (b?.[field]) {
                            data = b?.[field]
                            return <div>
                                <div className={style.dbox}>
                                    <span style={{ color: '#d81b60', fontWeight: 600 }}>
                                        <span>活跃：</span>
                                        <span>{getNumber(Number(data?.activeRetention || '0'), 100, '*')}%</span>
                                    </span>
                                    <span style={{ color: '#faad14', fontWeight: 600 }}>
                                        <span>付费：</span>
                                        <span>{getNumber(Number(data?.paidRetentionRate || '0'), 100, '*')}%</span>
                                    </span>
                                    <span style={{ color: 'rgb(12,130,16)', fontWeight: 600 }}>
                                        <span>小R：</span>
                                        <span>{data?.smallR}%</span>
                                    </span>
                                    <span style={{ color: '#0f538a', fontWeight: 600 }}>
                                        <span>中R：</span>
                                        <span>{data?.mediumR}%</span>
                                    </span>
                                    <span style={{ color: '#eb2f96', fontWeight: 600 }}>
                                        <span>大R：</span>
                                        <span>{data?.largeR}%</span>
                                    </span>
                                    <span style={{ color: '#2f54eb', fontWeight: 600 }}>
                                        <span>超大R：</span>
                                        <span>{data?.superR}%</span>
                                    </span>
                                    <span style={{ color: '#0f538a', fontWeight: 600 }}>
                                        <span>R总：</span>
                                        <span>{data?.rtotalRetention}%</span>
                                    </span>
                                </div>
                            </div>
                        }
                        return <div style={{ height: 147.5, lineHeight: '126px' }}>--</div>
                    }
                    return <div style={{ height: 147.5, lineHeight: '126px' }}>--</div>
                }
            },{
                title: `总人数`,
                dataIndex: field,
                key: 'count',
                align: "center",
                width: 100,
                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');
                    if (index <= day) {
                        let data: any = {}
                        if (b?.[field]) {
                            data = b?.[field]
                            return <div>
                                <div className={style.dbox}>
                                    <span style={{ color: 'rgb(12,130,16)', fontWeight: 600 }}>
                                        <span>创角：</span>
                                        <span>{data?.totalRegNum}</span>
                                    </span>
                                    <span style={{ color: '#eb2f96', fontWeight: 600 }}>
                                        <span>付费：</span>
                                        <span>{data?.totalAmountNum}</span>
                                    </span>
                                    <span style={{ color: '#faad14', fontWeight: 600 }}>
                                        <span>小R：</span>
                                        <span>{data?.smallRNum}</span>
                                    </span>
                                    <span style={{ color: '#2f54eb', fontWeight: 600 }}>
                                        <span>中R：</span>
                                        <span>{data?.mediumRNum}</span>
                                    </span>
                                    <span style={{ color: '#0f538a', fontWeight: 600 }}>
                                        <span>大R：</span>
                                        <span>{data?.largeRNum}</span>
                                    </span>
                                    <span style={{ color: '#eb2f96', fontWeight: 600 }}>
                                        <span>超大R：</span>
                                        <span>{data?.superRNum}</span>
                                    </span>
                                    <span style={{ color: '#2f54eb', fontWeight: 600 }}>
                                        <span>R总：</span>
                                        <span>{data?.rtotal}</span>
                                    </span>
                                </div>
                            </div>
                        }
                        return <div style={{ height: 147.5, lineHeight: '126px' }}>--</div>
                    }
                    return <div style={{ height: 147.5, lineHeight: '126px' }}>--</div>
                }
            }]
        }
        data['default'] = defaultStart + index
        return data
    })


    return [
        {
            label: 'GS信息',
            data: [
                {
                    title: 'GS名称', dataIndex: 'gsNames', label: 'GS信息', align: 'center', width: 70, default: 4,
                    render: (a: string) => (<WidthEllipsis value={a} />)
                } 
            ]
        },
        {
            label: '游戏信息',
            data: [
                {
                    title: '游戏名称', dataIndex: 'parentGameName', label: '游戏信息', align: 'center', width: 90, default: 1,
                    render: (a: string) => (<WidthEllipsis value={a} />)
                },
                { title: '游戏ID', dataIndex: 'parentGameId', label: '游戏信息', align: 'center', width: 90 },
                {
                    title: '游戏应用类型', dataIndex: 'parentGameClassify', 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 },
                {
                    title: '开服时间', dataIndex: 'dt', label: '游戏信息', align: 'center', width: 90, default: 5, sorter: true,
                    render: (a: any, b: any) => {
                        if (b.gameName === '总计') {
                            return '--'
                        }
                        return a
                    }
                },
                {
                    title: '开服天数', dataIndex: 'days', label: '游戏信息', align: 'center', width: 70, default: 6,
                    render: (a: string, b: { gameName: string }) => {
                        if (b.gameName === '总计') {
                            return '--'
                        }
                        return <WidthEllipsis value={a} />
                    }
                },
            ]
        },
        {
            label: '数据',
            data: [
                {
                    title: '新用户人数', dataIndex: 'totalRegNum', label: '数据', align: 'center', width: 70, sorter: true, default: 7,
                    render: (a: number) => <Statistic value={a || 0} />
                },
                {
                    title: '创角人数', dataIndex: 'totalRoleNum', label: '数据', align: 'center', width: 70, sorter: true, default: 8,
                    render: (a: number) => <Statistic value={a || 0} />
                },
                {
                    title: '付费人数', dataIndex: 'totalAmountNum', label: '数据', align: 'center', width: 70, sorter: true, default: 9,
                    render: (a: number) => <Statistic value={a || 0} />
                }
            ]
        },
        {
            label: 'D1~Dn',
            data: [
                ...day
            ]
        }
    ]
}

export default columns12