import { useLingui } from '../../../../../../node_modules/@lingui/react/dist/index.mjs';
import React__default, { useMemo } from 'react';
import { useGlobalReducer } from '../../b2b/GlobalContextProvider.mjs';
import { AppScreens } from '../../b2b/types/AppScreens.mjs';
import { ErrorType } from '../../b2b/types/ErrorType.mjs';
import Button from '../atoms/Button.mjs';
import Column from '../atoms/Column.mjs';
import TextColumn from './TextColumn.mjs';

const ErrorDisplay = ({ text, onGoBack })=>{
    const { i18n: $__i18n, _: $__ } = useLingui();
    return /*#__PURE__*/ React__default.createElement(Column, {
        gap: 6
    }, /*#__PURE__*/ React__default.createElement(TextColumn, {
        header: $__i18n._({
            id: "error.title",
            message: "Looks like there was an error!"
        }),
        body: text
    }), onGoBack && /*#__PURE__*/ React__default.createElement(Button, {
        variant: "outline",
        onClick: onGoBack
    }, $__i18n._({
        id: "button.goBack",
        message: "Go back"
    })));
};
const ErrorScreen = ()=>{
    const [state, dispatch] = useGlobalReducer();
    const { i18n: $__i18n, _: $__ } = useLingui();
    const { type: currentErrorType, canGoBack } = state.error;
    const organizationName = state.flowState.organization?.organization_name;
    const ErrorTypeMap = {
        [ErrorType.Default]: $__i18n._({
            id: "error.default",
            message: "Something went wrong. Try again later or contact your admin for help."
        }),
        [ErrorType.EmailMagicLink]: $__i18n._({
            id: "error.eml",
            message: "Something went wrong. Your login link may have expired, been revoked, or been used more than once. Request a new login link to try again, or contact your admin for help."
        }),
        [ErrorType.Organization]: $__i18n._({
            id: "error.organization",
            message: "The organization you are looking for could not be found. If you think this is a mistake, contact your admin."
        }),
        [ErrorType.CannotJoinOrgDueToAuthPolicy]: organizationName ? $__i18n._({
            id: "error.authPolicyWithOrg",
            message: "Unable to join due to {organizationName}'s authentication policy. Please contact your admin for more information.",
            values: {
                organizationName: organizationName
            }
        }) : $__i18n._({
            id: "error.authPolicyNoOrg",
            message: "Unable to join due to the organization's authentication policy. Please contact your admin for more information."
        }),
        [ErrorType.AdBlockerDetected]: $__i18n._({
            id: "error.adBlockerDetected",
            message: "The request was blocked by an Ad Blocker. Please disable your ad blocker, refresh the page, and try again."
        }),
        [ErrorType.OrganizationDiscoveryClaimedDomain]: $__i18n._({
            id: "error.claimedDomain",
            message: "Your email domain is associated with a particular organization, so you are unable to join or create other organizations. Please contact your admin for more information."
        })
    };
    const handleGoBack = useMemo(()=>{
        if (canGoBack) {
            return ()=>dispatch({
                    type: 'transition',
                    screen: AppScreens.Main
                });
        }
        return undefined;
    }, [
        canGoBack,
        dispatch
    ]);
    return /*#__PURE__*/ React__default.createElement(ErrorDisplay, {
        text: ErrorTypeMap[currentErrorType],
        onGoBack: handleGoBack
    });
};

export { ErrorDisplay, ErrorScreen };
//# sourceMappingURL=ErrorScreen.mjs.map
