/**
 * Client-side Logger Utility
 *
 * Provides environment-aware logging for browser code.
 * Suppresses debug/info logs in production to keep console clean.
 * Errors always logged for debugging production issues.
 */

const isDevelopment = process.env.NODE_ENV === "development";
const isTest = process.env.NODE_ENV === "test";

/**
 * Client-safe logger that respects environment
 */
export const clientLogger = {
  /**
   * Debug logging - only in development
   */
  debug: (message: string, ...args: unknown[]): void => {
    if (isDevelopment && !isTest) {
      console.debug(`[DEBUG] ${message}`, ...args);
    }
  },

  /**
   * Info logging - only in development
   */
  info: (message: string, ...args: unknown[]): void => {
    if (isDevelopment && !isTest) {
      console.info(`[INFO] ${message}`, ...args);
    }
  },

  /**
   * Warning logging - only in development
   */
  warn: (message: string, ...args: unknown[]): void => {
    if (isDevelopment && !isTest) {
      console.warn(`[WARN] ${message}`, ...args);
    }
  },

  /**
   * Error logging - always logged (important for debugging)
   * In production, could optionally send to error tracking service
   */
  error: (message: string, error?: unknown, ...args: unknown[]): void => {
    if (isTest) return;

    if (error) {
      console.error(`[ERROR] ${message}`, error, ...args);
    } else {
      console.error(`[ERROR] ${message}`, ...args);
    }
  },
};

export default clientLogger;
