import { 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 { restoreGroupData, restoreMomentData, restoreUserInheritData } from "../create/const";
import PreviewUserInherit from "../create/components/userInherit/previewUserlnherit";
import PreviewMassSendingStrategy from "../create/components/massSending/previewMassSendingStrategy";
import ShowContent from "../create/components/massSending/showContent";
import PreviewWelcome from "../create/components/welcome/previewWelcome";
import PreviewFriendsStrategy from "../create/components/friends/previewFriendsStrategy";
import ShowFriendsContent from "../create/components/friends/showFriendsContent";

const { Text, Paragraph } = Typography;
const taskListColumns = (
    bookPlatForm: any[],
    bookList: any[],
    handleLog: (data: any) => void,
): ColumnsType<AnyObject> => {


    return [
        {
            title: '操作',
            dataIndex: 'cz',
            key: 'cz',
            width: 120,
            render(_, record) {
                return <Space>
                    <a onClick={() => handleLog(record)}>详情</a>
                </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: 'welcomeMsgTemplateDTO',
            key: 'welcomeMsgTemplateDTO',
            width: 150,
            ellipsis: true,
            render: (_, record) => {
                return record?.welcomeMsgTemplateDTO && Object.keys(record?.welcomeMsgTemplateDTO)?.length > 0 ? <div className={style.nameBox}>
                    <div>
                        <Text ellipsis>{record?.welcomeMsgTemplateDTO?.welcomeName || '<空>'}</Text>
                    </div>
                    <Popover
                        placement="left"
                        content={<div>
                            <PreviewWelcome
                                welcomeMsgTemplateDTO={record?.welcomeMsgTemplateDTO}
                                bookList={bookList}
                                bookPlatForm={bookPlatForm}
                            />
                        </div>}
                        styles={{ body: { width: 300, overflow: 'hidden', overflowY: 'auto', maxHeight: 400 } }}
                    >
                        <a><QuestionCircleFilled /></a>
                    </Popover>
                </div> : <Text type="danger">当前没有欢迎语配置</Text>
            }
        },
        // {
        //     title: '朋友圈配置',
        //     dataIndex: 'momentCreateDTO',
        //     key: 'momentCreateDTO',
        //     width: 150,
        //     ellipsis: true,
        //     render: (value) => {
        //         if (value && Object.keys(value)?.length > 0) {
        //             const data = restoreMomentData(value)
        //             return <div className={style.nameBox}>
        //                 <div>
        //                     <Text ellipsis>{value?.momentSendName || '<空>'}</Text>
        //                 </div>
        //                 <Popover
        //                     placement="left"
        //                     content={<div>
        //                         <PreviewFriendsStrategy friendsStrategy={data?.friendsStrategy} />
        //                     </div>}
        //                     styles={{ body: { width: 360, overflow: 'hidden', overflowY: 'auto', maxHeight: 400 } }}
        //                 >
        //                     <a><QuestionCircleFilled /></a>
        //                 </Popover>
        //                 <Popover
        //                     placement="left"
        //                     content={<div>
        //                         <ShowFriendsContent
        //                             strategySettings={data?.friendsStrategy?.strategySettings}
        //                             friendsContent={data?.friendsContent}
        //                         />
        //                     </div>}
        //                     styles={{ body: { width: 360, overflow: 'hidden', overflowY: 'auto', maxHeight: 400 } }}
        //                 >
        //                     <a><QuestionCircleFilled /></a>
        //                 </Popover>
        //             </div>
        //         }
        //         return <Text type="danger">当前没有朋友圈配置</Text>
        //     }
        // },
        {
            title: '群发配置',
            dataIndex: 'groupSendTaskAddDTO',
            key: 'groupSendTaskAddDTO',
            width: 170,
            ellipsis: true,
            render: (value) => {
                if (value && Object.keys(value)?.length > 0) {
                    const data = restoreGroupData(value)
                    return <div className={style.nameBox}>
                        <div>
                            <Text ellipsis>{value?.groupSendName || '<空>'}</Text>
                        </div>
                        <Popover
                            placement="left"
                            content={<div>
                                <PreviewMassSendingStrategy
                                    massSendingStrategy={data.massSendingStrategy}
                                />
                            </div>}
                            styles={{ body: { width: 360, overflow: 'hidden', overflowY: 'auto', maxHeight: 400 } }}
                        >
                            <a><QuestionCircleFilled /></a>
                        </Popover>
                        <Popover
                            placement="left"
                            content={<div>
                                <ShowContent
                                    strategySettings={data?.massSendingStrategy?.strategySettings}
                                    massSendingContent={data?.massSendingContent}
                                />
                            </div>}
                            styles={{ body: { width: 360, overflow: 'hidden', overflowY: 'auto', maxHeight: 400 } }}
                        >
                            <a><QuestionCircleFilled /></a>
                        </Popover>
                    </div>
                }
                return <Text type="danger">当前没有群发配置</Text>
            }
        },
        // {
        //     title: '高级群发配置',
        //     dataIndex: 'messageSendTaskAddDTO',
        //     key: 'messageSendTaskAddDTO',
        //     width: 170,
        //     ellipsis: true,
        //     render: (value, record) => {
        //         if (value && Object.keys(value)?.length > 0) {
        //             const data = restoreGroupData(value, 'GROUP_GROUP')
        //             console.log('data', record.projectName, data)
        //             return <div className={style.nameBox}>
        //                 <div>
        //                     <Text ellipsis>{value?.groupSendName || '<空>'}</Text>
        //                 </div>
        //                 <Popover
        //                     placement="left"
        //                     content={<div>
        //                         <PreviewMassSendingStrategy
        //                             massSendingStrategy={data.massSendingStrategy}
        //                             configType='GROUP_GROUP'
        //                         />
        //                     </div>}
        //                     styles={{ body: { width: 360, overflow: 'hidden', overflowY: 'auto', maxHeight: 400 } }}
        //                 >
        //                     <a><QuestionCircleFilled /></a>
        //                 </Popover>
        //                 <Popover
        //                     placement="left"
        //                     content={<div>
        //                         <ShowContent
        //                             strategySettings={data?.massSendingStrategy?.strategySettings}
        //                             massSendingContent={data?.massSendingContent}
        //                             type="highQf"
        //                         />
        //                     </div>}
        //                     styles={{ body: { width: 360, overflow: 'hidden', overflowY: 'auto', maxHeight: 400 } }}
        //                 >
        //                     <a><QuestionCircleFilled /></a>
        //                 </Popover>
        //             </div>
        //         }
        //         return <Text type="danger">当前没有群发配置</Text>
        //     }
        // },
        {
            title: '客户继承配置',
            dataIndex: 'externalUserTransferTasksDTO',
            key: 'externalUserTransferTasksDTO',
            width: 150,
            ellipsis: true,
            render: (value) => {
                if (value && Object.keys(value)?.length > 0) {
                    const data = restoreUserInheritData(value)
                    return <div className={style.nameBox}>
                        <div>
                            <Text ellipsis>{value?.taskName || '<空>'}</Text>
                        </div>
                        <Popover
                            placement="left"
                            content={<div>
                                <PreviewUserInherit
                                    userInherit={data}
                                />
                            </div>}
                            styles={{ body: { width: 360, 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
        },
    ]
}


export default taskListColumns