import PocketBase from 'pocketbase';

// const domain = "cal.htwk-leipzig.de";
// const baseUri = "https://" + domain;

// For development, we might want to use the local backend
// const backendUrl = import.meta.env.DEV ? 'http://127.0.0.1:8090' : baseUri;
// But since we are running in docker, the frontend might be accessing the backend via a different URL or proxy.
// The existing code uses relative paths for API calls which go through the reverse proxy.
// PocketBase SDK needs a full URL or it defaults to /. 
// If we are serving frontend from the same domain as backend (via proxy), / is fine.
// However, the proxy config shows backend at /api/ and pocketbase at /_/? 
// Let's check reverseproxy.conf

export const pb = new PocketBase("/");

// Note: OAuth2 redirect URL should be configured in Keycloak/OIDC provider as:
// Development: http://localhost/callback
// Production: https://cal.htwk-leipzig.de/callback

export const login = async () => {
    await pb.collection('users').authWithOAuth2({ provider: 'oidc' });
}

export const logout = () => {
    pb.authStore.clear();
}
