import WidthEllipsis from "@/components/widthEllipsis"
import LookRoleDetails from "@/pages/gameDataStatistics/player/role/lookRoleDetails"
import { Space, Statistic } from "antd"
import React from "react"
import LoginIpDetails from "../roleIpMonitor/loginIpDetails"
import { EyeOutlined } from "@ant-design/icons"
import TongIpUser from "../roleIpMonitor/tongIpUser"
import RegIpRoleDetails from "../roleIpMonitor/regIpRoleDetails"
import SuspectedUser from "./suspectedUser"

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

    return [
        {
            label: '基本信息',
            data: [
                {
                    title: '角色名称', dataIndex: 'roleName', label: '基本信息', align: 'center', width: 85, default: 1,
                    render: (a: string) => (<WidthEllipsis value={a} />)
                },
                {
                    title: '角色ID', dataIndex: 'roleId', label: '基本信息', align: 'center', width: 85,
                    render: (a: string) => (<WidthEllipsis value={a} />)
                },
                {
                    title: '玩家名称', dataIndex: 'userName', label: '基本信息', align: 'center', width: 90, default: 2,
                    render: (a: string) => (<WidthEllipsis value={a} />)
                },
                {
                    title: '玩家ID', dataIndex: 'userId', label: '基本信息', align: 'center', width: 85,
                    render: (a: string) => (<WidthEllipsis value={a} />)
                },
                {
                    title: '游戏名称', dataIndex: 'gameName', label: '基本信息', align: 'center', width: 85, default: 3,
                    render: (a: string) => (<WidthEllipsis value={a} />)
                },
                {
                    title: '游戏ID', dataIndex: 'gameId', label: '基本信息', align: 'center', width: 85,
                    render: (a: string) => (<WidthEllipsis value={a} />)
                },
                {
                    title: '区服名称', dataIndex: 'serverName', label: '基本信息', align: 'center', width: 80, default: 4,
                    render: (a: string) => (<WidthEllipsis value={a} />)
                },
                {
                    title: '帮派', dataIndex: 'country', label: '基本信息', align: 'center', width: 80, default: 5,
                    render: (a: string) => (<WidthEllipsis value={a} />)
                },
                {
                    title: '区服ID', dataIndex: 'serverId', label: '基本信息', align: 'center', width: 80,
                    render: (a: string) => (<WidthEllipsis value={a} />)
                },
                {
                    title: '角色创建时间', dataIndex: 'createTime', label: '基本信息', align: 'center', width: 125, default: 6, sorter: true,
                    render: (a: string) => (<WidthEllipsis value={a} />)
                },
                {
                    title: '角色等级', dataIndex: 'roleLevel', label: '基本信息', align: 'center', width: 60, sorter: true, default: 7,
                    render: (a: string) => <Statistic value={a || 0} />
                },
                {
                    title: '等级上报时间', dataIndex: 'levelTime', label: '基本信息', align: 'center', width: 120, default: 8, sorter: true,
                    render: (a: string) => (<WidthEllipsis value={a} />)
                },
                {
                    title: '等级上报时间距今', dataIndex: 'levelTimeDiff', label: '角色游戏数据', align: 'center', width: 140, default: 9,
                    render: (_: any, b: any) => {
                        if (b?.createTime) {
                            let a = (new Date().getTime() / 1000) - (new Date(b?.levelTime).getTime() / 1000)
                            function secondsToDhms(seconds: any) {
                                const days = Math.floor(seconds / (3600 * 24));
                                const hours = Math.floor((seconds % (3600 * 24)) / 3600);
                                const minutes = Math.floor((seconds % 3600) / 60);
                                const remainingSeconds = seconds % 60;
                                return <span style={{ fontSize: 12, color: (hours + (days * 24)) > 1 ? 'red' : '#000' }}>{`${days ? days + "天" : ''}${hours ? hours + "小时" : ''}${minutes ? minutes + "分" : ''}${remainingSeconds ? remainingSeconds.toFixed(0) + "秒" : ''}`}</span>
                            }
                            return a ? secondsToDhms(a) : '--'
                        } else {
                            return '--'
                        }
                    }
                },
                {
                    title: '创角时间至今', dataIndex: 'createTimeDiff', label: '角色游戏数据', align: 'center', width: 140, default: 10,
                    render: (_: any, b: any) => {
                        if (b?.createTime) {
                            let a = (new Date().getTime() / 1000) - (new Date(b?.createTime).getTime() / 1000)
                            function secondsToDhms(seconds: any) {
                                const days = Math.floor(seconds / (3600 * 24));
                                const hours = Math.floor((seconds % (3600 * 24)) / 3600);
                                const minutes = Math.floor((seconds % 3600) / 60);
                                const remainingSeconds = seconds % 60;
                                return <span style={{ fontSize: 12, color: days > 5 ? 'red' : '#000' }}>{`${days ? days + "天" : ''}${hours ? hours + "小时" : ''}${minutes ? minutes + "分" : ''}${remainingSeconds ? remainingSeconds.toFixed(0) + "秒" : ''}`}</span>
                            }
                            return a ? secondsToDhms(a) : '--'
                        } else {
                            return '--'
                        }
                    }
                },
                {
                    title: '角色注册IP', dataIndex: 'ip', label: '角色游戏数据', align: 'center', width: 110, default: 11,
                    render: (a: string) => (<WidthEllipsis value={a} />)
                },
                {
                    title: '是否导量用户', dataIndex: 'importUser', label: '角色游戏数据', align: 'center', width: 55, sorter: true, default: 12,
                    render: (a: boolean) => a ? '是' : '否'
                },
                {
                    title: '角色登录IP数量', dataIndex: 'ipCount', label: '角色游戏数据', align: 'center', width: 65, sorter: true, default: 13,
                    render: (a: number, b: any) => <Statistic value={a || 0} valueStyle={a > 1 ? { color: 'red' } : {}} suffix={<LoginIpDetails gameId={b.gameId} roleId={b.roleId} icon={<EyeOutlined />} />} />
                },
                {
                    title: '同玩家角色数量', dataIndex: 'userRoleCount', label: '角色游戏数据', align: 'center', width: 65, sorter: true, default: 14,
                    render: (a: number, b: any) => <Statistic value={a || 0} valueStyle={a > 1 ? { color: 'red' } : {}} suffix={<LookRoleDetails userId={b.userId} icon={<EyeOutlined />} />} />
                },
                {
                    title: '角色同IP的玩家数量', dataIndex: 'userCount', label: '角色游戏数据', align: 'center', width: 70, sorter: true, default: 15,
                    render: (a: number, b: any) => <Statistic value={a || 0} valueStyle={a > 1 ? { color: 'red' } : {}} suffix={<TongIpUser roleId={b.roleId} icon={<EyeOutlined />} />} />
                },
                {
                    title: '同IP的角色数量', dataIndex: 'roleCount', label: '角色游戏数据', align: 'center', width: 70, sorter: true, default: 16,
                    render: (a: number, b: any) => <Statistic value={a || 0} valueStyle={a > 1 ? { color: 'red' } : {}} suffix={<RegIpRoleDetails roleId={b.roleId} excludeUserType={0} icon={<EyeOutlined />} />} />
                },
                {
                    title: '同IP的角色数量（排除同玩家）', dataIndex: 'ipRoleCountFilter', label: '角色游戏数据', align: 'center', width: 90, sorter: true, default: 17,
                    render: (a: number, b: any) => <Statistic value={a || 0} valueStyle={a > 1 ? { color: 'red' } : {}} suffix={<RegIpRoleDetails roleId={b.roleId} excludeUserType={1} icon={<EyeOutlined />} />} />
                },
                {
                    title: '疑似同玩家数量', dataIndex: 'suspectedCount', label: '角色游戏数据', align: 'center', width: 80, sorter: true, default: 18,
                    render: (a: number, record: any) => <Statistic value={a || 0} valueStyle={a > 1 ? { color: 'red' } : {}} suffix={<SuspectedUser roleId={record.roleId} icon={<EyeOutlined />} />} />
                },
                {
                    title: '同玩家IP的角色数量（排除同玩家）', dataIndex: 'roleUserIpCountFilter', label: '角色游戏数据', align: 'center', width: 100, sorter: true, default: 19,
                    render: (a: number) => <Statistic value={a || 0} valueStyle={a > 1 ? { color: 'red' } : {}} />
                },
                {
                    title: '角色所在玩家登录过的所有IP的统计数量', dataIndex: 'roleUserIpCount', label: '角色游戏数据', align: 'center', width: 100, sorter: true, default: 20,
                    render: (a: number) => <Statistic value={a || 0} valueStyle={a > 1 ? { color: 'red' } : {}} />
                }
            ]
        },
        {
            label: '客户管理操作',
            data: [
                { title: 'GS', dataIndex: 'gsName', label: '客户管理操作', align: 'center', width: 80, default: 21, render: (a: string, b: any) => (<WidthEllipsis value={a} />) },
                { title: '客服', dataIndex: 'customerServiceName', label: '客户管理操作', align: 'center', width: 80, default: 22, render: (a: string, b: any) => (<WidthEllipsis value={a} />) },
                { title: '运营', dataIndex: 'operUserName', label: '客户管理操作', align: 'center', width: 80, default: 23, render: (a: string, b: any) => (<WidthEllipsis value={a} />) },
                { title: '投手', dataIndex: 'putUserName', label: '客户管理操作', align: 'center', width: 80, default: 24, render: (a: string, b: any) => (<WidthEllipsis value={a} />) },
                { title: '备注', dataIndex: 'remark', label: '客户管理操作', align: 'center', width: 80, default: 25, render: (a: string, b: any) => (<WidthEllipsis value={a} />) },
            ]
        },
        {
            label: '操作',
            data: [
                {
                    title: '操作',
                    dataIndex: 'cz',
                    align: 'center',
                    width: 70,
                    label: '操作',
                    default: 26,
                    render: (_: any, b: any) => {
                        return <Space>
                            <LookRoleDetails userId={b.userId} />
                            <a style={{ fontSize: 12 }} onClick={() => { assignHandle([b]) }}>指派</a>
                        </Space>
                    }
                }
            ]
        }
    ]
}

export default columns12