"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var base_logger_exports = {};
__export(base_logger_exports, {
  BaseLogger: () => BaseLogger
});
module.exports = __toCommonJS(base_logger_exports);
var import_boxen = __toESM(require("boxen"));
var import_chalk = __toESM(require("chalk"));
var import_lodash = __toESM(require("lodash"));
var import_util = __toESM(require("util"));
var utils = __toESM(require("../utils"));
const STDOUT_CHUNK_SIZE = 100;
const DEFAULT_OPTIONS = {
  verbose: false,
  json: false,
  outStream: process.stdout,
  errStream: process.stderr
};
const NO_COLOR = (str) => str;
const PINK = [255, 100, 255];
const ORANGE = [255, 165, 0];
const PURPLE = [128, 0, 128];
const BG_COLORS = {
  blue: import_chalk.default.bgBlueBright,
  green: import_chalk.default.bgGreenBright,
  yellow: import_chalk.default.bgYellowBright,
  red: import_chalk.default.bgRedBright,
  white: import_chalk.default.bgWhite,
  pink: (str) => import_chalk.default.bgRgb(...PINK)(str),
  orange: (str) => import_chalk.default.bgRgb(...ORANGE)(str),
  purple: (str) => import_chalk.default.bgRgb(...PURPLE)(str)
};
const FG_COLORS = {
  blue: import_chalk.default.blueBright,
  green: import_chalk.default.green,
  yellow: import_chalk.default.yellowBright,
  red: import_chalk.default.red,
  white: import_chalk.default.white,
  pink: (str) => import_chalk.default.rgb(...PINK)(str),
  orange: (str) => import_chalk.default.rgb(...ORANGE)(str),
  purple: (str) => import_chalk.default.rgb(...PURPLE)(str)
};
const checkmark = {
  default: "\u2713",
  windows: "\u221A",
  mac: "\u2714"
};
const cross = {
  default: "\xD7",
  mac: "\u2716"
};
const danger = { default: "\u26A0" };
const circle = { default: "\u25CB" };
const disc = { default: "\u25CF" };
const space = { default: " " };
const renderers = {
  "\u2713": checkmark,
  "\xD7": cross,
  "\u26A0": danger,
  "\u25CB": circle,
  "\u25CF": disc,
  " ": space
};
const BOX_OPTIONS = {
  padding: 1,
  margin: 1,
  borderStyle: "round",
  borderColor: "yellow"
};
class BaseLogger {
  opts;
  constructor(opts = {}) {
    this.opts = { ...DEFAULT_OPTIONS, ...opts };
  }
  log(message, props = {}) {
    if (this.opts.json && !props.stderr) {
      return;
    }
    const prefix = this._resolvePrefix(props.prefix);
    this.print(message, { ...props, prefix });
  }
  json(data, opts = { depth: Infinity }) {
    if (this.opts.json) {
      this.print(JSON.stringify(data, void 0, 2));
      return;
    }
    const { depth } = opts;
    const msg = import_util.default.inspect(data, { colors: true, depth });
    this.log(msg);
  }
  debug(message) {
    if (!this.opts.verbose) {
      return;
    }
    this.log(import_chalk.default.grey(message), { prefix: { symbol: "\u25CF", fg: "blue" } });
  }
  started(message) {
    this.log(message, { prefix: { symbol: "\u25CB", fg: "purple" } });
  }
  success(message) {
    this.log(message, { prefix: { symbol: "\u2713", fg: "green" } });
  }
  warn(message) {
    this.log(message, { prefix: { symbol: "\u26A0", fg: "yellow" } });
  }
  error(message) {
    this.log(message, { prefix: { symbol: "\xD7", fg: "red" }, stderr: true });
  }
  box(message) {
    const box = (0, import_boxen.default)(message, BOX_OPTIONS);
    this.log(box);
  }
  _resolvePrefix(prefix) {
    if (!prefix) {
      return;
    }
    if (import_lodash.default.isString(prefix)) {
      return prefix;
    }
    const { symbol, fg, bg, indent } = prefix;
    const renderedSymbol = this._renderSymbol(symbol);
    const fgcolor = fg ? FG_COLORS[fg] : NO_COLOR;
    const bgcolor = bg ? BG_COLORS[bg] : NO_COLOR;
    const indentStr = indent ? " ".repeat(indent) : "";
    const symbolStr = fgcolor(bgcolor(renderedSymbol));
    return `${indentStr}${symbolStr}`;
  }
  _renderSymbol(symbol) {
    const renderer = renderers[symbol];
    if (process.platform === "win32") {
      return renderer.windows || renderer.default;
    } else if (process.platform === "darwin") {
      return renderer.mac || renderer.default;
    } else {
      return renderer.default;
    }
  }
  render(message, streamType = "out") {
    const stream = streamType === "err" ? this.opts.errStream : this.opts.outStream;
    for (const chunk of utils.string.chunkString(message, STDOUT_CHUNK_SIZE)) {
      stream.write(chunk);
    }
  }
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  BaseLogger
});
//# sourceMappingURL=base-logger.js.map
