import { Trash } from 'iconsax-react'
import { FC, useState } from 'react'
import { useDeletePlan } from '../hooks/useSupportData'
import ModalConfrim from '../../../components/ModalConfrim'

type Props = {
    id: string,
    refetch: () => void
}

const Delete: FC<Props> = ({ id, refetch }) => {
    const { mutate: deletePlan, isPending } = useDeletePlan()
    const [isOpen, setIsOpen] = useState(false)
    const close = () => setIsOpen(false)
    return (
        <div>
            <Trash size={20} color='#8C90A3' onClick={() => setIsOpen(true)} />

            <ModalConfrim
                isOpen={isOpen}
                close={close}
                onConfrim={() => {
                    deletePlan(id, {
                        onSuccess: () => {
                            setIsOpen(false)
                            refetch()
                        }
                    })
                }}
                isLoading={isPending}
            />
        </div>
    )
}

export default Delete