import { isDev } from "./env";
/**
 * Analytics stub for @djangocfg/api/auth
 * Provides minimal analytics interface without external dependencies
 *
 * If you need full analytics, install @djangocfg/layouts and use its Analytics module
 */

export enum AnalyticsEvent {
  AUTH_OTP_REQUEST = 'auth_otp_request',
  AUTH_LOGIN_SUCCESS = 'auth_login_success',
  AUTH_OTP_VERIFY_FAIL = 'auth_otp_verify_fail',
  AUTH_SESSION_EXPIRED = 'auth_session_expired',
  AUTH_TOKEN_REFRESH = 'auth_token_refresh',
  AUTH_TOKEN_REFRESH_FAIL = 'auth_token_refresh_fail',
  AUTH_LOGOUT = 'auth_logout',
  AUTH_OAUTH_START = 'auth_oauth_start',
  AUTH_OAUTH_FAIL = 'auth_oauth_fail',
}

export enum AnalyticsCategory {
  AUTH = 'auth',
}

export type AnalyticsEventType = `${AnalyticsEvent}`;
export type AnalyticsCategoryType = `${AnalyticsCategory}`;

interface AnalyticsEventParams {
  category?: AnalyticsCategoryType;
  label?: string;
  value?: number;
  [key: string]: any;
}

/**
 * Minimal analytics implementation
 * Logs to console in development, silent in production
 */
export const Analytics = {
  /**
   * Track an analytics event
   */
  event(eventName: AnalyticsEventType, params?: AnalyticsEventParams) {
    if (isDev) {
      console.log('[Analytics]', eventName, params);
    }

    // You can extend this to send to your analytics service
    // Example: window.gtag?.('event', eventName, params);
  },

  /**
   * Set user ID for tracking
   */
  setUser(userId: string) {
    if (isDev) {
      console.log('[Analytics] Set user:', userId);
    }

    // You can extend this to send to your analytics service
    // Example: window.gtag?.('set', { user_id: userId });
  },
};
