import { jsx as e, jsxs as o, Fragment as w } from "react/jsx-runtime";
import { useState as g, useEffect as N } from "react";
import r from "prop-types";
import { Modal as T, Typography as n, IconButton as C, Stack as k, Button as O } from "@mui/material";
import i from "@mui/material/Grid2";
import { execute as S } from "@/common/services/GlobalApis";
import { showToast as _ } from "@/common/toaster/toaster";
import { useTranslateProvider as B } from "@/common/languageTranslator/TranslationContext";
import { FontAwesomeIcon as E } from "@fortawesome/react-fontawesome";
import { faXmark as I } from "@fortawesome/free-solid-svg-icons";
import { o as j } from "./EventsSkeleton-BN7_0IGs-BAnd1Vug.js";
function L({ id: d, title: v, open: f, handleClose: s, dataTestId: x }) {
  const { translate: a } = B(), [t, m] = g(null), [l, p] = g(!1);
  N(() => {
    d && b(d);
  }, [d]);
  const b = async (y) => {
    var u;
    try {
      p(!0);
      const h = await S(
        {
          code: "event_config_retrieve_exceptions_by_config_id",
          parameters: {
            configId: Number(y)
          }
        },
        { showLoader: !1 }
      );
      p(!1);
      const c = (u = h == null ? void 0 : h.data) == null ? void 0 : u.result;
      (c == null ? void 0 : c.length) > 0 ? m(c[0]) : m(null);
    } catch {
      _({ message: "Error in Showing Exception", type: "error" });
    }
  };
  return /* @__PURE__ */ e(
    T,
    {
      open: f,
      onClose: s,
      sx: {
        "& .MuiBackdrop-root": {
          backgroundColor: "rgba(0, 0, 0, 0.1)"
          // Set the modal overlay background color to transparent
        }
      },
      "data-testid": x,
      children: /* @__PURE__ */ o(
        i,
        {
          container: !0,
          className: "absolute top-[5%] left-[11%] w-[80%] bg-white shadow-md  max-h-[80vh] overflow-y-auto",
          "data-testid": "eventsexceptionmodal-grid-container",
          children: [
            /* @__PURE__ */ o(
              i,
              {
                className: "manageeventconfiguration-modal-header p-2.5 px-5 flex  justify-between border-b w-full",
                "data-testid": "eventsexceptionmodal-header",
                children: [
                  /* @__PURE__ */ e(
                    n,
                    {
                      variant: "body1",
                      className: "font-medium text-lg text-customBlue",
                      "data-testid": "eventsexceptionmodal-title",
                      children: v
                    }
                  ),
                  /* @__PURE__ */ e(
                    C,
                    {
                      size: "small",
                      onClick: s,
                      "data-testid": "eventsexceptionmodal-close-button",
                      children: /* @__PURE__ */ e(E, { icon: I })
                    }
                  )
                ]
              }
            ),
            /* @__PURE__ */ e(
              i,
              {
                item: !0,
                className: "border-b border-gray-300 w-full p-2.5",
                "data-testid": "eventsexceptionmodal-content",
                children: /* @__PURE__ */ o(j, { isLoading: l, children: [
                  t && !l && /* @__PURE__ */ o(w, { children: [
                    /* @__PURE__ */ e(
                      n,
                      {
                        variant: "h6",
                        "data-testid": "eventsexceptionmodal-exception-header",
                        className: "text-customBlue",
                        children: /* @__PURE__ */ o("strong", { children: [
                          a("Exception"),
                          ":"
                        ] })
                      }
                    ),
                    /* @__PURE__ */ e(
                      "pre",
                      {
                        className: "whitespace-pre-wrap break-words m-0",
                        "data-testid": "eventsexceptionmodal-exception-string",
                        children: t == null ? void 0 : t.exceptionString
                      }
                    ),
                    (t == null ? void 0 : t.systemTriggerOn) && /* @__PURE__ */ o(
                      n,
                      {
                        variant: "body1",
                        className: "mt-2",
                        "data-testid": "eventsexceptionmodal-triggered-on",
                        children: [
                          /* @__PURE__ */ o("strong", { children: [
                            a("Triggered On"),
                            ":"
                          ] }),
                          " ",
                          new Date(t == null ? void 0 : t.systemTriggerOn).toLocaleString()
                        ]
                      }
                    ),
                    (t == null ? void 0 : t.processedOn) && /* @__PURE__ */ o(
                      n,
                      {
                        variant: "body1",
                        "data-testid": "eventsexceptionmodal-processed-on",
                        children: [
                          /* @__PURE__ */ o("strong", { children: [
                            a("Processed On"),
                            ":"
                          ] }),
                          " ",
                          new Date(t == null ? void 0 : t.processedOn).toLocaleString()
                        ]
                      }
                    )
                  ] }),
                  !t && !l && /* @__PURE__ */ e(
                    n,
                    {
                      variant: "body1",
                      className: "m-1",
                      "data-testid": "eventsexceptionmodal-no-exception",
                      children: a("No Exception Occurred")
                    }
                  )
                ] })
              }
            ),
            /* @__PURE__ */ e(
              i,
              {
                item: !0,
                className: "border-b border-gray-300 pb-[1px] pr-2.5 w-full",
                "data-testid": "eventsexceptionmodal-footer",
                children: /* @__PURE__ */ e(
                  k,
                  {
                    direction: "row",
                    spacing: 2,
                    justifyContent: "flex-end",
                    mt: 1,
                    mb: 1,
                    children: /* @__PURE__ */ e(i, { children: /* @__PURE__ */ e(
                      O,
                      {
                        variant: "contained",
                        color: "secondary",
                        className: "ml-2",
                        onClick: s,
                        "data-testid": "eventsexceptionmodal-close-button-action",
                        children: /* @__PURE__ */ e(n, { variant: "body2", children: a("Close") })
                      }
                    ) })
                  }
                )
              }
            )
          ]
        }
      )
    }
  );
}
L.propTypes = {
  open: r.any,
  handleClose: r.any,
  id: r.any,
  title: r.any,
  dataTestId: r.any
};
export {
  L as default
};
//# sourceMappingURL=EventsExceptionModal-BF6E1Np7-DHT7pQsx.js.map
