import useSendWithButton from '../useSendWithButton'
import { composePutAnnouncementURL, processPutAnnouncement } from '../../api/putAnnouncement'
import { isPutAnnouncementResponse } from '../../api/putAnnouncement/types'

function useAddAnnouncement() {
    const { doSend, button } = useSendWithButton(
        'Опубликовать',
        'Опубликовано',
        true,
        composePutAnnouncementURL(),
        'PUT',
        true,
        isPutAnnouncementResponse,
        processPutAnnouncement
    )

    async function handleAdd(formData: FormData) {
        await doSend({}, {
            body: formData,
        })
    }

    return { handleAdd, addButton: button }
}

export default useAddAnnouncement
