import React__default from 'react';
import ButtonColumn from '../../../components/molecules/ButtonColumn.mjs';
import LastUsed from '../../../components/molecules/LastUsed.mjs';
import { GoogleOneTap } from '../../components/GoogleOneTap.mjs';
import { OAuthButton } from '../../components/OAuthButton.mjs';
import { useConfig } from '../../GlobalContextProvider.mjs';
import { useLastUsedOAuth } from './useLastUsedOAuth.mjs';
import { arrayUtils } from '../../../../../../core/src/utils/arrayUtils.mjs';

const OAuthButtons = ()=>{
    const config = useConfig();
    const [lastUsedOAuth, setLastUsedOAuth] = useLastUsedOAuth();
    if (!config.oauthOptions) return /*#__PURE__*/ React__default.createElement(React__default.Fragment, null);
    const { providers, loginRedirectURL, signupRedirectURL } = config.oauthOptions;
    const [reorderedProviders, foundLastUsed] = arrayUtils.moveToFront(providers, (provider)=>provider.type === lastUsedOAuth);
    return /*#__PURE__*/ React__default.createElement(ButtonColumn, null, reorderedProviders.map((provider, index)=>{
        const providerProps = {
            customScopes: provider.custom_scopes,
            providerParams: provider.provider_params
        };
        if (provider.one_tap) {
            return /*#__PURE__*/ React__default.createElement(GoogleOneTap, {
                position: provider.position,
                key: `oauth-${provider.type}`,
                ...providerProps,
                cancelOnTapOutside: provider.cancel_on_tap_outside
            });
        }
        const button = /*#__PURE__*/ React__default.createElement(OAuthButton, {
            key: `oauth-${provider.type}`,
            providerType: provider.type,
            loginRedirectUrl: loginRedirectURL,
            signupRedirectUrl: signupRedirectURL,
            onSuccess: ()=>setLastUsedOAuth(provider.type),
            ...providerProps
        });
        return foundLastUsed && index === 0 ? /*#__PURE__*/ React__default.createElement(LastUsed, null, button) : button;
    }));
};

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