import { Flex, 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 PreviewMomentsContent from "../create/components/content/previewMomentsContent";
import { QuestionCircleFilled } from "@ant-design/icons";
import PreviewMomentsStrategy from "../create/components/Strategy/previewMomentsStrategy";

const { Text, Paragraph } = Typography;
const taskListColumns = (
    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: 230,
            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: '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: 'momentCreateDTO',
            key: 'momentCreateDTO',
            width: 170,
            ellipsis: true,
            render: (value) => {
                if (value && Object.keys(value)?.length > 0) {
                    return <div className={style.nameBox}>
                        <div>
                            <Text ellipsis>{value?.momentSendName || '<空>'}</Text>
                        </div>
                        <Popover
                            placement="left"
                            content={<div>
                                <PreviewMomentsStrategy
                                    massSendingStrategy={value}
                                />
                            </div>}
                            styles={{ body: { width: 360, overflow: 'hidden', overflowY: 'auto', maxHeight: 400 } }}
                        >
                            <a><QuestionCircleFilled /></a>
                        </Popover>
                        <Popover
                            placement="left"
                            content={<div>
                                <PreviewMomentsContent
                                    strategyList={value.strategyList}
                                />
                            </div>}
                            styles={{ body: { width: 360, 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: 'taskCount',
            key: 'taskCount',
            width: 260,
            render(value, record) {
                return <Flex gap={6}>
                    <Text type={record.momentCreateCount > 0 ? 'success' : 'danger'}>朋友圈：{record.momentCreateCount}</Text>
                </Flex>
            },
        },
    ]
}


export default taskListColumns