import React__default from 'react';
import { useCountdown } from '../../components/atoms/Countdown.mjs';
import { EmailConfirmationView } from '../../components/organisms/EmailConfirmationView.mjs';
import { useGlobalReducer } from '../GlobalContextProvider.mjs';
import { useEmlDiscoverySend } from '../hooks/useEmlDiscoverySend.mjs';
import { useEmlLoginOrSignup } from '../hooks/useEmlLoginOrSignup.mjs';
import { AppScreens } from '../types/AppScreens.mjs';
import { useEmailDomain } from './useEmailDomain.mjs';
import { AuthFlowType } from '../../../../../core/src/public/b2b/ui.mjs';

const EmailConfirmation = ()=>{
    const [state, dispatch] = useGlobalReducer();
    const emailDomain = useEmailDomain();
    const countdown = useCountdown();
    const { trigger: sendLoginOrSignupEml, isMutating: isSendingLoginOrSignupEml } = useEmlLoginOrSignup();
    const { trigger: sendDiscoveryEml, isMutating: isSendingDiscoveryEml } = useEmlDiscoverySend();
    const email = state.formState.emailState.userSuppliedEmail;
    const goBack = ()=>{
        dispatch({
            type: 'set_user_supplied_email',
            email: ''
        });
        dispatch({
            type: 'transition',
            screen: AppScreens.Main
        });
    };
    const resend = async ()=>{
        if (state.flowState.type === AuthFlowType.Discovery) {
            await sendDiscoveryEml({
                email
            });
        } else if (state.flowState.type === AuthFlowType.Organization && state.flowState.organization) {
            await sendLoginOrSignupEml({
                email,
                organization_id: state.flowState.organization.organization_id
            });
        }
    };
    const isSubmitting = isSendingLoginOrSignupEml || isSendingDiscoveryEml;
    return /*#__PURE__*/ React__default.createElement(EmailConfirmationView, {
        emailDomain: emailDomain,
        email: email,
        goBack: goBack,
        resend: resend,
        countdown: countdown,
        isSubmitting: isSubmitting
    });
};

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