import { FC, useState } from 'react'
import { useSummarizeEmail } from '../hooks/useEmailData';
import { InboxMessage } from '@/pages/draft/types/DraftTypes';
import Intelligense from '@/assets/images/intelligense.svg'
import SummarizeModal from './SummarizeModal';

const Summerize: FC<{ id: string, mailbox: string, item: InboxMessage }> = ({ id, mailbox, item }) => {

    const [open, setOpen] = useState(false)
    const { mutate: summarizeEmail, isPending } = useSummarizeEmail();
    // eslint-disable-next-line @typescript-eslint/no-explicit-any
    const [data, setData] = useState<any>()

    const handleSummarizeEmail = () => {
        setOpen(true)
        summarizeEmail({ messageId: Number(id), mailbox }, {
            onSuccess: (data) => {
                setData(data)
            }
        });
    };


    return (
        <div>
            <div onClick={handleSummarizeEmail}>
                <img src={Intelligense} alt='summerize' className='min-w-[18px] z-1 ' />
            </div>


            <SummarizeModal open={open} onClose={() => setOpen(false)} isPending={isPending} item={item} id={id} mailbox={mailbox} data={data} />
        </div>
    )
}

export default Summerize