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): 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: 85
            },
            {
                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
            },
        ]
    }
    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