import { Button, Popconfirm, Space, Tag, Badge, Typography } from "antd";
import { ColumnsType } from "antd/es/table";
const { Paragraph } = Typography;

export function TableConfig(edit: (row: any, isCopy?: boolean) => void, del: (value: any) => void, taskPause: (pause: boolean, taskId: number[]) => void): ColumnsType<any> {

    let arr: ColumnsType<any> = [
        {
            title: '企业名称',
            dataIndex: 'corpUserVO',
            key: 'corpUserVO',
            align: 'center',
            width: 150,
            ellipsis: true,
            render(value) {
                return value?.[0]?.corpName
            },
        },
        {
            title: '企业ID',
            dataIndex: 'corpId',
            key: 'corpId',
            align: 'center',
            width: 150,
            ellipsis: true
        },
        {
            title: '企微号',
            dataIndex: 'corpUserVO',
            key: 'corpUserVO',
            width: 450,
            render(value) {
                return <Paragraph style={{ margin: 0 }} ellipsis={{ rows: 3, tooltip: { mouseEnterDelay: 1, placement: 'bottomLeft', styles: { body: { maxHeight: 450, width: 500, overflow: 'auto' } } } }}>{value?.map((item: { name: any; }) => item.name).toString()}</Paragraph>
            },
        },
        {
            title: '企微号ID',
            dataIndex: 'corpUserId',
            key: 'corpUserId',
            width: 450,
            render(value) {
                return <Paragraph style={{ margin: 0 }} ellipsis={{ rows: 3, tooltip: { mouseEnterDelay: 1, placement: 'bottomLeft', styles: { body: { maxHeight: 450, width: 500, overflow: 'auto' } } } }}>{value?.toString()}</Paragraph>
            },
        },
        {
            title: '风险等级',
            dataIndex: 'riskLevel',
            key: 'riskLevel',
            align: 'center',
            width: 100,
            render: (a: any, b: any) => {
                return a ? ["", <Badge color="#ffccc7" text="低" />, <Badge color="#ff7875" text="中" />, <Badge color="#cf1322" text="高" />][a] : "--"
            }
        },
        {
            title: '风险词',
            dataIndex: 'keywordJson',
            key: 'keywordJson',
            align: 'center',
            ellipsis: true,
            width: 450,
            render: (a) => {
                return <Space size={[0, 0]} wrap>
                    {
                        a?.map((str: any, index: number) => {
                            return <Tag key={index}>{str}</Tag>
                        })
                    }
                </Space>
            }
        },
        {
            title: '启用状态',
            dataIndex: 'enabled',
            key: 'enabled',
            align: 'center',
            width: 90,
            render: (a: any) => {
                return a ? <Tag color="success">启用</Tag> : <Tag color="error">禁用</Tag>
            }
        },
        {
            title: '创建人',
            dataIndex: 'sysUserRpcVO',
            key: 'sysUserRpcVO',
            align: 'center',
            width: 90,
            ellipsis: true,
            render(a) {
                return a?.nickName || '--'
            }
        },
        {
            title: '创建时间',
            dataIndex: 'createTime',
            key: 'createTime',
            align: 'center',
            width: 140,
            ellipsis: true
        },
        {
            title: '更新时间',
            dataIndex: 'updateTime',
            key: 'updateTime',
            align: 'center',
            width: 140,
            ellipsis: true
        },
        {
            title: '操作',
            dataIndex: 'cz',
            key: 'cz',
            width: 150,
            fixed: 'right',
            render: (_, b) => {
                return <Space>
                    <Button type="link" style={{ padding: 0 }} onClick={() => { edit(b, true) }}>复制</Button>
                    {b?.sysUserRpcVO?.userId == sessionStorage.getItem('userId') ? <>
                        {b?.enabled === false ? <>
                            <Button type="link" style={{ padding: 0 }} onClick={() => { edit(b) }}>编辑</Button>
                            <Button type="link" style={{ padding: 0 }} onClick={() => { taskPause(true, [b.id]) }}>启用</Button>
                            <Popconfirm
                                title='确定删除？'
                                onConfirm={() => { del(b?.id) }}
                            >
                                <Button type="link" style={{ padding: 0 }} danger>删除</Button>
                            </Popconfirm>
                        </> : b?.enabled === true ? <>
                            <Button type="link" style={{ padding: 0 }} danger onClick={() => { taskPause(false, [b.id]) }}>禁用</Button>
                        </> : null}
                    </> : <>--</>}
                </Space>
            }
        },
    ]
    return arr
}