// msalConfig.ts
import { PublicClientApplication, LogLevel } from '@azure/msal-browser';

export const msalConfig = {
    auth: {
        clientId: '1225bb0a-37ec-4b82-be22-bb1f4a1e0231',
        authority: 'https://login.microsoftonline.com/9840a2a0-6ae1-4688-b03d-d2ec291be0f9',
        redirectUri: window.location.origin,
    },
    cache: {
        cacheLocation: 'sessionStorage',
        storeAuthStateInCookie: false,
    },
    system: {
        loggerOptions: {
            loggerCallback: (level: LogLevel, message: string, containsPii: boolean) => {
                if (containsPii) return;
                switch (level) {
                    case LogLevel.Error:
                        console.error(message);
                        return;
                    case LogLevel.Info:
                        console.info(message);
                        return;
                    case LogLevel.Verbose:
                        console.debug(message);
                        return;
                    case LogLevel.Warning:
                        console.warn(message);
                        return;
                }
            }
        }
    }
};

export const loginRequest = {
    scopes: ['User.Read']
};

// Créer l'instance (ne pas l'initialiser ici)
export const msalInstance = new PublicClientApplication(msalConfig);

// ❌ SUPPRIMER cette ligne - l'initialisation se fait dans main.tsx
// await msalInstance.initialize();