import { convertMagicLinkOptions, convertPasswordResetOptions } from '../../../../utils/index.mjs';
import { useGlobalReducer, useStytch, useConfig, AppScreens } from '../../GlobalContextProvider.mjs';

/**
 * Handle the common behavior part of email actions, used in conjunction with <EmailActionLayout>
 */ function useResetResendPasswordActions() {
    const [state, dispatch] = useGlobalReducer();
    const stytchClient = useStytch();
    const email = state.formState.passwordState.email;
    const { emailMagicLinksOptions, passwordOptions } = useConfig();
    return {
        email,
        resendResetPassword: ()=>stytchClient.passwords.resetByEmailStart(convertPasswordResetOptions(email, passwordOptions)),
        sendMagicLink: async ()=>{
            const result = await stytchClient.magicLinks.email.loginOrCreate(email, convertMagicLinkOptions(emailMagicLinksOptions));
            dispatch({
                type: 'transition',
                screen: AppScreens.EmailConfirmation
            });
            return result;
        },
        goBack: ()=>dispatch({
                type: 'transition',
                screen: AppScreens.Main
            })
    };
}

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