import React from "react"
import { Badge, Col, Popconfirm, Row, Space, Tooltip } from "antd"
import { QuestionCircleOutlined } from "@ant-design/icons"
import dic from "../weChat/components/createPlan/components/Dic"
let columns = (callBack: (name: string, posType: number) => void, del: (id: string) => void) => [
    {
        title: '任务名称',
        dataIndex: 'taskName',
        key: 'taskName',
        align: 'left',
        width: 180,
        ellipsis: true,
        fixed: 'left',
        render: (a: any, b: any) => {
            return <span style={{ fontSize: "12px" }}>{a || '--'}</span>
        }
    },
    {
        title: '计划名称',
        dataIndex: 'plans',
        key: 'planName',
        align: 'center',
        width: 150,
        ellipsis: true,
        render: (a: any, b: any) => {
            if (a?.length > 0) {
                return <span style={{ fontSize: "12px" }}>{a[0].planName || '--'}</span>
            } else {
                return <span>--</span>
            }
        }
    },
    {
        title: '投放位置',
        dataIndex: 'plans',
        key: 'putLocation',
        align: 'center',
        width: 120,
        render: (a: any, b: any) => {
            if (a?.length > 0) {
                return <span style={{ fontSize: "12px" }}>{a[0].putLocation || '--'}</span>
            } else {
                return <span>--</span>
            }
        }
    },
    {
        title: '推广目标',
        dataIndex: 'plans',
        key: 'putTarget',
        align: 'center',
        width: 100,
        render: (a: any, b: any) => {
            if (a?.length > 0) {
                return <span style={{ fontSize: "12px" }}>{dic.promotionTarget[a[0].putTarget] || '--'}</span>
            } 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: '任务状态',
        dataIndex: 'createStatus',
        key: 'createStatus',
        align: 'center',
        width: 100,
        render: (a: any, b: any) => {
            return <span style={{ fontSize: "12px" }}>
                {a === 0 ? <span><Badge status="warning" />创建中</span> : a === 100 ? <span><Badge status="processing" />创建成功</span> : a === -1 ? <span><Badge status="error" />创建失败</span> : a === 1 ? <span><Badge status="success" />部分成功</span> : <></>}
            </span>
        }
    },
    {
        title: <>广告数 <Tooltip title="计划-广告-创意">
            <QuestionCircleOutlined />
        </Tooltip></>,
        dataIndex: 'planCount',
        key: 'planCount',
        align: 'center',
        width: 90,
        render: (a: any, b: any) => {
            return <span style={{ fontSize: "12px" }}>{a + '-' + a + '-1'}</span>
        }
    },
    {
        title: '任务反馈',
        dataIndex: 'planSuccess',
        key: 'planSuccess',
        align: 'left',
        // width: 300,
        render: (a: any, b: any) => {
            return <Row gutter={10}>
                <Col style={{ fontSize: 12 }}>
                    <div style={{ width: 125 }}><Badge status="processing" />计划总条数：{b?.planCount}条</div>
                </Col>
                <Col style={{ fontSize: 12 }}>
                    <div style={{ width: 105 }}><Badge status="warning" />执行中：{b?.createStatus === 0 ? b?.planCount : 0}条</div>
                </Col>
                <Col style={{ fontSize: 12 }}>
                    <div style={{ width: 110 }}><Badge status="success" />执行成功：{a}条</div>
                </Col>
                <Col style={{ fontSize: 12 }}>
                    <div style={{ width: 110 }}><Badge status="error" />执行失败：{b?.createStatus === 0 ? 0 : b?.planCount - a}条</div>
                </Col>
            </Row>
        }
    },
    {
        title: '操作',
        dataIndex: 'taskName',
        key: 'taskName',
        align: 'center',
        width: 80,
        fixed: 'right',
        render: (a: any, b: any) => {
            return <Space>
                <a style={{ color: '#1890ff', fontSize: 12 }} onClick={() => { callBack(a, b?.plans[0]?.posType) }}>详情</a>
                <Popconfirm
                    title={`你确定删除"${b?.taskName}"这个任务?`}
                    onConfirm={() => { del(b?.id) }}
                    okText="Yes"
                    cancelText="No"
                >
                    <a style={{ color: 'red', fontSize: 12 }}>删除</a>
                </Popconfirm>
            </Space>
        }
    }
]

export default columns