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

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

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