/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
import { ansi, STATUS_ICON_FAILURE } from "@nacho-iot/js-tools";
import { TextDiff } from "./text-diff.js";
const BEGIN_ERROR = `${ansi.red}\u250F\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2505${ansi.not.red}`;
const OUTER_PREFIX = `${ansi.red}\u2503  ${ansi.not.red}`;
const INNER_PREFIX = `${ansi.dim}\u2506  ${ansi.not.dim}`;
const END_ERROR = `${ansi.red}\u2517\u2501\u2505${ansi.not.red}`;
var FailureReporter;
((FailureReporter2) => {
  function report(out, failure, title) {
    out(BEGIN_ERROR, "\n", OUTER_PREFIX, "\n");
    out.state({ linePrefix: OUTER_PREFIX }, () => {
      out(ansi.bold.red(STATUS_ICON_FAILURE), " ", title, "\n");
      dumpDetails(out, failure);
    });
    out(OUTER_PREFIX, "\n", END_ERROR, "\n");
  }
  FailureReporter2.report = report;
})(FailureReporter || (FailureReporter = {}));
function dumpCause(out, failure) {
  out.state({ linePrefix: INNER_PREFIX }, () => {
    dumpDetails(out, failure);
  });
}
function dumpDetails(out, { message, id, actual, expected, stack, cause, errors, secondary, logs, diagnostics }) {
  out("\n", ansi.bright.red(id ? `[${ansi.bold(id)}] ${message}` : message), "\n");
  if (actual !== void 0 && expected !== void 0) {
    out("\n");
    out.state({ linePrefix: "    " }, () => out(TextDiff(actual, expected)));
    out("\n");
  }
  if (stack) {
    out("\n");
    out.state({ linePrefix: "  " }, () => out(stack));
    out("\n");
  }
  if (cause) {
    out("\n", ansi.bold("Caused by:"), "\n");
    dumpCause(out, cause);
  }
  if (errors?.length) {
    let num = 0;
    for (const cause2 of errors) {
      out("\n", ansi.bold(`Cause #${++num}:`), "\n");
      dumpCause(out, cause2);
    }
  }
  if (secondary) {
    out("\n", ansi.bold("Secondary error during disposal:"), "\n");
    dumpCause(out, secondary);
  }
  if (logs) {
    out("\n", logs, "\n");
  }
  if (diagnostics) {
    out("\n", ansi.bold("Process state at timeout:"), diagnostics, "\n");
  }
}
export {
  FailureReporter
};
//# sourceMappingURL=failure-reporter.js.map
