"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 nodejs_reporter_exports = {};
__export(nodejs_reporter_exports, {
  NodejsReporter: () => NodejsReporter
});
module.exports = __toCommonJS(nodejs_reporter_exports);
var import_js_tools = require("@nacho-iot/js-tools");
var import_failure_reporter = require("./failure-reporter.js");
/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
class NodejsReporter {
  constructor(progress) {
    this.progress = progress;
  }
  progress;
  #run = "";
  #suite = Array();
  #test;
  #step;
  #stats;
  #failures = Array();
  #lastTitle;
  beginRun(name, stats, supportsSuites = true) {
    this.#run = name;
    this.#suite = [];
    this.#failures = [];
    if (!supportsSuites) {
      this.progress.update(this.#summarize(stats));
    }
  }
  beginSuite(name, _stats, _file) {
    this.#suite = name;
  }
  beginTest(name, stats) {
    this.#test = name;
    this.#stats = stats;
    this.#step = void 0;
    const title = process.stdout.isTTY ? this.#formatName(this.#suite, name) : this.#suite[0];
    this.#updateTitle(title);
  }
  beginStep(name) {
    this.#step = name;
    if (process.stdout.isTTY && this.#test) {
      const title = this.#formatName(this.#suite, this.#test, name);
      this.#updateTitle(title);
    }
  }
  #updateTitle(title) {
    if (title === this.#lastTitle) {
      return;
    }
    this.#lastTitle = title;
    this.progress.update(this.#summarize(this.#stats), title);
  }
  passTest(_name) {
  }
  failTest(name, detail) {
    this.#failures.push({
      suite: this.#suite,
      test: name,
      step: this.#step,
      detail
    });
  }
  endRun(stats) {
    if (this.#failures.length) {
      this.progress.failure(this.#summarize(stats));
      this.#dumpFailures();
    } else if (stats && !stats.complete) {
      this.progress.failure("No tests found");
    } else {
      this.progress.success(this.#summarize(stats));
    }
  }
  #summarize(stats) {
    let statStr;
    if (stats) {
      const complete = import_js_tools.ansi.dim(`${stats.complete}/${stats.total}`);
      const failures = stats.failures ? import_js_tools.ansi.bright.red(` ${stats.failures.toString()} failed`) : "";
      statStr = ` ${complete}${failures}`;
    } else {
      statStr = "";
    }
    return `${import_js_tools.ansi.bold(this.#run)}${statStr}`;
  }
  #dumpFailures() {
    import_js_tools.std.out("\n");
    for (let i = 0; i < this.#failures.length; i++) {
      const failure = this.#failures[i];
      const index = `Failure ${import_js_tools.ansi.bold((i + 1).toString())} of ${this.#failures.length}: `;
      const title = `${index}${this.#formatName(failure.suite, failure.test, failure.step)}`;
      import_failure_reporter.FailureReporter.report(import_js_tools.std.out, failure.detail, title);
    }
  }
  #formatName(suite, test, step) {
    const breadcrumb = [...suite, test];
    if (step) {
      breadcrumb.push(step);
    }
    breadcrumb[breadcrumb.length - 1] = import_js_tools.ansi.bold(breadcrumb[breadcrumb.length - 1]).toString();
    return breadcrumb.join(" \u27A1 ");
  }
}
//# sourceMappingURL=nodejs-reporter.js.map
