import { Popconfirm, Popover, Space, Typography } from "antd";
import { AnyObject } from "antd/es/_util/type";
import { ColumnsType } from "antd/es/table";
import style from '../../businessPlan/taskList/index.less'
import { QuestionCircleFilled } from '@ant-design/icons';
import PreviewStrategy from "../create/components/strategy/previewStrategy";
import PreviewGroupUser from "../create/components/groupUser/previewGroupUser";
import { getPullGroupData } from "../create/const";

const { Text, Paragraph } = Typography;
const taskListColumns = (
    bookPlatForm: TASK_CREATE.BookPlatFormProps[],
    bookList: TASK_CREATE.BookListProps[],
    handleLog: (data: any) => void,
    handleCopy: (data: any, isCopy: boolean) => void,
    handleDel: (data: any, type: 'del' | 'cancel' | 'open') => void,
): ColumnsType<AnyObject> => {

    return [
        {
            title: '操作',
            dataIndex: 'cz',
            key: 'cz',
            width: 200,
            render(_, record) {
                return <Space>
                    {record?.status === 1 ? <Popconfirm
                        title="确定暂停？"
                        onConfirm={() => { handleDel({ projectIds: [record.id] }, 'cancel') }}
                    >
                        <a style={{ color: 'orange' }}>暂停任务</a>
                    </Popconfirm> : record?.status === 3 ? <Popconfirm
                        title="确定启用？"
                        onConfirm={() => { handleDel({ projectIds: [record.id] }, 'open') }}
                    >
                        <a style={{ color: '#87d068' }}>启用任务</a>
                    </Popconfirm> : undefined}
                    <a onClick={() => handleCopy(record, true)}>复制</a>
                    <a onClick={() => handleCopy(record, false)}>编辑</a>
                    <a onClick={() => handleLog(record)}>详情</a>
                    <Popconfirm
                        title="确定删除？"
                        onConfirm={() => { handleDel({ projectIds: [record.id] }, 'del') }}
                    >
                        <a style={{ color: 'red' }}>删除</a>
                    </Popconfirm>
                </Space>
            },
        },
        {
            title: '任务名称',
            dataIndex: 'taskName',
            key: 'taskName',
            width: 120,
            ellipsis: true
        },
        {
            title: '项目组',
            dataIndex: 'projectGroupInfo',
            key: 'projectGroupInfo',
            width: 120,
            ellipsis: true,
            align: 'center',
            render(value) {
                return value?.name || '--'
            },
        },
        {
            title: '基础信息',
            dataIndex: 'bizType',
            key: 'bizType',
            width: 180,
            render: (_, record) => {
                return <Paragraph style={{ margin: 0 }} ellipsis={{ tooltip: true }}>
                    业务类型：{record?.bizType === 'novel' ? '小说' : '<空>'}-书城：{record?.platformName || '<空>'}-适用产品：{record?.templateProductName || '<空>'}
                </Paragraph>
            }
        },
        {
            title: '群主号',
            dataIndex: 'corpChatUserList',
            key: 'corpChatUserList',
            width: 130,
            render(value) {
                return <Paragraph style={{ margin: 0 }} ellipsis={{ tooltip: true }}>{value.map((item) => item.name + `（${item.corpName}）`).join('、')}</Paragraph>
            }
        },
        {
            title: '机器人客服号',
            dataIndex: 'corpRobots',
            key: 'corpRobots',
            width: 130,
            render(value) {
                return value?.length > 0 ? <Paragraph style={{ margin: 0 }} ellipsis={{ tooltip: true }}>{value.map((item) => item.corpUserName + `（${item.corpName}）`).join('、')}</Paragraph> : '--'
            }
        },
        {
            title: '客服号',
            dataIndex: 'corpUsers',
            key: 'corpUsers',
            width: 150,
            render(value) {
                return <Paragraph style={{ margin: 0 }} ellipsis={{ tooltip: true }}>{value.map((item) => item.corpUserName + `（${item.corpName}）`).join('、')}</Paragraph>
            }
        },
        {
            title: '群聊创建配置预览',
            dataIndex: 'strategyList',
            key: 'strategyList',
            width: 150,
            ellipsis: true,
            render: (_, record) => {
                if (record?.strategyList?.length > 0) {
                    const data = getPullGroupData(record?.strategyList || [])
                    return <div className={style.nameBox}>
                        <Popover
                            placement="left"
                            content={<div>
                                <PreviewStrategy strategyDTO={{
                                    strategyList: record?.strategyList
                                }} />
                            </div>}
                            styles={{ body: { width: 300, overflow: 'hidden', overflowY: 'auto', maxHeight: 400 } }}
                        >
                            <a>策略 <QuestionCircleFilled /></a>
                        </Popover>
                        <Popover
                            placement="left"
                            content={<div>
                                <PreviewGroupUser
                                    strategyList={data?.strategyList || []}
                                    bookList={bookList}
                                    bookPlatForm={bookPlatForm}
                                />
                            </div>}
                            styles={{ body: { width: 700, overflow: 'hidden', overflowY: 'auto', maxHeight: 400 } }}
                        >
                            <a>群配置 <QuestionCircleFilled /></a>
                        </Popover>
                    </div>
                }
                return <Text type="danger">当前没有欢迎语配置</Text>
            }
        },
        {
            title: '创建人',
            dataIndex: 'createByInfo',
            key: 'createByInfo',
            align: 'center',
            width: 100,
            ellipsis: true,
            render(value) {
                return <Text ellipsis>{value?.nickName || '--'}</Text>
            }
        },
        {
            title: '创建时间',
            dataIndex: 'createTime',
            key: 'createTime',
            align: 'center',
            width: 125,
            ellipsis: true
        },
        {
            title: '拉群任务数量',
            dataIndex: 'corpPullGroupTaskCount',
            key: 'corpPullGroupTaskCount',
            width: 100,
            align: 'center',
            render(value) {
                return value
            },
        },
    ]
}


export default taskListColumns