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