import { PayScene, PayStatus, PayType, gameClassifyEnum } from "@/components/QueryForm/const"
import WidthEllipsis from "@/components/widthEllipsis"
import { Badge, Space, Statistic } from "antd"
import React from "react"
import LogA from "./logA"

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

    return [
        {
            label: '回传信息',
            data: [
                {
                    title: '回传状态', dataIndex: 'backStatus', label: '回传信息', width: 100, default: 38,
                    render: (a: any) => {
                        return a === -1 ? <Badge status="error" text="回传失败" /> : a === 0 ? <Badge status="warning" text="未回传" /> : a === 1 ? <Badge status="success" text="回传成功" /> : a === 2 ? <Badge status="default" text="部分成功" /> : '--'
                    }
                },
                {
                    title: '回传金额', dataIndex: 'backMoney', label: '回传信息', align: 'center', width: 100, default: 36,
                    render: (a: any, b: any) => <Statistic value={a || 0} valueStyle={b?.day === '总计' ? { color: 'red' } : {}} precision={2} />
                },
                {
                    title: '回传信息', dataIndex: 'backMsg', label: '回传信息', align: 'center', width: 150, default: 37,
                    render: (a: string, b: any) => (<WidthEllipsis value={a} />)
                }
            ]
        },
        {
            label: '订单明细',
            data: [
                {
                    title: '日期（订单创建日期）', dataIndex: 'day1', label: '订单明细', align: 'center', width: 85, default: 1,
                    render: (a: string, b: any) => (<WidthEllipsis value={b?.day} />)
                },
                {
                    title: '商户订单号ID', dataIndex: 'orderId', label: '订单明细', align: 'center', width: 120, default: 2,
                    render: (a: string, b: any) => (<WidthEllipsis isCopy value={a} />)
                },
                {
                    title: 'CP订单号', dataIndex: 'cpOrderId', label: '订单明细', align: 'center', width: 130, default: 3,
                    render: (a: string, b: any) => (<WidthEllipsis isCopy value={a} />)
                },
                {
                    title: '第三方支付订单号', dataIndex: 'merchantOrderNo', label: '订单明细', align: 'center', width: 85, default: 4,
                    render: (a: string, b: any) => (<WidthEllipsis isCopy value={a} />)
                },
                {
                    title: '计划ID', dataIndex: 'promotionId', label: '订单明细', align: 'center', width: 90,
                    render: (a: string, b: any) => (<WidthEllipsis isCopy value={a} />)
                },
                {
                    title: '广告ID', dataIndex: 'projectId', label: '订单明细', align: 'center', width: 90,
                    render: (a: string, b: any) => (<WidthEllipsis isCopy value={a} />)
                },
                {
                    title: '玩家ID', dataIndex: 'gameUserId', label: '订单明细', align: 'center', width: 65, default: 5,
                    render: (a: string, b: any) => (<WidthEllipsis isCopy value={a} />)
                },
                {
                    title: '玩家账号', dataIndex: 'username', label: '订单明细', align: 'center', width: 95, default: 6,
                    render: (a: string, b: any) => (<WidthEllipsis isCopy value={a} />)
                },
                {
                    title: '玩家注册时间', dataIndex: 'regTime', label: '订单明细', align: 'center', width: 135, default: 7, sorter: true,
                    render: (a: string, b: any) => (<WidthEllipsis value={a} />)
                },
                {
                    title: '玩家注册渠道', dataIndex: 'agentName', label: '订单明细', align: 'center', width: 70, default: 8,
                    render: (a: string, b: any) => (<WidthEllipsis value={a} />)
                },
                {
                    title: '玩家注册游戏', dataIndex: 'gameName', label: '订单明细', align: 'center', width: 70, default: 9,
                    render: (a: string, b: any) => (<WidthEllipsis value={a} />)
                },
                {
                    title: 'CP名称', dataIndex: 'cpName', label: '订单明细', align: 'center', width: 95, default: 10,
                    render: (a: string, b: any) => (<WidthEllipsis value={a} />)
                },
                {
                    title: '玩家注册游戏应用类型', dataIndex: 'classify', label: '订单明细', align: 'center', width: 80, default: 11,
                    render: (a: string) => (<span>{gameClassifyEnum[a as keyof typeof gameClassifyEnum]}</span>)
                },
                {
                    title: '归因投放人员', dataIndex: 'zxPitcherName', label: '订单明细', align: 'center', width: 65, default: 12,
                    render: (a: string, b: any) => (<WidthEllipsis value={a} />)
                },
                {
                    title: '玩家充值游戏', dataIndex: 'orderGameName', label: '订单明细', align: 'center', width: 70, default: 13,
                    render: (a: string, b: any) => (<WidthEllipsis value={a} />)
                },
                {
                    title: '玩家充值游戏应用类型', dataIndex: 'orderGameClassify', label: '订单明细', align: 'center', width: 80, default: 14,
                    render: (a: string, b: any) => (<WidthEllipsis value={gameClassifyEnum[a as keyof typeof gameClassifyEnum]} />)
                },
                {
                    title: '订单金额', dataIndex: 'amount', label: '订单明细', align: 'center', width: 95, default: 15, sorter: true,
                    render: (a: any, b: any) => <Statistic value={a || 0} valueStyle={b?.day === '总计' ? { color: 'red' } : {}} precision={2} />
                },
                {
                    title: '订单实付金额', dataIndex: 'realAmount', label: '订单明细', align: 'center', width: 95, default: 16, sorter: true,
                    render: (a: any, b: any) => <Statistic value={a || 0} valueStyle={b?.day === '总计' ? { color: 'red' } : {}} precision={2} />
                },
                {
                    title: '角色累计充值金额', dataIndex: 'roleTotalAmount', label: '订单明细', align: 'center', width: 100, default: 34,
                    render: (a: any, b: any) => {
                        if (b?.day === '总计') {
                            return '--'
                        } else {
                            return <Statistic value={a || 0} valueStyle={b?.day === '总计' ? { color: 'red' } : {}} precision={2} />
                        }
                    }
                },
                {
                    title: '角色累计充值次数', dataIndex: 'roleTotalAmountCount', label: '订单明细', align: 'center', width: 90, default: 35,
                    render: (a: any, b: any) => {
                        if (b?.day === '总计') {
                            return '--'
                        } else {
                            return <Statistic value={a || 0} valueStyle={b?.day === '总计' ? { color: 'red' } : {}} />
                        }
                    }
                },
                {
                    title: '角色注册7日内订单数', dataIndex: 'roleOrder7DayTotal', label: '订单明细', align: 'center', width: 90,
                    render: (a: any, b: any) => {
                        if (b?.day === '总计') {
                            return '--'
                        } else {
                            return <Statistic value={a || 0} valueStyle={b?.day === '总计' ? { color: 'red' } : {}} />
                        }
                    }
                },
                {
                    title: '购买商品', dataIndex: 'productName', label: '订单明细', align: 'center', width: 95, default: 17,
                    render: (a: string, b: any) => (<WidthEllipsis value={a} />)
                },
                {
                    title: '支付方式', dataIndex: 'payway', label: '订单明细', align: 'center', width: 65, default: 18,
                    render: (a: string, b: any) => (<WidthEllipsis value={PayType[a as keyof typeof PayType]} />)
                },
                {
                    title: '支付场景', dataIndex: 'payScene', label: '订单明细', align: 'center', width: 95, default: 19,
                    render: (a: string, b: any) => (<WidthEllipsis value={PayScene[a as keyof typeof PayScene]} />)
                },
                {
                    title: '收款账户名', dataIndex: 'merchantName', label: '订单明细', align: 'center', width: 95, default: 20,
                    render: (a: string, b: any) => (<WidthEllipsis value={a} />)
                },
                {
                    title: '收款账户', dataIndex: 'payAccountId', label: '订单明细', align: 'center', width: 95, default: 21,
                    render: (a: string, b: any) => (<WidthEllipsis value={a} />)
                },
                {
                    title: '原始服务器名', dataIndex: 'sourceServerName', label: '订单明细', align: 'center', width: 85, default: 22,
                    render: (a: string, b: any) => (<WidthEllipsis value={a} />)
                },
                {
                    title: '游戏区服', dataIndex: 'serverName', label: '订单明细', align: 'center', width: 85, default: 23,
                    render: (a: string, b: any) => (<WidthEllipsis value={a} />)
                },
                {
                    title: '游戏角色', dataIndex: 'roleName', label: '订单明细', align: 'center', width: 85, default: 24,
                    render: (a: string, b: any) => (<WidthEllipsis value={a} />)
                },
                {
                    title: '角色等级', dataIndex: 'roleLevel', label: '订单明细', align: 'center', width: 50, default: 25,
                    render: (a: string, b: any) => (<WidthEllipsis value={a} />)
                },
                {
                    title: '角色VIP', dataIndex: 'roleVip', label: '订单明细', align: 'center', width: 45, default: 26,
                    render: (a: string, b: any) => (<WidthEllipsis value={a} />)
                },
                {
                    title: '操作系统', dataIndex: 'os', label: '订单明细', align: 'center', width: 65, default: 27,
                    render: (a: string, b: any) => (<WidthEllipsis value={a} />)
                },
                {
                    title: '是否切量', dataIndex: 'orderIsSwitch', label: '订单明细', align: 'center', width: 45, default: 28,
                    render: (a: string, b: any) => (<WidthEllipsis value={a} />)
                },
                {
                    title: '下单时间', dataIndex: 'orderCreateTime', label: '订单明细', align: 'center', width: 135, default: 29, sorter: true,
                    render: (a: string, b: any) => (<WidthEllipsis value={a} />)
                },
                {
                    title: '支付时间', dataIndex: 'payTime', label: '订单明细', align: 'center', width: 135, default: 30, sorter: true,
                    render: (a: string, b: any) => (<WidthEllipsis value={a} />)
                },
                {
                    title: '注册充值时间差',
                    dataIndex: 'regUntilPay',
                    align: 'center',
                    width: 140,
                    default: 31,
                    render: (a: number) => {
                        if (a) {
                            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 `${days ? days + "天" : ''}${hours ? hours + "小时" : ''}${minutes ? minutes + "分" : ''}${remainingSeconds ? remainingSeconds + "秒" : ''}`
                            }
                            return a ? secondsToDhms(a) : '--'
                        } else {
                            return '--'
                        }
                    }
                },
                {
                    title: '最近充值时间距今',
                    dataIndex: 'payUntilNow',
                    align: 'center',
                    width: 150,
                    default: 32,
                    render: (a: number) => {
                        if (a) {
                            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 `${days ? days + "天" : ''}${hours ? hours + "小时" : ''}${minutes ? minutes + "分" : ''}${remainingSeconds ? remainingSeconds.toFixed(0) + "秒" : ''}`
                            }
                            return a ? secondsToDhms(a) : '--'
                        } else {
                            return '--'
                        }
                    }
                },
                {
                    title: '支付状态', dataIndex: 'orderStatus', label: '订单明细', align: 'center', width: 85, default: 33,
                    render: (a: string, b: any) => PayStatus[a as keyof typeof PayStatus]
                },
                {
                    title: '是否首充', dataIndex: 'isFirstRecharge', label: '订单明细', align: 'center', width: 45, default: 39,
                    render: (a: any, b: any) => {
                        if (b?.day !== '总计') {
                            return a == 1 ? '是' : '否'
                        }
                        return '--'
                    }
                },
                {
                    title: '游戏类型', dataIndex: 'category', label: '订单明细', align: 'center', width: 80,
                    render: (a: string, b: any) => {
                        const c = {
                            CATEGORY_WX_APPLET: '微信小游戏',
                            CATEGORY_H5: 'h5游戏',
                            CATEGORY_IOS_APP: 'IOS APP',
                            CATEGORY_ANDROID_APP: 'Android APP',
                            CATEGORY_DY_APPLET: '抖音小游戏',
                            CATEGORY_APP: 'APP'
                        }
                        return <WidthEllipsis value={c[a as keyof typeof c]} />
                    }
                },
                {
                    title: '投放类型', dataIndex: 'putType', label: '订单明细', align: 'center', width: 80,
                    render: (a: string, b: any) => {
                        const c = {
                            '0': '导量APP',
                            '1': '头条直投APP',
                            '2': '腾讯直投APP',
                            '3': '头条私域投APP',
                            '4': '腾讯私域投APP'
                        }
                        return <WidthEllipsis value={c[a as keyof typeof c]} />
                    }
                },
                {
                    title: '拆单笔数', dataIndex: 'backCount', label: '订单明细', align: 'center', width: 80, sorter: true,
                    render: (a: string, b: any) => (<WidthEllipsis value={a} />)
                },
                {
                    title: '操作',
                    dataIndex: 'cz',
                    label: '订单明细',
                    align: 'center',
                    width: 140,
                    default: 40,
                    render: (a: any, b: any) => {
                        if (b?.day !== '总计') {
                            return <Space>
                                {b?.backTableName && <LogA orderId={b?.orderId} backTableName={b?.backTableName}/>}
                                {(b?.backStatus !== 2 && b?.backStatus !== 1) && <a onClick={() => back(b)}>回传</a>}
                                <a onClick={() => onDetail(b)}>订单详情</a>
                            </Space>
                        }
                        return '--'

                    }
                }
            ]
        },
    ]
}

export default columns12