import useSendWithButton from '../useSendWithButton'
import { composeSignUpURL, processSignUp } from '../../api/signup'
import { isSignUpResponse } from '../../api/signup/types'

function useSignUp() {
    const { doSend, button } = useSendWithButton(
        'Я здесь впервые',
        'Зарегистрирован',
        false,
        composeSignUpURL(),
        'POST',
        false,
        isSignUpResponse,
        processSignUp,
    )

    async function handleSignUp(formData: FormData) {
        const res = await doSend({}, {
            body: formData,
        })

        return res ?? false
    }

    return { handleSignUp, signUpButton: button }
}

export default useSignUp
