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

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

    return [
        {
            label: '基本信息',
            data: [
                {
                    title: '角色名称', dataIndex: 'role_name', label: '基本信息', align: 'center', width: 85, default: 1,
                    render: (a: string) => (<WidthEllipsis value={a} />)
                },
                {
                    title: '角色ID', dataIndex: 'role_id', label: '基本信息', align: 'center', width: 85,
                    render: (a: string) => (<WidthEllipsis value={a} />)
                },
                {
                    title: '玩家名称', dataIndex: 'user_name', label: '基本信息', align: 'center', width: 90, default: 2,
                    render: (a: string) => (<WidthEllipsis value={a} />)
                },
                {
                    title: '玩家ID', dataIndex: 'user_id', label: '基本信息', align: 'center', width: 85,
                    render: (a: string) => (<WidthEllipsis value={a} />)
                },
                {
                    title: '游戏名称', dataIndex: 'game_name', label: '基本信息', align: 'center', width: 85, default: 3,
                    render: (a: string) => (<WidthEllipsis value={a} />)
                },
                {
                    title: '游戏ID', dataIndex: 'game_id', label: '基本信息', align: 'center', width: 85,
                    render: (a: string) => (<WidthEllipsis value={a} />)
                },
                {
                    title: '区服名称', dataIndex: 'server_name', label: '基本信息', align: 'center', width: 80, default: 4,
                    render: (a: string) => (<WidthEllipsis value={a} />)
                },
                {
                    title: '区服ID', dataIndex: 'server_id', label: '基本信息', align: 'center', width: 80,
                    render: (a: string) => (<WidthEllipsis value={a} />)
                },
                {
                    title: '角色创建时间', dataIndex: 'create_time', label: '基本信息', align: 'center', width: 125, default: 5, sorter: true,
                    render: (a: string, b: any) => (<WidthEllipsis value={a} />)
                },
                {
                    title: '角色等级', dataIndex: 'role_level', label: '基本信息', align: 'center', width: 60, sorter: true, default: 6,
                    render: (a: string) => <Statistic value={a || 0} />
                },
                {
                    title: '角色注册IP', dataIndex: 'ip', label: '基本信息', align: 'center', width: 110, default: 7,
                    render: (a: string) => <Statistic value={a || 0} />
                },
                {
                    title: '角色登录IP数量', dataIndex: 'ip_count', label: '基本信息', align: 'center', width: 65, sorter: true, default: 8,
                    render: (a: number, b: any) => <Statistic value={a || 0} valueStyle={a > 1 ? { color: 'red' } : {}} suffix={<LoginIpDetails gameId={b.game_id} roleId={b.role_id} icon={<EyeOutlined />} />} />
                },
                {
                    title: '同玩家角色数量', dataIndex: 'user_role_count', label: '基本信息', align: 'center', width: 65, sorter: true, default: 9,
                    render: (a: number, b: any) => <Statistic value={a || 0} valueStyle={a > 1 ? { color: 'red' } : {}} suffix={<LookRoleDetails userId={b.user_id} icon={<EyeOutlined />} />} />
                },
                {
                    title: '角色同IP的玩家数量', dataIndex: 'user_count', label: '基本信息', align: 'center', width: 70, sorter: true, default: 10,
                    render: (a: number, b: any) => <Statistic value={a || 0} valueStyle={a > 1 ? { color: 'red' } : {}} suffix={<TongIpUser roleId={b.role_id} icon={<EyeOutlined />} />} />
                },
                {
                    title: '同IP的角色数量', dataIndex: 'role_count', label: '基本信息', align: 'center', width: 70, sorter: true, default: 11,
                    render: (a: number, b: any) => <Statistic value={a || 0} valueStyle={a > 1 ? { color: 'red' } : {}} suffix={<RegIpRoleDetails roleId={b.role_id} excludeUserType={0} icon={<EyeOutlined />} />} />
                },
                {
                    title: '同IP的角色数量（排除同玩家）', dataIndex: 'ip_role_count_filter', label: '基本信息', align: 'center', width: 90, sorter: true, default: 12,
                    render: (a: number, b: any) => <Statistic value={a || 0} valueStyle={a > 1 ? { color: 'red' } : {}} suffix={<RegIpRoleDetails roleId={b.role_id} excludeUserType={1} icon={<EyeOutlined />} />} />
                },
                {
                    title: '同玩家IP的角色数量（排除同玩家）', dataIndex: 'role_user_ip_count_filter', label: '基本信息', align: 'center', width: 100, sorter: true, default: 13,
                    render: (a: number) => <Statistic value={a || 0} valueStyle={a > 1 ? { color: 'red' } : {}} />
                },
                {
                    title: '角色所在玩家登录过的所有IP的统计数量', dataIndex: 'role_user_ip_count', label: '基本信息', align: 'center', width: 100, sorter: true, default: 14,
                    render: (a: number) => <Statistic value={a || 0} valueStyle={a > 1 ? { color: 'red' } : {}} />
                },
                {
                    title: '创角时间至今', dataIndex: 'createTimeDiff', label: '角色游戏数据', align: 'center', width: 130, default: 15,
                    render: (_: any, b: any) => {
                        if (b?.create_time) {
                            let a = (new Date().getTime() / 1000) - (new Date(b?.create_time).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 '--'
                        }
                    }
                }

            ]
        }
    ]
}

export default columns12