import { jsxs as s, jsx as e } from "react/jsx-runtime";
import { useState as l, useRef as R, useEffect as C, useCallback as re, Suspense as W, lazy as q } from "react";
import { useTranslateProvider as de } from "@/common/languageTranslator/TranslationContext";
import { api as J } from "@/common/interceptors/AxiosInterceptor";
import { getNotifications as U, getAllRoleList as ue } from "@/common/services/GlobalApis";
import me from "@/common/syncWithServer/SyncWithServerDialog";
import { showToast as T } from "@/common/toaster/toaster";
import fe from "@/views/custom-components/CustomConfirmationModal";
import { debounce as pe, Card as he, Typography as D, Box as I, FormControlLabel as Q, Checkbox as G, TextField as ge, Button as ye } from "@mui/material";
import { Grid as S } from "@mui/system";
import N from "prop-types";
import { useSelector as K } from "react-redux";
import { getUseSkeleton as X } from "@/store/reducers/SkeletonReducer";
import be from "@/hooks/useTrackEvent";
import xe from "@/views/custom-components/CustomizedTable/CustomizedTableV2";
import { faPen as Ne, faBars as ve } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon as H } from "@fortawesome/react-fontawesome";
const we = ({ id: n, state: c }) => J.put(
  `notificationtype/${n}?is_active=${c === "INACTIVE" ? "true" : "false"}`
), De = (n) => J.post("notificationtype", n), Y = ({ children: n, isLoading: c }) => !K(X) || !c ? n : /* @__PURE__ */ s("div", { className: "flex flex-col gap-2", children: [
  /* @__PURE__ */ s("div", { className: "flex space-between justify-between m-[0px]", children: [
    /* @__PURE__ */ e("div", { className: "bg-gray-300 animate-pulse rounded-sm w-[130px] h-[40px]" }),
    /* @__PURE__ */ s("div", { className: "flex", children: [
      /* @__PURE__ */ e("div", { className: "bg-gray-300 animate-pulse rounded-sm w-[150px] h-[40px] mx-[5px]" }),
      /* @__PURE__ */ e("div", { className: "bg-gray-300 animate-pulse rounded-sm w-[100px] h-[40px]" })
    ] })
  ] }),
  /* @__PURE__ */ e("div", { className: "bg-gray-300 animate-pulse rounded-sm w-full h-100" })
] });
Y.propTypes = {
  children: N.any,
  isLoading: N.any
};
const Ce = ({ children: n, isLoading: c }) => !K(X) || !c ? n : /* @__PURE__ */ s("div", { className: "flex flex-col w-full md:w-[650px] bg-white ", children: [
  /* @__PURE__ */ e("div", { className: "px-2 py-2 flex  items-center  ", children: /* @__PURE__ */ e("div", { className: "bg-gray-300 animate-pulse rounded-sm w-60 h-10" }) }),
  /* @__PURE__ */ e("hr", {}),
  /* @__PURE__ */ s("div", { className: "flex flex-col w-full space-y-2 p-2", children: [
    /* @__PURE__ */ s("div", { className: "flex flex-col space-y-2", children: [
      /* @__PURE__ */ e("button", { className: "bg-gray-300 animate-pulse rounded-sm w-40 h-5  mr-[100px]" }),
      /* @__PURE__ */ e("button", { className: "bg-gray-300 animate-pulse rounded-sm w-full h-10 " })
    ] }),
    /* @__PURE__ */ s("div", { className: "flex flex-col space-y-2 ", children: [
      /* @__PURE__ */ e("button", { className: "bg-gray-300 animate-pulse rounded-sm w-40 h-5  mr-[100px]" }),
      /* @__PURE__ */ e("button", { className: "bg-gray-300 animate-pulse rounded-sm w-full h-10 " })
    ] }),
    /* @__PURE__ */ s("div", { className: "flex flex-col space-y-2 ", children: [
      /* @__PURE__ */ e("button", { className: "bg-gray-300 animate-pulse rounded-sm w-40 h-5  mr-[100px]" }),
      /* @__PURE__ */ e("button", { className: "bg-gray-300 animate-pulse rounded-sm w-full h-10 " })
    ] }),
    /* @__PURE__ */ s("div", { className: "flex flex-col space-y-2 ", children: [
      /* @__PURE__ */ e("button", { className: "bg-gray-300 animate-pulse rounded-sm w-40 h-5  mr-[100px]" }),
      /* @__PURE__ */ e("button", { className: "bg-gray-300 animate-pulse rounded-sm w-full h-10 " })
    ] }),
    /* @__PURE__ */ s("div", { className: "flex flex-col space-y-2 ", children: [
      /* @__PURE__ */ e("button", { className: "bg-gray-300 animate-pulse rounded-sm w-40 h-5 mr-[100px]" }),
      /* @__PURE__ */ e("button", { className: "bg-gray-300 animate-pulse rounded-sm w-full h-10 " })
    ] })
  ] }),
  /* @__PURE__ */ e("hr", {}),
  /* @__PURE__ */ s("div", { className: "px-2 py-2 w-full flex space-x-3 items-center justify-end ", children: [
    /* @__PURE__ */ e("div", { className: "bg-gray-300 animate-pulse rounded-sm w-20 h-10" }),
    /* @__PURE__ */ e("div", { className: "bg-gray-300 animate-pulse rounded-sm w-20 h-10" })
  ] })
] });
Ce.propTypes = {
  children: N.any,
  isLoading: N.any
};
const Te = q(() => import("./ManageNotification-DMN2szWy.js")), Ie = q(() => import("./NotificationFlywayQuery-BY8Zzml_.js"));
function Se() {
  const n = be(), [c, b] = l(""), [v, k] = l([]), [A, p] = l([]), [h, r] = l(""), [o, x] = l({}), [w, Z] = l([]), { translate: m } = de(), [E, M] = l(null), [O, f] = l(!1), ee = [
    {
      field: "notificationName",
      label: "Name",
      sortable: !0,
      sortOrder: "asc",
      align: "left"
    },
    {
      field: "code",
      label: "Code",
      sortable: !0,
      sortOrder: "asc",
      align: "left"
    },
    {
      field: "notificationType",
      label: "Type",
      align: "left",
      render: (a) => /* @__PURE__ */ e(D, { mt: 0.5, children: a.notificationType === "WEB" ? "WEB" : "MOBILE" })
    },
    {
      field: "state",
      label: "State",
      sortable: !0,
      sortOrder: "asc",
      align: "left"
    },
    { field: "Actions", label: "Actions", align: "left" }
  ], [te, ae] = l(ee), [g, ie] = l(!0), [y, se] = l(!0), L = R(g), B = R(y);
  C(() => {
    L.current = g;
  }, [g]), C(() => {
    B.current = y;
  }, [y]);
  const oe = async () => {
    try {
      f((t) => !t), await we({ id: o.id, state: o.state }), r("");
      const { data: a } = await U();
      k(a), p(a), T({
        type: "success",
        message: `State succesfully changed from  ${(o == null ? void 0 : o.state) === "INACTIVE" ? "inactive" : "active"} to ${(o == null ? void 0 : o.state) === "INACTIVE" ? "active" : "inactive"}`
      }), f((t) => !t);
    } catch (a) {
      T({
        type: "error",
        message: `Error ${a}`
      }), f((t) => !t);
    }
  }, ne = (a) => [
    {
      label: "",
      icon: /* @__PURE__ */ e(
        H,
        {
          icon: Ne,
          "data-testid": "notificationlist-button-edit"
        }
      ),
      onClick: (t) => {
        r(1), x(t);
      }
    },
    {
      label: "",
      icon: /* @__PURE__ */ e(
        H,
        {
          icon: ve,
          "data-testid": "notificationlist-button-menu"
        }
      ),
      menuItems: [
        {
          label: m(
            a.state === "ACTIVE" ? "Mark as Inactive" : "Mark as Active"
          ),
          onClick: (t) => {
            x(t), r(2);
          }
        },
        {
          label: m("Sync With Server"),
          onClick: (t) => {
            if (!t.uuid) {
              T({
                type: "info",
                message: "No configuration found. Please open the respective feature item and save it."
              });
              return;
            }
            r(4), M(t == null ? void 0 : t.uuid), x(t);
          }
        },
        {
          label: m("Show Flyway Query"),
          onClick: (t) => {
            r(3), x(t);
          }
        }
      ]
    }
  ], _ = re(
    pe((a) => {
      const t = v.filter(
        (i) => {
          var d;
          return ((d = i.notificationName) == null ? void 0 : d.toLowerCase().includes(a)) && i.state === (L.current ? "ACTIVE" : "INACTIVE") && i.notificationType === (B.current ? "MO" : "WEB");
        }
      );
      n("search_tracking", {
        searchTerm: a,
        results_count: t.length,
        search_type: "Page Search"
      }), p(t);
    }, 500),
    [v, n]
  ), le = (a) => {
    const t = a.target.value.toLowerCase();
    b(t), _(t);
  }, ce = (a) => {
    const t = a.sortOrder === "asc" ? "desc" : "asc";
    ae(
      (d) => d.map((u) => u.field === a.field ? { ...u, sortOrder: t } : u)
    );
    const i = [...A].sort((d, u) => {
      var j, z;
      const P = (j = d[a.field]) == null ? void 0 : j.toString().toLowerCase(), $ = (z = u[a.field]) == null ? void 0 : z.toString().toLowerCase();
      return P < $ ? t === "asc" ? -1 : 1 : P > $ ? t === "asc" ? 1 : -1 : 0;
    });
    p(i);
  }, V = async () => {
    try {
      f((i) => !i);
      const { data: a } = await U();
      k(a);
      const t = a.filter((i) => i.notificationType === "MO" && i.state === "ACTIVE");
      if (p(t), !w.length) {
        const { data: i } = await ue();
        Z(i);
      }
      f((i) => !i), b("");
    } catch (a) {
      console.error("error", a), f((t) => !t);
    }
  };
  C(() => {
    V();
  }, []);
  const F = (a, t) => {
    const i = t === "status" ? a : g, d = t === "notificationType" ? a : y;
    ie(i), se(d), c ? _(c) : p(
      v.filter(
        (u) => u.state === (i ? "ACTIVE" : "INACTIVE") && u.notificationType === (d ? "MO" : "WEB")
      )
    );
  };
  return /* @__PURE__ */ s(
    he,
    {
      variant: "elevation",
      container: !0,
      className: "mt-6 p-3 flex flex-col space-y-3 shadow-xl",
      children: [
        /* @__PURE__ */ e(W, { children: /* @__PURE__ */ e(
          Te,
          {
            open: h === 1 || h === 5,
            handleClose: () => r(""),
            data: h === 1 ? o : null,
            roleData: w,
            setNotifications: V,
            "data-testid": "notification-list-managenotification-dialog"
          }
        ) }),
        /* @__PURE__ */ e(W, { children: /* @__PURE__ */ e(
          Ie,
          {
            open: h === 3,
            handleClose: () => r(""),
            data: o,
            roleData: w
          }
        ) }),
        /* @__PURE__ */ e(
          fe,
          {
            title: "CONFIRM ACTION",
            open: h === 2,
            description: `Are you sure you want to change the state ${(o == null ? void 0 : o.state) === "INACTIVE" ? "inactive" : "active"} to ${(o == null ? void 0 : o.state) === "INACTIVE" ? "active" : "inactive"}`,
            handleClick: oe,
            handleClose: () => r(""),
            dataTestId: "notification-list-customconfirmationmodal-dialog"
          }
        ),
        /* @__PURE__ */ e(
          me,
          {
            isOpen: !!E,
            handleClose: () => M(() => null),
            featureUUID: E,
            dataTestId: "notification-list-syncwithserverdialog-dialog"
          }
        ),
        /* @__PURE__ */ s(Y, { isLoading: O, children: [
          /* @__PURE__ */ s(S, { container: !0, className: "flex justify-between", children: [
            /* @__PURE__ */ e(S, { children: /* @__PURE__ */ e(
              D,
              {
                variant: "body2",
                className: "font-bold font-sans text-lg text-customBlue uppercase",
                "data-testid": "notification-list-typography-title",
                children: m("Notification Configuration")
              }
            ) }),
            /* @__PURE__ */ s(I, { className: "flex flex-col sm:flex-row sm:items-center gap-3 w-full sm:w-auto", children: [
              /* @__PURE__ */ s(I, { className: "flex items-center gap-3", children: [
                /* @__PURE__ */ e(
                  Q,
                  {
                    control: /* @__PURE__ */ e(
                      G,
                      {
                        checked: g,
                        onChange: (a) => F(a.target.checked, "status"),
                        "data-testid": "notifications-checkbox-include-active"
                      }
                    ),
                    label: m("Active"),
                    slotProps: {
                      typography: {
                        className: "custom-label"
                      }
                    }
                  }
                ),
                /* @__PURE__ */ e(
                  Q,
                  {
                    control: /* @__PURE__ */ e(
                      G,
                      {
                        checked: y,
                        onChange: (a) => F(a.target.checked, "notificationType"),
                        "data-testid": "notifications-checkbox-include-mobile"
                      }
                    ),
                    label: m("Mobile"),
                    slotProps: {
                      typography: {
                        className: "custom-label"
                      }
                    }
                  }
                )
              ] }),
              /* @__PURE__ */ s(I, { className: "flex items-center gap-3 w-full sm:w-auto", children: [
                /* @__PURE__ */ e(
                  ge,
                  {
                    id: "searchQuery",
                    placeholder: "Search Text",
                    size: "small",
                    onChange: le,
                    className: "m-0 p-0 bg-white",
                    value: c,
                    "data-testid": "notification-list-textfield-search",
                    sx: {
                      "& .MuiInputBase-root": {
                        height: "2.4em",
                        width: { xs: "100%", sm: "190px" }
                      },
                      flex: { xs: 1, sm: 1 }
                    }
                  }
                ),
                /* @__PURE__ */ e(
                  ye,
                  {
                    size: "small",
                    variant: "contained",
                    onClick: () => {
                      n("button_click", {
                        button_name: "notification-list-add-button",
                        button_type: "navigate",
                        button_id: "notification-list-button-add"
                      }), r(5);
                    },
                    "data-testid": "notification-list-button-add",
                    sx: { whiteSpace: "nowrap" },
                    children: m("Add")
                  }
                )
              ] })
            ] })
          ] }),
          /* @__PURE__ */ e(S, { size: { xs: 12 }, children: /* @__PURE__ */ e(
            xe,
            {
              columns: te,
              actions: ne,
              tableData: A,
              paginationConfig: {
                pagination: !1
              },
              styleConfig: {
                tableStyle: {
                  maxHeight: 40
                }
              },
              handleSort: ce,
              isLoading: O,
              dataTestId: "notification-list-customizedtable"
            }
          ) })
        ] })
      ]
    }
  );
}
const Qe = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
  __proto__: null,
  default: Se
}, Symbol.toStringTag, { value: "Module" }));
export {
  Ce as M,
  Qe as N,
  De as P
};
//# sourceMappingURL=NotificationList-BqibwMaM.js.map
