import { PageStatusEnum } from "@/services/launchAdq/enum"
import { Badge, TableProps, Tag } from "antd"
import React from "react"
import QrCode from "../QrCode"

let columns = (type?: 1 | 2 | 3): TableProps<any>['columns'] => {

    if (type === 2) {  // 灵鹊落地页
        return [
            {
                title: '是否可用?',
                dataIndex: 'disableCode',
                key: 'disableCode',
                width: 80,
                fixed: 'left',
                align: 'center',
                render(value) {
                    return <Tag style={{ fontSize: 12 }} color={value === 0 ? 'success' : 'error'}>{value === 0 ? '可用' : '不可用'}</Tag>
                },
            },
            {
                title: '落地页ID',
                dataIndex: 'pageId',
                key: 'pageId',
                align: 'center',
                width: 95,
                ellipsis: true
            },
            {
                title: '落地页名称',
                dataIndex: 'pageName',
                key: 'pageName',
                ellipsis: true,
                width: 300
            },
            {
                title: '落地页状态',
                dataIndex: 'pageStatus',
                key: 'pageStatus',
                align: 'center',
                width: 90,
                render: (a: string | number) => {
                    return <Badge status={a === 'NORMAL' ? "success" : a === 'DELETED' ? "error" : 'processing'} text={PageStatusEnum[a as keyof typeof PageStatusEnum]} />
                }
            },
            {
                title: '不可用原因',
                dataIndex: 'disableMessage',
                key: 'disableMessage',
                ellipsis: true,
                width: 200
            },
        ]
    } else if (type === 3) { // 微信小程序
        return [
            {
                title: '微信小程序名称',
                dataIndex: 'appletName',
                key: 'appletName',
                width: 160,
                ellipsis: true,
                fixed: 'left',
                render: (a) => {
                    return <span style={{ fontSize: "12px" }}>{a}</span>
                }
            },
            {
                title: '微信小程序原始ID',
                dataIndex: 'appletId',
                key: 'appletId',
                width: 180,
                ellipsis: true,
                render: (a) => {
                    return <span style={{ fontSize: "12px" }}>{a}</span>
                }
            },
            {
                title: '微信小程序路径',
                dataIndex: 'appletLink',
                key: 'appletLink',
                width: 380,
                ellipsis: true,
                render: (a) => {
                    return <span style={{ fontSize: "12px" }}>{a}</span>
                }
            },
            {
                title: '详细描述',
                dataIndex: 'description',
                key: 'description',
                ellipsis: true,
                render: (a) => {
                    return <span style={{ fontSize: "12px" }}>{a || '--'}</span>
                }
            },
            {
                title: '创建人',
                dataIndex: 'createByName',
                key: 'createByName',
                align: 'center',
                width: 75,
                ellipsis: true,
                render: (a) => {
                    return <span style={{ fontSize: "12px" }}>{a || '--'}</span>
                }
            },
            {
                title: '更新人',
                dataIndex: 'createByName',
                key: 'createByName',
                align: 'center',
                width: 75,
                ellipsis: true,
                render: (a) => {
                    return <span style={{ fontSize: "12px" }}>{a || '--'}</span>
                }
            },
            {
                title: '创建时间',
                dataIndex: 'createTime',
                key: 'createTime',
                align: 'center',
                width: 140,
                ellipsis: true,
                render: (a) => {
                    return <span style={{ fontSize: "12px" }}>{a}</span>
                }
            }
        ]
    }
    return [
        {
            title: '落地页ID',
            dataIndex: 'pageId',
            key: 'pageId',
            align: 'center',
            width: 90
        },
        {
            title: '落地页名称',
            dataIndex: 'pageName',
            key: 'pageName',
            ellipsis: true
        },
        {
            title: '预览',
            dataIndex: 'previewUrl',
            key: 'previewUrl',
            width: 60,
            align: 'center',
            render(value) {
                return <QrCode url={value}/>
            }
        },
        {
            title: '落地页状态',
            dataIndex: 'pageStatus',
            key: 'pageStatus',
            align: 'center',
            width: 90,
            render: (a: string | number) => {
                return <Badge status={a === 'NORMAL' ? "success" : a === 'DELETED' ? "error" : 'processing'} text={PageStatusEnum[a as keyof typeof PageStatusEnum]} />
            }
        }
    ]
}
export default columns