'use strict';
import { Google, generateState, generateCodeVerifier } from 'arctic';
import { authEnvSettingKeys, authParam, googleApi } from '../../../../fd-toolbox/constants/internal-auth-constants.js';
import { navigate } from '../../../../fd-toolbox/redirect/redirect-functions.js';
import { apiBaseGet } from '../../../../fd-toolbox/api/base-api.js';
import { signUpByOAuth } from './standard-login.js';
import { getLoginUrl } from '../../../../fd-toolbox/routing/login-routers.js';
import { setSessionStorage, getSessionStorage } from '../../../../fd-toolbox/auth/session-storage.js';
import { defaultOAuthProviders, defaultOAuthProvidersNames } from '../../../../fd-toolbox/auth/oauth-provider-types.js';
import { iconNames } from '../../../fd-component-toolbox/icon/Icon.js';
import { buildUrl } from '../../../../fd-toolbox/url/urls.js';
import { getStringEnvSetting } from '../../../../fd-toolbox/infra/env-functions.js';
import { wellKnownUserProps } from '../../../../fd-toolbox/constants/common-user-fields.js';
import { getBearerAccessToken } from './microsoft-login.js';

var __defProp=Object['defineProperty'],__name=(_0x360e7f,_0x11d5e5)=>__defProp(_0x360e7f,'name',{'value':_0x11d5e5,'configurable':!![]});const codeVerifierString='code_verifier';async function onGoogleLogin(){const _0x45301=getStringEnvSetting(authEnvSettingKeys['googleClientId']),_0x414c91=getStringEnvSetting(authEnvSettingKeys['googleClientSecret']);if(!_0x45301||!_0x414c91)return void(0x9d*0x11+0x5*0x32d+-0x25*0xb6);const _0x118702=new Google(_0x45301,_0x414c91,buildUrl(getLoginUrl(),[{'name':authParam,'value':defaultOAuthProviders['google']}])),_0x11dc3e=generateState(),_0x4d7721=generateCodeVerifier();setSessionStorage(codeVerifierString,_0x4d7721);const _0x29d6d6=[wellKnownUserProps['openid'],wellKnownUserProps['profile'],wellKnownUserProps['email']],_0x32d54c=await _0x118702['createAuthorizationURL'](_0x11dc3e,_0x4d7721,{'scopes':_0x29d6d6});return navigate(_0x32d54c['toString']());}__name(onGoogleLogin,'onGoogleLogin');async function googleOAuth(_0x1c1c04,_0x5f06f3){const _0x104268=getStringEnvSetting(authEnvSettingKeys['googleClientId']),_0x56112f=getStringEnvSetting(authEnvSettingKeys['googleClientSecret']);if(!_0x104268||!_0x56112f)return;const _0xae75c8=new Google(_0x104268,_0x56112f,buildUrl(getLoginUrl(),[{'name':authParam,'value':defaultOAuthProviders['google']}])),_0x5aa09b=getSessionStorage(codeVerifierString),_0x5d813c=await _0xae75c8['validateAuthorizationCode'](_0x1c1c04,_0x5aa09b),_0x3ffb34=await apiBaseGet(googleApi,new Headers({'Authorization':getBearerAccessToken(_0x5d813c['accessToken'])}));await signUpByOAuth(_0x5f06f3,_0x3ffb34['sub'],defaultOAuthProviders['google'],_0x3ffb34['email'],_0x3ffb34['given_name'],_0x3ffb34['family_name']);}__name(googleOAuth,'googleOAuth');function getGoogleOAuthConfig(){const _0xe93542={'buttonText':defaultOAuthProvidersNames['google'],'oAuthProvider':defaultOAuthProviders['google'],'onLogin':onGoogleLogin,'handleOAuth':googleOAuth,'iconName':iconNames['googleLogo']};return _0xe93542;}__name(getGoogleOAuthConfig,'getGoogleOAuthConfig');

export { codeVerifierString, getGoogleOAuthConfig, googleOAuth, onGoogleLogin };
