import { Space, Tag, Tooltip, Typography } from "antd";
import { ColumnsType } from "antd/es/table";
const { Text } = Typography;

export function TableConfig(lockUsers: (v: any) => void, chatLog: (v: any) => void): ColumnsType<any> {

    const arr: ColumnsType<any> = [
        {
            title: '客户群',
            dataIndex: 'chatName',
            key: 'chatName',
            width: 300,
            fixed: 'left',
            render(value) {
                return value ? <Text copyable ellipsis>{value}</Text> : '--'
            },
        },
        {
            title: '群主',
            dataIndex: 'ownerName',
            key: 'ownerName',
            align: 'center',
            width: 80,
            fixed: 'left',
        },
        {
            title: '备注',
            dataIndex: 'remark',
            key: 'remark',
            width: 140,
            ellipsis: true,
            render(value) {
                return value || '--'
            },
        },
        {
            title: '群人数',
            dataIndex: 'userCount',
            key: 'userCount',
            align: 'center',
            width: 65,
        },
        {
            title: '企业名称',
            dataIndex: 'corpName',
            key: 'corpName',
            align: 'center',
            width: 180,
            ellipsis: true
        },
        {
            title: '绑定公众号',
            dataIndex: 'mpAccount',
            key: 'mpAccount',
            align: 'center',
            width: 100,
            ellipsis: true,
            render(value) {
                return value?.name || '--'
            },
        },
        {
            title: '群公告',
            dataIndex: 'notice',
            key: 'notice',
            width: 400,
            ellipsis: true,
            render: (a: any) => {
                return a || '--'
            }
        },
        {
            title: '群标签',
            dataIndex: 'chatTagNames',
            key: 'chatTagNames',
            width: 300,
            ellipsis: {
                showTitle: false
            },
            render: (a: string) => {
                return a ? <Tooltip placement="topLeft" title={a}>
                    {a.split(',').sort((a, b) => {
                        if (a.startsWith('QC_') && !b.startsWith('QC_')) {
                            return -1;
                        } else if (!a.startsWith('QC_') && b.startsWith('QC_')) {
                            return 1;
                        } else {
                            return 0;
                        }
                    }).map((item: string, index) => <span key={index}><span style={item.includes('QC') ? { color: 'red' } : {}}>{item}</span>,</span>)}
                </Tooltip> : '--'
            }
        },
        {
            title: '创建时间',
            dataIndex: 'createTime',
            key: 'createTime',
            align: 'center',
            width: 150
        },
        {
            title: '操作',
            dataIndex: 'cz',
            key: 'cz',
            align: 'center',
            width: 100,
            fixed: 'right',
            render: (a, b) => {
                return <Space>
                    <a onClick={() => lockUsers(b)}>客户</a>
                    <a onClick={() => chatLog(b)}>变更记录</a>
                </Space>
            }
        }
    ]
    return arr
}

export function TableConfigLog(): ColumnsType<any> {

    const arr: ColumnsType<any> = [
        {
            title: '群名',
            dataIndex: 'chatName',
            key: 'chatName',
            ellipsis: true,
            width: 150
        },
        {
            title: '群主',
            dataIndex: 'ownerName',
            key: 'ownerName',
            ellipsis: true,
            align: 'center',
            width: 80
        },
        {
            title: '执行状态',
            dataIndex: 'executionStatus',
            key: 'executionStatus',
            width: 90,
            align: 'center',
            render(value) {
                return value === 1 ? '执行中' : value === 100 ? '执行成功' : value === -1 ? '执行失败' : '--'
            },
        },
        {
            title: '任务创建时间',
            dataIndex: 'taskTime',
            key: 'taskTime',
            ellipsis: true,
            align: 'center',
            width: 130
        },
        {
            title: '创建者名称',
            dataIndex: 'createName',
            key: 'createName',
            ellipsis: true,
            align: 'center',
            width: 80
        },
        {
            title: '任务结果',
            dataIndex: 'disbandStatus',
            key: 'disbandStatus',
            width: 90,
            align: 'center',
            render(value) {
                return value === 1 ? <Tag bordered={false} color="success">成功</Tag> : value === 0 ? <Tag bordered={false} color="error">失败</Tag> : '--'
            },
        },
        {
            title: '完成时间',
            dataIndex: 'finishTime',
            key: 'finishTime',
            ellipsis: true,
            align: 'center',
            width: 130
        },
        {
            title: '失败信息',
            dataIndex: 'errorMsg',
            key: 'errorMsg',
            ellipsis: true,
            width: 250,
            render(value) {
                return value || '--'
            },
        },
    ]

    return arr
}