

import { Row, Col, Popconfirm, Tag } from "antd"
import { DeleteOutlined, EditOutlined } from "@ant-design/icons"
import WidthEllipsis from "@/components/widthEllipsis"
import React from "react"
import { conditionEnum } from "./strategyModal"

function columnsPos(editPack: (data: any) => void, del: (id: number) => void) {

    let newArr: any = [
        {
            title: '超父游戏ID',
            dataIndex: 'superGameId',
            key: 'superGameId',
            align: 'center',
            width: 60
        },
        {
            title: '超父游戏名称',
            dataIndex: 'superGameName',
            key: 'superGameName',
            align: 'center',
            width: 90,
            render: (a: string, b: any) => (<WidthEllipsis value={a} />)
        },
        {
            title: '策略类型',
            dataIndex: 'type',
            key: 'type',
            align: 'center',
            width: 100,
            render: (a: number, b: any) => {
                return { 1: <Tag color="#f50">追踪玩家</Tag>, 2: <Tag color="#2db7f5">玩家流失</Tag>, 3: <Tag color="#87d068">新用户追踪</Tag>, 4: <Tag color="#108ee9">累充追踪</Tag>, 5: <Tag color="#2f8eef">新增角色追踪</Tag> }[a]
            }
        },
        {
            title: '金额（元）',
            dataIndex: 'amount',
            key: 'amount',
            align: 'center',
            width: 100,
            render: (a: any, b: any) => {
                return ((a && a !== 0) && b?.amountCondition) ? conditionEnum[b?.amountCondition as keyof typeof conditionEnum] + " " + a : '--'
            }
        },
        {
            title: '时间（小时）',
            dataIndex: 'time',
            key: 'time',
            align: 'center',
            width: 100,
            render: (a: any, b: any) => {
                return (b?.timeCondition && (a && a !== 0)) ? conditionEnum[b?.timeCondition  as keyof typeof conditionEnum] + " " + a : '--'
            }
        },
        {
            title: '策略备注',
            dataIndex: 'configExplain',
            key: 'configExplain',
            width: 150,
            render: (a: string, b: any) => (<WidthEllipsis value={a} />)
        },
        {
            title: '策略说明',
            dataIndex: 'configExplain',
            key: 'configExplain',
            width: 350,
            render: (a: string, b: any) => {
                const { type, time, amount, timeCondition, amountCondition } = b
                if (type) {
                    let timeTips: string = ''
                    let amountTips: string = ''
                    switch (type) {
                        case 1:
                            // 单笔充值金额大于等于XX,并且注册时间在XX小时内的玩家
                            timeTips = time ? `注册时间${conditionEnum[timeCondition  as keyof typeof conditionEnum]}${time}小时的玩家` : ''
                            amountTips = amount ? `单笔充值金额${conditionEnum[amountCondition  as keyof typeof conditionEnum]}${amount}元` : ''
                            break
                        case 2:
                            // 累计充值金额大于等于XX,并且最近游戏距今时间超过XX小时的玩家
                            amountTips = amount ? `累计充值金额${conditionEnum[amountCondition  as keyof typeof conditionEnum]}${amount}元` : ''
                            timeTips = time ? `最近游戏距今时间${conditionEnum[timeCondition  as keyof typeof conditionEnum]}${time}小时的玩家` : ''
                            break
                        case 3:
                            // '新用户注册创角首日充值大于等于XX的用户'
                            amountTips = amount ? `新用户注册创角首日充值${conditionEnum[amountCondition  as keyof typeof conditionEnum]}${amount}元的用户` : ''
                            break
                        case 5:
                            amountTips = amount ? `新创建的角色在创角至今${conditionEnum[timeCondition as keyof typeof conditionEnum]}${time}小时内，首次充值（角色首充，单笔充值）${conditionEnum[amountCondition as keyof typeof conditionEnum]}${amount}金额，触发报警一次` : ''
                            break
                    }
                    let helpTips = ''
                    if (timeTips && amountTips) {
                        helpTips = amountTips + '，并且' + timeTips + '，发送钉钉消息'
                    } else if (timeTips) {
                        helpTips = timeTips + '，发送钉钉消息'
                    } else if (amountTips) {
                        helpTips = amountTips + '，发送钉钉消息'
                    }
                    return <WidthEllipsis value={helpTips} />
                } else {
                    return '--'
                }
            }
        },
        {
            title: '告警人员',
            dataIndex: 'userNameStr',
            key: 'userNameStr',
            align: 'center',
            width: 110,
            render: (a: string, b: any) => (<WidthEllipsis value={a} />)
        },
        {
            title: '排除指标标签',
            dataIndex: 'tagsNameStr',
            key: 'tagsNameStr',
            align: 'center',
            width: 100,
            render: (a: string, b: any) => (<WidthEllipsis value={a} />)
        },
        {
            title: '创建人',
            dataIndex: 'createName',
            key: 'createName',
            align: 'center',
            width: 80,
            render: (a: string, b: any) => (<WidthEllipsis value={a} />)
        },
        {
            title: '创建时间',
            dataIndex: 'createTime',
            key: 'createTime',
            align: 'center',
            width: 135,
            render: (a: string, b: any) => (<WidthEllipsis value={a} />)
        },
        {
            title: '更新人',
            dataIndex: 'updateName',
            key: 'updateName',
            align: 'center',
            width: 80,
            render: (a: string, b: any) => (<WidthEllipsis value={a} />)
        },
        {
            title: '更新时间',
            dataIndex: 'updateTime',
            key: 'updateTime',
            align: 'center',
            width: 135,
            render: (a: string, b: any) => (<WidthEllipsis value={a} />)
        },
        {
            title: '操作',
            dataIndex: 'cz',
            key: 'cz',
            align: 'center',
            width: 100,
            fixed: 'right',
            render: (a: string, b: any) => (
                <Row justify='center' gutter={[10, 0]}>
                    <Col><a style={{ fontSize: "12px" }} onClick={() => { editPack(b) }}><EditOutlined /> 修改</a></Col>
                    <Col>
                        <Popconfirm
                            title="确定删除?"
                            onConfirm={() => { del(b.id) }}
                            okText="是"
                            cancelText="否"
                        >
                            <a style={{ fontSize: "12px", color: 'red' }}><DeleteOutlined /> 删除</a>
                        </Popconfirm>
                    </Col>
                </Row>
            )
        }
    ]
    return newArr
}


export default columnsPos