import { useLingui } from '../../../../../../node_modules/@lingui/react/dist/index.mjs';
import React__default from 'react';
import Button from '../../components/atoms/Button.mjs';
import { usePresentation, getButtonId } from '../../components/PresentationConfig.mjs';
import { useStytch, useGlobalReducer } from '../GlobalContextProvider.mjs';
import { B2BOAuthProviders } from '../../../../../core/src/public/b2b/ui.mjs';

const providerInfo = {
    [B2BOAuthProviders.Google]: {
        messageDescriptor: {
            id: "oauth.continueWithGoogle",
            message: "Continue with Google"
        }
    },
    [B2BOAuthProviders.Microsoft]: {
        messageDescriptor: {
            id: "oauth.continueWithMicrosoft",
            message: "Continue with Microsoft"
        }
    },
    [B2BOAuthProviders.HubSpot]: {
        messageDescriptor: {
            id: "oauth.continueWithHubSpot",
            message: "Continue with HubSpot"
        }
    },
    [B2BOAuthProviders.Slack]: {
        messageDescriptor: {
            id: "oauth.continueWithSlack",
            message: "Continue with Slack"
        }
    },
    [B2BOAuthProviders.GitHub]: {
        messageDescriptor: {
            id: "oauth.continueWithGitHub",
            message: "Continue with GitHub"
        }
    }
};
const OAuthB2BButton = ({ providerType, loginRedirectUrl, signupRedirectUrl, discoveryRedirectUrl, customScopes, providerParams, onSuccess })=>{
    const { i18n: $__i18n, _: $__ } = useLingui();
    const stytchClient = useStytch();
    const [state] = useGlobalReducer();
    const presentation = usePresentation();
    const iconRegistry = presentation.iconRegistry;
    const id = getButtonId(`oauth-${providerType}`, presentation.options);
    const provider = providerInfo[providerType];
    let label = providerType;
    let icon = null;
    if (provider) {
        const { messageDescriptor } = provider;
        const Icon = iconRegistry[providerType];
        label = $__i18n._(messageDescriptor);
        icon = /*#__PURE__*/ React__default.createElement(Icon, null);
    }
    const onButtonClick = async ()=>{
        const providerClient = stytchClient.oauth[providerType];
        if (state.flowState.organization) {
            await providerClient.start({
                login_redirect_url: loginRedirectUrl,
                signup_redirect_url: signupRedirectUrl,
                custom_scopes: customScopes,
                organization_id: state.flowState.organization.organization_id,
                provider_params: providerParams
            });
        } else {
            await providerClient.discovery.start({
                discovery_redirect_url: discoveryRedirectUrl,
                custom_scopes: customScopes,
                provider_params: providerParams
            });
        }
        onSuccess?.();
    };
    return /*#__PURE__*/ React__default.createElement(Button, {
        onClick: onButtonClick,
        variant: "outline",
        icon: icon,
        id: id
    }, label);
};

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