import { EUserEventNames } from "./logger-constants.mjs";
import { getLogPrefix, LogContext, LogLevelType } from "./logger-utils.mjs";
let currentLogLevel = LogLevelType.LOG_LEVEL_DEBUG;
const logger = {
  debug(...args) {
    if (currentLogLevel <= LogLevelType.LOG_LEVEL_DEBUG) {
      console.debug(`${getLogPrefix(LogContext.RENDER)}`, ...args);
    }
  },
  log(...args) {
    if (currentLogLevel <= LogLevelType.LOG_LEVEL_LOG) {
      console.log(`${getLogPrefix(LogContext.RENDER)}`, ...args);
    }
  },
  info(...args) {
    if (currentLogLevel <= LogLevelType.LOG_LEVEL_INFO) {
      console.info(`${getLogPrefix(LogContext.RENDER)}`, ...args);
    }
  },
  warn(...args) {
    if (currentLogLevel <= LogLevelType.LOG_LEVEL_WARN) {
      console.warn(`${getLogPrefix(LogContext.RENDER)}`, ...args);
    }
  },
  error(...args) {
    if (currentLogLevel <= LogLevelType.LOG_LEVEL_ERROR) {
      console.error(`${getLogPrefix(LogContext.RENDER)}`, ...args);
    }
  },
  setLevel(newLevel) {
    var _a;
    if (newLevel >= LogLevelType.LOG_LEVEL_DEBUG && newLevel <= LogLevelType.LOG_LEVEL_NON_LOGGING) {
      console.log(
        `${getLogPrefix(
          LogContext.RENDER
        )} set log level from ${currentLogLevel} to ${newLevel}`
      );
      currentLogLevel = newLevel;
      if ((_a = window.electron) == null ? void 0 : _a.ipcRenderer) {
        window.electron.ipcRenderer.send(
          EUserEventNames.ON_CHANGE_LOG_LEVEL,
          newLevel
        );
      }
    } else {
      console.error(
        `${getLogPrefix(
          LogContext.RENDER
        )} logger.setLevel() invalid params:${newLevel}`
      );
    }
  },
  getLevel() {
    return currentLogLevel;
  }
};
export {
  logger as default
};
