import { useAjax } from '@/Hook/useAjax';
import { getProjectLogListApi } from '@/pages/weComTask/API/businessPlan/create';
import { Drawer, Input, 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<{ groupChatSendTaskVOList?: any[] }>({})
    const [taskId, setTaskId] = useState<string>()

    const getProjectLogList = useAjax((params) => getProjectLogListApi(params))
    /******************************************************/

    useEffect(() => {
        if (data?.msg === '跳转日志详情') {
            setTaskId(data.taskId)
        }
        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 } }}
    >
        <Input.Search placeholder="请输入任务ID" allowClear defaultValue={data?.taskId} onSearch={(value) => { setTaskId(value); }} style={{ marginBottom: 10, width: 250 }} />
        <Spin spinning={getProjectLogList.loading}>
            <DispatchTaskDetails.Provider
                value={{ bookPlatForm, bookList }}
            >
                <GroupTask groupSendTaskVOList={taskId ? previewData?.groupChatSendTaskVOList?.filter(item => item.id == taskId) : previewData?.groupChatSendTaskVOList} />
            </DispatchTaskDetails.Provider>
        </Spin>
    </Drawer>
};

export default Log;