import { copy } from "@/utils/utils"
import { Badge, Space } from "antd"
import React from "react"

function tableConfig(callback: (records: any, type: string) => void): any {
    return [
        {
            title: '操作',
            dataIndex: 'cz',
            key: 'cz',
            width: 70,
            align: 'center',
            fixed: 'left',
            render: (_: any, records: any) => {
                return records?.operationName === '添加创意' ? <Space>
                    <a style={{ color: '#1890ff', fontSize: 12 }} onClick={() => { callback(records, 'log') }}>创意日志</a>
                </Space> : '--'
            }
        },
        {
            title: '所属账号',
            dataIndex: 'accountId',
            key: 'accountId',
            align: 'center',
            width: 80,
            fixed: 'left',
            ellipsis: true,
            render: (a: string) => {
                return <Space>
                    <a style={{ fontSize: 12 }} onClick={() => copy(a)} >{a}</a>
                </Space>
            }
        },
        {
            title: '广告ID',
            dataIndex: 'adgroupId',
            key: 'adgroupId',
            align: 'center',
            width: 100,
            fixed: 'left',
            ellipsis: true,
            render: (a: string) => {
                return <Space>
                    <a style={{ fontSize: 12 }} onClick={() => copy(a)} >{a}</a>
                </Space>
            }
        },
        {
            title: '广告名称',
            dataIndex: 'adgroupName',
            key: 'adgroupName',
            width: 280,
            ellipsis: true,
            render: (a: string) => {
                return <a style={{ wordBreak: 'break-all', fontSize: 12 }} onClick={() => { copy(a) }}>{a}</a>
            }
        },
        {
            title: '执行时间',
            dataIndex: 'createTime',
            key: 'createTime',
            width: 140,
            align: 'center',
            render: (a: string) => {
                return <span style={{ fontSize: 12 }}>{a}</span>
            }
        },
        {
            title: '操作者名字',
            dataIndex: 'operationByName',
            key: 'operationByName',
            width: 65,
            align: 'center',
            render: (a: string) => {
                return <span style={{ fontSize: 12 }}>{a}</span>
            }
        },
        {
            title: '操作类型名称',
            dataIndex: 'operationName',
            key: 'operationName',
            width: 70,
            align: 'center',
            render: (a: string) => {
                return <span style={{ fontSize: 12 }}>{a}</span>
            }
        },
        {
            title: '操作数',
            dataIndex: 'operationCount',
            key: 'operationCount',
            width: 60,
            align: 'center',
            render: (a: string) => {
                return <span style={{ fontSize: 12 }}>{a}</span>
            }
        },
        {
            title: '成功数',
            dataIndex: 'successCount',
            key: 'successCount',
            width: 60,
            align: 'center',
            render: (a: string) => {
                return <span style={{ fontSize: 12 }}>{a}</span>
            }
        },
        {
            title: '失败数',
            dataIndex: 'failCount',
            key: 'failCount',
            width: 60,
            align: 'center',
            render: (a: number) => {
                return <span style={a > 0 ? { color: 'red', fontSize: 12 } : { fontSize: 12 }}>{a}</span>
            }
        },
        {
            title: '状态',
            dataIndex: 'status',
            key: 'status',
            width: 70,
            align: 'center',
            render: (a: any) => {
                let obj = {
                    '成功': 'success',
                    '失败': 'error',
                    '执行中': 'warning'
                }
                return <Badge status={obj[a]} text={a} />
            }
        },
        {
            title: '完成时间',
            dataIndex: 'updateTime',
            key: 'updateTime',
            width: 140,
            align: 'center',
            render: (a: string) => {
                return <span style={{ fontSize: 12 }}>{a}</span>
            }
        },
        {
            title: '错误消息',
            dataIndex: 'errorMsg',
            key: 'errorMsg',
            width: 400,
            ellipsis: true,
            render: (a: string) => {
                return <span style={{ fontSize: 12 }}>{a}</span>
            }
        },
        {
            title: '操作参数',
            dataIndex: 'requestJson',
            key: 'requestJson',
            width: 400,
            ellipsis: true,
            render: (a: string) => {
                return <span style={{ fontSize: 12 }}>{a}</span>
            }
        },
    ]
}


export default tableConfig