import { getSignInAuthProvider, getTokenRequest, getLoginRequest, } from './signInAuthProvider';
import { whitelistedPaths } from './whitelistedPaths.internal';
/**
 * Hook providing auth "actions" such as login/logout
 */
export const useLoginAction = () => loginRedirect;
export const loginRedirect = () => {
    const signInAuthProvider = getSignInAuthProvider();
    void signInAuthProvider.loginRedirect(getLoginRequest());
};
export function useLogoutAction() {
    return () => {
        const signInAuthProvider = getSignInAuthProvider();
        void signInAuthProvider.logoutRedirect({
            account: signInAuthProvider.getActiveAccount(),
        });
    };
}
export async function acquireAccessToken() {
    var _a;
    const signInAuthProvider = getSignInAuthProvider();
    const account = (_a = signInAuthProvider.getActiveAccount()) !== null && _a !== void 0 ? _a : undefined;
    if (account) {
        return signInAuthProvider
            .acquireTokenSilent(Object.assign(Object.assign({}, getTokenRequest()), { account }))
            .then((response) => {
            return response.accessToken;
        })
            .catch(() => {
            const currentPathIsWhitelisted = whitelistedPaths.includes(window.location.pathname);
            if (!currentPathIsWhitelisted) {
                void signInAuthProvider.loginRedirect(getLoginRequest());
            }
        });
    }
}
//# sourceMappingURL=authActions.js.map