import { Popconfirm, Space } from "antd"
import { ColumnsType } from "antd/es/table"


export function GroupTableConfig(handleUser: (data: any) => void, handleEdit: (data: any) => void, handleDel: (id: number) => void): ColumnsType<any> {

    const arr: ColumnsType<any> = [
        {
            title: '项目组名称',
            dataIndex: 'name',
            key: 'name',
            width: 150,
            ellipsis: true,
            fixed: 'left'
        },
        {
            title: '项目组成员',
            dataIndex: 'userList',
            key: 'userList',
            width: 400,
            ellipsis: true,
            render(value) {
                return value?.length > 0 ? value.map((item: any) => item.nickname).join(',') : '--'
            }
        },
        {
            title: '描述',
            dataIndex: 'description',
            key: 'description',
            width: 220,
            ellipsis: true,
            render(value) {
                return value || '--'
            },
        },
        {
            title: '创建人',
            dataIndex: 'createByInfo',
            key: 'createByInfo',
            width: 100,
            ellipsis: true,
            align: 'center',
            render(value) {
                return value?.nickname || '--'
            },
        },
        {
            title: '创建时间',
            dataIndex: 'createTime',
            key: 'createTime',
            width: 135,
            ellipsis: true,
            align: 'center'
        },
        {
            title: '操作',
            dataIndex: 'cz',
            key: 'cz',
            align: 'center',
            width: 130,
            fixed: 'right',
            render(_, record) {
                return <Space>
                    <a onClick={() => handleUser(record)}>成员更新</a>
                    <a onClick={() => handleEdit(record)}>修改</a>
                    <Popconfirm
                        title="确认删除?"
                        onConfirm={() => handleDel(record.id)}
                    >
                        <a style={{ color: 'red' }}>删除</a>
                    </Popconfirm>
                </Space>
            },
        }
    ]
    return arr
}