"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 __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
));
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const react = require("react");
const parseStacktrace = async (e) => {
  const StackTracey = (await import("stacktracey")).default;
  return (await new StackTracey(e).withSourcesAsync()).items.map((it) => ({
    filename: it.fileShort,
    line: it.line,
    callee: it.callee,
    thirdParty: it.thirdParty,
    sourceCodeLines: it.sourceFile?.lines
  }));
};
const createInitialError = (e) => ({
  error: e,
  cause: e instanceof Error && "cause" in e && e.cause !== void 0 ? createInitialError(e.cause) : void 0
});
const useProcessedError = (e) => {
  const [error, setError] = react.useState(() => createInitialError(e));
  react.useEffect(() => {
    setError(createInitialError(e));
    if (!(e instanceof Error)) {
      return;
    }
    const createErrorWithStackTrace = async (e2) => {
      return {
        error: e2,
        parsedStackStrace: e2 instanceof Error ? await parseStacktrace(e2) : void 0,
        cause: e2 instanceof Error && "cause" in e2 && e2.cause !== void 0 ? await createErrorWithStackTrace(e2.cause) : void 0
      };
    };
    (async () => {
      setError(await createErrorWithStackTrace(e));
    })();
  }, [e]);
  return error;
};
exports.parseStacktrace = parseStacktrace;
exports.useProcessedError = useProcessedError;
//# sourceMappingURL=useParsedStacktrace.cjs.map
