import { useAjax } from '@/Hook/useAjax';
import { getProjectLogListApi } from '@/pages/weComTask/API/businessPlan/create';
import { Drawer, Spin } from 'antd';
import React, { useEffect, useState } from 'react';
import GroupTask from './components/groupTask';


interface Props {
    data: any,
    bookPlatForm: TASK_CREATE.BookPlatFormProps[]
    bookList: TASK_CREATE.BookListProps[]
    visible?: boolean,
    onClose?: () => void
}

export const DispatchTaskDetails = React.createContext<TASK_CREATE.DispatchTaskDetails | null>(null);
/**
 * 任务日志
 * @param param0 
 * @returns 
 */
const Log: React.FC<Props> = ({ data, visible, onClose, bookPlatForm, bookList }) => {

    /******************************************************/
    const [previewData, setPreviewData] = useState<{ robotGroupChatSendTaskVOList?: any[] }>({})
    const getProjectLogList = useAjax((params) => getProjectLogListApi(params))
    /******************************************************/

    useEffect(() => {
        getProjectLogList.run(data.id).then(res => {
            if (res?.data) {
                setPreviewData(res.data)
            }
        })
    }, [])

    return <Drawer
        title={<strong>{data.projectName} 任务详情</strong>}
        onClose={onClose}
        open={visible}
        width={1400}
        styles={{ body: { paddingTop: 5 } }}
    >

        <Spin spinning={getProjectLogList.loading}>
            <DispatchTaskDetails.Provider
                value={{ bookPlatForm, bookList }}
            >
                <GroupTask robotGroupChatSendTaskVOList={previewData?.robotGroupChatSendTaskVOList} />
            </DispatchTaskDetails.Provider>
        </Spin>
    </Drawer>
};

export default Log;