import React from "react"
import { Badge, Space } from "antd"
import { AdStatus, PromotedObjectType, SpeedMode } from "@/services/launchAdq/enum"
import TargetingPopover from "../../components/targetingPopover"
import AdPopover from "../../components/adPopover"
function tableConfig(callback: (data: any, type: 'log' | 'page' | 'copy', allData?: any) => void): any {
    return [
        {
            title: '操作',
            dataIndex: 'taskName',
            key: 'taskName',
            width: 80,
            align: 'center',
            render: (a: any, b: any) => {
                return <Space>
                    <a style={{ color: '#1890ff', fontSize: 12 }} onClick={() => { callback({ taskId: b.id, campaignName: b.campaignName }, 'log', b) }}>日志</a>
                    <a style={{ color: '#1890ff', fontSize: 12 }} onClick={() => { callback({ taskId: b.id, campaignName: b.campaignName,putModel:b.putModel }, 'copy') }}>复制</a>
                </Space>
            }
        },
        {
            title: 'ID',
            dataIndex: 'id',
            key: 'id',
            align: 'center',
            width: 50,
        },
        {
            title: '计划名称',
            dataIndex: 'campaignName',
            key: 'campaignName',
            align: 'left',
            width: 180,
            ellipsis: true,
            render: (a: any, b: any) => {
                return <span style={{ fontSize: "12px" }}>{a || '--'}</span>
            }
        },
        {
            title: '计划类型',
            dataIndex: 'campaignType',
            key: 'campaignType',
            align: 'center',
            width: 120,
            render: (a: any, b: any) => {
                if (a) {
                    return <span style={{ fontSize: "12px" }}>{a === 'CAMPAIGN_TYPE_NORMAL' ? '普通展示广告' : '微信朋友圈广告'}</span>
                } else {
                    return <span>--</span>
                }
            }
        },
        {
            title: '广告状态',
            dataIndex: 'configuredStatus',
            key: 'configuredStatus',
            align: 'center',
            width: 80,
            render: (a: any, b: any) => {
                if (a) {
                    return <span style={{ fontSize: "12px" }}>{AdStatus[a]}</span>
                } else {
                    return <span>--</span>
                }
            }
        },
        {
            title: '推广目标',
            dataIndex: 'promotedObjectType',
            key: 'promotedObjectType',
            align: 'center',
            width: 100,
            render: (a: any, b: any) => {
                if (a) {
                    return <span style={{ fontSize: "12px" }}>{PromotedObjectType[a]}</span>
                } else {
                    return <span>--</span>
                }
            }
        },
        {
            title: '投放速度模式',
            dataIndex: 'speedMode',
            key: 'speedMode',
            align: 'center',
            width: 90,
            render: (a: any, b: any) => {
                if (a) {
                    return <span style={{ fontSize: "12px" }}>{SpeedMode[a]}</span>
                } else {
                    return <span>--</span>
                }
            }
        },
        {
            title: '广告',
            dataIndex: 'sysAdgroupId',
            key: 'sysAdgroupId',
            align: 'center',
            width: 90,
            ellipsis: true,
            render: (a: any, b: any) => {
                if (a) {
                    return <AdPopover name={b?.sysAdgroup?.adgroupName} id={a} />
                } else {
                    return <span>--</span>
                }
            }
        },
        {
            title: '定向ID',
            dataIndex: 'sysTargetingId',
            key: 'sysTargetingId',
            align: 'center',
            width: 80,
            render: (a: any, b: any) => {
                if (a) {
                    return <Space><span style={{ fontSize: "12px" }}>{a}</span><TargetingPopover id={b.sysTargetingId} /></Space>
                } else {
                    return <span>--</span>
                }
            }
        },
        {
            title: '创建时间',
            dataIndex: 'createTime',
            key: 'createTime',
            align: 'center',
            width: 140,
            render: (a: any, b: any) => {
                return <span style={{ fontSize: "12px" }}>{a || '--'}</span>
            }
        },
        {
            title: <span style={{ marginLeft: 10 }}>任务反馈</span>,
            dataIndex: 'total',
            key: 'total',
            render: (a: any, b: any) => {
                let errCount = a - (b?.successCount || 0)
                return <Space style={{ fontSize: "12px", marginLeft: 10 }} size={20}>
                    <span><Badge status="processing" />总条数：{a}条</span>
                    {<span><Badge status="success" />成功数：{b?.successCount || 0}条</span> }
                    {/* {errCount ? <span><Badge status="error" />创建中：{errCount}条</span> : null} */}
                </Space>
            }
        }
    ]
}

export default tableConfig