/**
 * Logger utility
 */

type LogLevel = 'debug' | 'info' | 'warn' | 'error';

interface Logger {
  debug(...args: any[]): void;
  info(...args: any[]): void;
  warn(...args: any[]): void;
  error(...args: any[]): void;
  log(...args: any[]): void;
  namespace(name: string): Logger;
}

const createLogger = (prefix: string = ''): Logger => {
  const log = (level: LogLevel, ...args: any[]) => {
    const timestamp = new Date().toISOString();
    const prefixStr = prefix ? `[${prefix}]` : '';
    console[level](`[${timestamp}]${prefixStr}`, ...args);
  };

  return {
    debug: (...args: any[]) => log('debug', ...args),
    info: (...args: any[]) => log('info', ...args),
    warn: (...args: any[]) => log('warn', ...args),
    error: (...args: any[]) => log('error', ...args),
    log: (...args: any[]) => log('info', ...args),
    namespace: (name: string) => createLogger(prefix ? `${prefix}:${name}` : name),
  };
};

export const logger = createLogger('pixel');
