import { jsx as r, jsxs as n } from "@emotion/react/jsx-runtime";
import { useEnvironment as O, useModuleDictionary as T } from "@m4l/core";
import { Typography as f } from "@m4l/base";
import { LoadingErrorRootStyled as C, LoadingErrorStyled as x, LinearProgressIndeterminateStyled as N, LoadingErrorContainerStyled as D, LoadingErrorContentStyled as z, LoadingErrorImageStyled as B, LoadingErrorTextContainerStyled as A, LoadingErrorTitleDescriptionStyled as P, LoadingErrorButtonContainerStyled as $ } from "./slots/LoadingErrorSlots.js";
import { getComponentSlotRoot as k } from "../../utils/getComponentSlotRoot.js";
import { getPropDataTestId as M } from "../../test/getNameDataTestId.js";
import { LOADING_ERROR_KEY_COMPONENT as E } from "./constants.js";
import j from "clsx";
import { dictionary as i } from "./dictionary.js";
import { useComponentSize as w } from "../../hooks/useComponentSize/index.js";
import { useRef as V, useState as W, useEffect as G } from "react";
import { LoadingErrorSlots as K } from "./slots/LoadingErrorEnum.js";
import { Button as Y } from "../extended/mui/Button/Button.js";
const ir = (g) => {
  const { status: L, action: u, title: s, description: a, introMessage: c, errorIcon: d, className: R, dataTestId: S, size: o = "medium" } = g, { host_static_assets: l, environment_assets: m } = O(), { getLabel: t } = T(), { currentSize: h } = w(o), y = {
    size: h
  }, e = V(null), [_, I] = W(!0);
  return G(() => {
    const p = new ResizeObserver((b) => {
      for (const v of b)
        I(v.contentRect.height >= 200);
    });
    return e.current && p.observe(e.current), () => p.disconnect();
  }, []), /* @__PURE__ */ r(
    C,
    {
      ref: e,
      ownerState: y,
      className: j(k(E), R),
      ...M(E, K.root, S),
      children: L !== "error" ? /* @__PURE__ */ r(x, { children: /* @__PURE__ */ r(N, {}) }) : /* @__PURE__ */ r(D, { children: /* @__PURE__ */ n(z, { children: [
        _ && /* @__PURE__ */ r(
          B,
          {
            size: o,
            src: d || `${l}/${m}/frontend/components/loading_error/assets/icons/LoadingError.svg`
          }
        ),
        /* @__PURE__ */ n(A, { children: [
          /* @__PURE__ */ n(P, { children: [
            /* @__PURE__ */ r(f, { size: o, variant: "subtitleDens", skeletonWidth: "100px", children: s || t(i.LABEL_ERROR_TITLE) }),
            /* @__PURE__ */ r(
              f,
              {
                size: o,
                variant: "captionSlim",
                skeletonWidth: "100px",
                color: "text.secondary",
                children: a || t(i.LABEL_ERROR_DESCRIPTION)
              }
            )
          ] }),
          /* @__PURE__ */ r($, { children: /* @__PURE__ */ r(
            Y,
            {
              size: o,
              variant: "contained",
              color: "primary",
              startIcon: `${l}/${m}/frontend/components/loading_error/assets/icons/refresh.svg`,
              onClick: u,
              label: c || t(i.LABEL_ERROR_INTRO),
              "aria-label": "button action"
            }
          ) })
        ] })
      ] }) })
    }
  );
};
export {
  ir as LoadingError
};
