import { PageStatusEnum } from "@/services/launchAdq/enum"
import { Badge, Space, TableProps } from "antd"
import React from "react"
import QrCode from "../../components/QrCode"
import DelPage from "./delPage"

let columns = (handleCopy: (data: any) => void, refresh?: () => void, accountId?: number): TableProps<any>['columns'] => {

    return [
        {
            title: '操作',
            dataIndex: 'cz',
            key: 'cz',
            align: 'center',
            width: 120,
            render(_, record) {
                let { canvasType } = record
                if (canvasType === 'COMMON_PAGE') {
                    return '--'
                }
                return <Space>
                    <a style={{ fontSize: 12 }} onClick={() => handleCopy(record)}>批量复制</a>
                    {record.ownerUid === accountId && <DelPage accountId={record.ownerUid} pageIds={[record.pageId]} onChange={refresh}/>}
                </Space>
            }
        },
        {
            title: '落地页ID',
            dataIndex: 'pageId',
            key: 'pageId',
            align: 'center',
            width: 100,
            render(value) {
                return <span style={{ fontSize: 12 }}>{value}</span>
            }
        },
        {
            title: '落地页名称',
            dataIndex: 'pageName',
            key: 'pageName',
            ellipsis: true,
            render(value) {
                return <span style={{ fontSize: 12 }}>{value}</span>
            }
        },
        {
            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={<span style={{ fontSize: 12 }}>{PageStatusEnum[a as keyof typeof PageStatusEnum]}</span>} />
            }
        }
    ]
}
export default columns