"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
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 __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var format_exports = {};
__export(format_exports, {
  formatStats: () => formatStats
});
module.exports = __toCommonJS(format_exports);
var import_color = require("./color");
var import_formatStats = require("./formatStats");
function formatStats(stats, showWarnings = true) {
  const statsData = stats.toJson({
    preset: "errors-warnings"
  });
  const { errors, warnings } = (0, import_formatStats.formatStatsMessages)(statsData, import_color.color);
  if (errors.length) {
    const errorMsgs = `${errors.join("\n\n")}
`;
    const isTerserError = errorMsgs.includes("from Terser");
    const title = import_color.color.bold(
      import_color.color.red(isTerserError ? `Minify error: ` : `Compile error: `)
    );
    const tip = import_color.color.yellow(
      isTerserError ? `Failed to minify with terser, check for syntax errors.` : "Failed to compile, check the errors for troubleshooting."
    );
    return {
      message: `${title}
${tip}
${errorMsgs}`,
      level: "error"
    };
  }
  if (warnings.length && (showWarnings || process.stdout.isTTY)) {
    const title = import_color.color.bold(import_color.color.yellow(`Compile Warning: 
`));
    return {
      message: `${title}${`${warnings.join("\n\n")}
`}`,
      level: "warning"
    };
  }
  return {};
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  formatStats
});
