import { useState, useEffect } from "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] = useState(() => createInitialError(e));
  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;
};
export { parseStacktrace, useProcessedError };
//# sourceMappingURL=useParsedStacktrace.js.map
