/**
 *  LogUtility is a wrapper class for console.log/warn/error with vega branding prefix
 */
export class LogUtility {
  /**
   * `setVegaLogLevel` sets the log level for the Vega logger
   *
   * @param {LogLevelType} level - The log level to set.
   */
  static setVegaLogLevel(level) {
    this.logLevel = level;
  }
  /**
   * Prints a log message to the console
   *
   * @param {unknown[]} message - The message to log.
   */
  static log(...message) {
    if (this.shouldLog('log')) {
      console.log(`%c${this.LOG_PREFIX_STR}`, this.LOG_PREFIX_STYLE, ...message);
    }
  }
  /**
   * Prints a warning message to the console
   *
   * @param {unknown[]} message - The message to log.
   */
  static warn(...message) {
    if (this.shouldLog('warn')) {
      console.warn(`%c${this.LOG_PREFIX_STR}`, this.LOG_PREFIX_STYLE, ...message);
    }
  }
  /**
   * Prints an error message to the console
   *
   * @param {unknown[]} message - The message to be logged.
   */
  static error(...message) {
    if (this.shouldLog('error')) {
      console.error(`%c${this.LOG_PREFIX_STR}`, this.LOG_PREFIX_STYLE, ...message);
    }
  }
  /**
   * If the current log level is less than or equal to the expected log level, then log
   *
   * @param {LogLevelType} level - LogLevelType - The log level of the message.
   * @returns {boolean} A boolean value.
   */
  static shouldLog(level) {
    const current = this.LOG_LEVELS.findIndex((item) => item === level);
    const expect = this.LOG_LEVELS.findIndex((item) => item === this.logLevel);
    return current <= expect;
  }
}
LogUtility.logLevel = 'error';
LogUtility.LOG_PREFIX_STR = '[Vega]';
LogUtility.LOG_PREFIX_STYLE = 'font-weight: bold';
LogUtility.LOG_LEVELS = ['off', 'error', 'warn', 'log'];
/**
 * > Sets the log level for the Vega library
 *
 * @param {LogLevelType} level - The log level to set.
 * @returns {void} -
 */
export function setVegaLogLevel(level) {
  LogUtility.setVegaLogLevel(level);
}
