import { getOtpCodeExpiration } from '../getOtpCodeExpiration.mjs';
import { useGlobalReducer, useStytch, useConfig } from '../GlobalContextProvider.mjs';
import { useMutate } from '../utils.mjs';

const useEmailOtpDiscoverySend = ({ throwOnError } = {})=>{
    const [, dispatch] = useGlobalReducer();
    const stytchClient = useStytch();
    const config = useConfig();
    return useMutate('stytch.otps.email.discovery.send', (_key, { arg: { email } })=>stytchClient.otps.email.discovery.send({
            email_address: email,
            login_template_id: config.emailOtpOptions?.loginTemplateId,
            locale: config.emailOtpOptions?.locale
        }), {
        onSuccess: ()=>{
            dispatch({
                type: 'send_email_otp',
                codeExpiration: getOtpCodeExpiration()
            });
        },
        throwOnError
    });
};

export { useEmailOtpDiscoverySend };
//# sourceMappingURL=useEmailOtpDiscoverySend.mjs.map
