"use strict";
/* Socket Lib - Built with esbuild */
"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 report_exports = {};
__export(report_exports, {
  generatePerformanceReport: () => generatePerformanceReport,
  printPerformanceSummary: () => printPerformanceSummary
});
module.exports = __toCommonJS(report_exports);
var import_output = require("../debug/output");
var import_math = require("../primordials/math");
var import_object = require("../primordials/object");
var import_internal = require("./_internal");
var import_enabled = require("./enabled");
var import_metrics = require("./metrics");
function generatePerformanceReport() {
  if (!(0, import_enabled.isPerfEnabled)() || import_internal.performanceMetrics.length === 0) {
    return "(no performance data collected - enable with DEBUG=perf)";
  }
  const summary = (0, import_metrics.getPerformanceSummary)();
  const operations = (0, import_object.ObjectKeys)(summary).sort();
  let report = "\n\u2554\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2557\n";
  report += "\u2551         Performance Report                    \u2551\n";
  report += "\u255A\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255D\n\n";
  for (const operation of operations) {
    const stats = summary[operation];
    report += `${operation}:
`;
    report += `  Calls: ${stats.count}
`;
    report += `  Avg:   ${stats.avg}ms
`;
    report += `  Min:   ${stats.min}ms
`;
    report += `  Max:   ${stats.max}ms
`;
    report += `  Total: ${stats.total}ms

`;
  }
  const totalDuration = (0, import_object.ObjectValues)(summary).reduce(
    (sum, s) => sum + s.total,
    0
  );
  report += `Total measured time: ${(0, import_math.MathRound)(totalDuration * 100) / 100}ms
`;
  return report;
}
function printPerformanceSummary() {
  if (!(0, import_enabled.isPerfEnabled)() || import_internal.performanceMetrics.length === 0) {
    return;
  }
  const summary = (0, import_metrics.getPerformanceSummary)();
  const operations = (0, import_object.ObjectKeys)(summary).sort();
  (0, import_output.debugLog)("[perf]\n=== Performance Summary ===");
  for (const operation of operations) {
    const stats = summary[operation];
    (0, import_output.debugLog)(
      `[perf] ${operation}: ${stats.count} calls, avg ${stats.avg}ms (min ${stats.min}ms, max ${stats.max}ms, total ${stats.total}ms)`
    );
  }
  (0, import_output.debugLog)("[perf] =========================\n");
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  generatePerformanceReport,
  printPerformanceSummary
});
