import { useLingui, Trans } from '../../../../../../node_modules/@lingui/react/dist/index.mjs';
import React__default from 'react';
import EmailActionLayout from '../../components/molecules/EmailActionLayout.mjs';
import { useGlobalReducer, useEventCallback, useConfig } from '../GlobalContextProvider.mjs';
import { AppScreens } from '../types/AppScreens.mjs';
import { usePasswordInput } from '../usePasswordInput.mjs';
import { StytchEventType } from '../../../../../core/src/public/ui.mjs';

const PasswordSetNew = ()=>{
    const [, dispatch] = useGlobalReducer();
    const onEvent = useEventCallback();
    const config = useConfig();
    const { i18n: $__i18n, _: $__ } = useLingui();
    const { stytch, onError, email, organization, setIsSubmitting } = usePasswordInput();
    const resendResetPassword = ()=>{
        if (!organization) {
            return stytch.passwords.discovery.resetByEmailStart({
                email_address: email,
                discovery_redirect_url: config.passwordOptions?.discoveryRedirectURL,
                reset_password_redirect_url: config.passwordOptions?.resetPasswordRedirectURL,
                reset_password_expiration_minutes: config.passwordOptions?.resetPasswordExpirationMinutes,
                reset_password_template_id: config.passwordOptions?.resetPasswordTemplateId,
                verify_email_template_id: config.passwordOptions?.verifyEmailTemplateId,
                locale: config.passwordOptions?.locale
            }).then((data)=>{
                setIsSubmitting(false);
                onEvent({
                    type: StytchEventType.B2BPasswordDiscoveryResetStart,
                    data
                });
            });
        } else {
            return stytch.passwords.resetByEmailStart({
                email_address: email,
                organization_id: organization.organization_id,
                login_redirect_url: config.passwordOptions?.loginRedirectURL,
                reset_password_redirect_url: config.passwordOptions?.resetPasswordRedirectURL,
                reset_password_expiration_minutes: config.passwordOptions?.resetPasswordExpirationMinutes,
                reset_password_template_id: config.passwordOptions?.resetPasswordTemplateId,
                verify_email_template_id: config.passwordOptions?.verifyEmailTemplateId,
                locale: config.passwordOptions?.locale
            }).then((data)=>{
                setIsSubmitting(false);
                onEvent({
                    type: StytchEventType.B2BPasswordResetByEmailStart,
                    data
                });
            }).catch((e)=>{
                onError(e);
                throw e;
            });
        }
    };
    return /*#__PURE__*/ React__default.createElement(EmailActionLayout, {
        header: $__i18n._({
            id: "password.reset.emailSent.title",
            message: "Check your email"
        }),
        description: /*#__PURE__*/ React__default.createElement(Trans, {
            id: "password.reset.emailSent.content",
            message: "A login link was sent to you at <bold>{email}</bold>.",
            components: {
                bold: /*#__PURE__*/ React__default.createElement("b", null)
            },
            values: {
                email
            }
        }),
        resend: resendResetPassword,
        goBack: ()=>dispatch({
                type: 'transition',
                screen: AppScreens.Main
            })
    });
};

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