import { j as t } from "./externalizeComponent-Dc3fViZA.js";
import { useTheme as c, Stack as i, CircularProgress as l, capitalize as g } from "@mui/material";
import { lowerFirst as d } from "lodash-es";
import { useState as u, useEffect as f } from "react";
import { AxiosError as a } from "axios";
function h(e) {
  try {
    return JSON.stringify(e);
  } catch {
    return;
  }
}
function T(e, r) {
  throw new Error(r + ` ${JSON.stringify(e)}`);
}
function x(e) {
  var r, s, o, n;
  return e instanceof a && e.code === "ERR_NETWORK" ? "Failed to connect to the server. Please check your internet connection." : e instanceof a && e.response ? `${(r = e.response) == null ? void 0 : r.status} ${(s = e.response) == null ? void 0 : s.statusText} from ${(o = e.response) == null ? void 0 : o.config.url}: ${JSON.stringify((n = e.response) == null ? void 0 : n.data)}` : e instanceof Error ? e.message : `Unexpected error: ${h(e) || e}`;
}
const k = (e) => {
  const r = e.softTimeout || 3e3, [s, o] = u(!1), n = c();
  return f(() => {
    const m = setTimeout(() => {
      o(!0);
    }, r);
    return () => clearTimeout(m);
  }), /* @__PURE__ */ t.jsx(
    i,
    {
      width: "100%",
      height: "100%",
      alignItems: "center",
      justifyContent: "center",
      sx: { color: n.palette.text.primary },
      children: e.error ? /* @__PURE__ */ t.jsx(
        w,
        {
          loadingMessage: e.message,
          error: e.error
        }
      ) : /* @__PURE__ */ t.jsxs(t.Fragment, { children: [
        /* @__PURE__ */ t.jsx(l, { sx: { marginBottom: "24px" } }),
        !!e.message && /* @__PURE__ */ t.jsx("div", { children: e.message }),
        /* @__PURE__ */ t.jsx(
          i,
          {
            sx: {
              visibility: s ? "visible" : "hidden",
              marginTop: "1rem",
              color: n.palette.text.secondary
            },
            children: "This is taking longer than expected..."
          }
        )
      ] })
    }
  );
}, w = (e) => {
  const r = x(e.error), s = e.error instanceof Error ? e.error.stack : null, o = c();
  return /* @__PURE__ */ t.jsxs(
    i,
    {
      sx: {
        maxHeight: "100%",
        maxWidth: "min(100%, 800px)",
        padding: 2,
        overflow: "auto",
        color: o.palette.error.main,
        "& pre": {
          whiteSpace: "pre-wrap",
          wordBreak: "break-word",
          paddingBottom: "3rem"
        }
      },
      children: [
        (e.loadingMessage ? `Error while ${d(g(e.loadingMessage))} - ` : "") + r,
        /* @__PURE__ */ t.jsx("br", {}),
        s && /* @__PURE__ */ t.jsx("pre", { children: s })
      ]
    }
  );
};
export {
  k as L,
  w as a,
  T as b
};
//# sourceMappingURL=LoadingCover-6gWr11KP.js.map
