import { useGlobalReducer, useStytch, useConfig } from '../GlobalContextProvider.mjs';
import { AppScreens } from '../types/AppScreens.mjs';
import { useMutate } from '../utils.mjs';
import { logger } from '../../../../../core/src/utils/logger.mjs';

const useEmlLoginOrSignup = ()=>{
    const [, dispatch] = useGlobalReducer();
    const stytchClient = useStytch();
    const config = useConfig();
    return useMutate('stytch.magicLinks.email.loginOrSignup', (_, { arg: { email, organization_id } })=>stytchClient.magicLinks.email.loginOrSignup({
            email_address: email,
            organization_id,
            login_redirect_url: config.emailMagicLinksOptions?.loginRedirectURL,
            signup_redirect_url: config.emailMagicLinksOptions?.signupRedirectURL,
            login_template_id: config.emailMagicLinksOptions?.loginTemplateId,
            signup_template_id: config.emailMagicLinksOptions?.signupTemplateId,
            locale: config.emailMagicLinksOptions?.locale
        }), {
        onSuccess: ()=>{
            dispatch({
                type: 'transition',
                screen: AppScreens.EmailConfirmation
            });
        },
        onError: (e)=>{
            logger.error(e);
        }
    });
};

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