import { Flex, Popconfirm, Popover, Space, Typography } from "antd";
import { AnyObject } from "antd/es/_util/type";
import { ColumnsType } from "antd/es/table";
import style from './index.less'
import { QuestionCircleFilled } from '@ant-design/icons';
import { getGroupChatSendData } from "../create/const";
import PreviewStrategy from "../create/components/Strategy/previewStrategy";
import { DefaultOptionType } from "antd/es/select";
import PreviewContent from "../create/components/content/previewContent";

const { Text, Paragraph } = Typography;
const taskListColumns = (
    mpList: DefaultOptionType[],
    corpList: DefaultOptionType[],
    handleLog: (data: any) => void,
    handleCopy: (data: any, isCopy: boolean, isEditSc?: boolean) => void,
    handleDel: (data: any, type: 'del' | 'cancel' | 'open') => void,
): ColumnsType<AnyObject> => {

    return [
        {
            title: '操作',
            dataIndex: 'cz',
            key: 'cz',
            width: 160,
            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={() => handleCopy(record, false, true)}>编辑素材</a>
                    <a onClick={() => handleLog(record)}>详情</a>
                    <Popconfirm
                        title="确定删除？"
                        onConfirm={() => { handleDel({ projectIds: [record.id] }, 'del') }}
                    >
                        <a style={{ color: 'red' }}>删除</a>
                    </Popconfirm>
                </Space>
            },
        },
        {
            title: '任务名称',
            dataIndex: 'projectName',
            key: 'projectName',
            width: 120,
            ellipsis: true
        },
        {
            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: 'groupChatSendTaskAddDTO',
            key: 'groupChatSendTaskAddDTO',
            width: 170,
            ellipsis: true,
            render: (value) => {
                if (value && Object.keys(value)?.length > 0) {
                    const data = getGroupChatSendData(value)
                    return <div className={style.nameBox}>
                        <div>
                            <Text ellipsis>{value?.groupSendName || '<空>'}</Text>
                        </div>
                        <Popover
                            placement="left"
                            content={<div>
                                <PreviewStrategy strategyDTO={data} />
                            </div>}
                            styles={{ body: { width: 380, overflow: 'hidden', overflowY: 'auto', maxHeight: 400 } }}
                        >
                            <a><QuestionCircleFilled /></a>
                        </Popover>
                        <Popover
                            placement="left"
                            content={<div>
                                <PreviewContent strategyList={data?.strategyList} />
                            </div>}
                            styles={{ body: { width: 500, overflow: 'hidden', overflowY: 'auto', maxHeight: 400 } }}
                        >
                            <a><QuestionCircleFilled /></a>
                        </Popover>
                    </div>
                }
                return <Text type="danger">当前没有群发配置</Text>
            }
        },
        {
            title: '创建时间',
            dataIndex: 'createTime',
            key: 'createTime',
            align: 'center',
            width: 125,
            ellipsis: true
        },
        {
            title: '任务数量',
            dataIndex: 'taskCount',
            key: 'taskCount',
            width: 260,
            render(_, record) {
                return <Flex gap={6}>
                    <Text type={record.groupSendTaskCount > 0 ? 'success' : 'danger'}>群发：{record.groupSendTaskCount}</Text>
                </Flex>
            },
        },
    ]
}


export default taskListColumns