import { jsxs as o, jsx as e, Fragment as _ } from "react/jsx-runtime";
import v from "@/common/services/util/GeneralUtil";
import { Button as G, debounce as H, Box as J, Card as C, Typography as T, TextField as O, TableContainer as Q } from "@mui/material";
import { Grid as c } from "@mui/system";
import { useTranslateProvider as U } from "@/common/languageTranslator/TranslationContext";
import { getNotifications as Y, getRoleList as q } from "@/common/services/GlobalApis.js";
import { getAssignedFeatures as K } from "@/utils/feature.js";
import { useState as s, useCallback as V, useEffect as X, Suspense as Z, lazy as $ } from "react";
import ee from "@/hooks/useTrackEvent";
import te from "@/views/custom-components/CustomizedTable/CustomizedTableV2";
import { useSelector as ae } from "react-redux";
import { getUseSkeleton as ie } from "@/store/reducers/SkeletonReducer";
const se = () => ae(ie) ? /* @__PURE__ */ o("div", { className: "flex flex-col gap-2 mt-6 w-full", children: [
  /* @__PURE__ */ o("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__ */ o("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" })
] }) : null, ne = $(() => import("./AddRoleDrawer-SvntLdRu.js"));
function we() {
  const [p, S] = s(""), [g, k] = s({}), [D, B] = s([]), [d, z] = s({}), { translate: h } = U(), x = ee(), [L, w] = s([]), [m, f] = s(!1), [n, j] = s({}), [b, y] = s(!1), A = [
    { field: "notificationName", label: "Name", align: "left" },
    { field: "roles", label: "Action By", align: "left" },
    {
      field: "Actions",
      label: "Actions",
      align: "left"
    }
  ], R = (t) => {
    y(!0), B(t);
  }, W = [
    (!v.isTecho || (n == null ? void 0 : n["update.manage.widgetManagement"])) && {
      label: "",
      icon: /* @__PURE__ */ e(
        G,
        {
          size: "small",
          variant: "contained",
          className: "text-[10px]",
          "data-testid": "widgetlist-button-assign",
          children: h("Assign")
        }
      ),
      onClick: R
    }
  ].filter(Boolean), E = V(
    H((t) => {
      const i = g.filter(
        (u) => {
          var l;
          return (l = u.notificationName) == null ? void 0 : l.toLowerCase().includes(t);
        }
      );
      x("search_tracking", {
        searchTerm: t,
        results_count: i.length,
        search_type: "Page Search"
      }), w(i);
    }, 500),
    [g, x]
  ), F = (t) => {
    const i = t.target.value.toLowerCase();
    S(i), E(i);
  }, N = async () => {
    try {
      f((a) => !a);
      const { data: t } = await K("techo.manage.manage-widgets");
      t && j(JSON.parse(t));
      let i = d;
      const { data: u } = await Y();
      if (!d.length) {
        const { data: a } = await q();
        i = a, z(a);
      }
      const l = u.map((a) => {
        const I = a == null ? void 0 : a.roles.map((r) => i.find((P) => P.id === r)).filter((r) => r !== void 0).map((r) => r.name);
        return {
          ...a,
          roles: I
        };
      });
      k(
        l.filter((a) => a.notificationType === "WEB")
      ), w(
        l.filter((a) => a.notificationType === "WEB")
      ), f((a) => !a);
    } catch (t) {
      console.error(t), f((i) => !i);
    }
  };
  X(() => {
    N();
  }, []);
  const M = async (t) => {
    y(!1), t && N();
  };
  return v.isTecho && !m && !(n != null && n["view.manage.widgetManagement"]) ? /* @__PURE__ */ e(J, { className: "flex justify-center items-center w-full h-[80vh]", children: /* @__PURE__ */ e(
    C,
    {
      className: "h-80 w-150 flex justify-center items-center",
      children: /* @__PURE__ */ e(T, { variant: "h5", className: "text-customBlue", children: "You dont have permission to view Widgets Management" })
    }
  ) }) : /* @__PURE__ */ e(
    C,
    {
      variant: "elevation",
      container: !0,
      className: "mt-6 p-3 flex flex-col space-y-3 shadow-xl",
      children: /* @__PURE__ */ o(c, { container: !0, "data-testid": "widgetlist-container", children: [
        /* @__PURE__ */ e(Z, { children: b && /* @__PURE__ */ e(
          ne,
          {
            open: b,
            handleClose: M,
            data: D,
            roleData: d
          }
        ) }),
        m ? /* @__PURE__ */ e(se, {}) : /* @__PURE__ */ o(_, { children: [
          /* @__PURE__ */ o(
            c,
            {
              container: !0,
              size: { xs: 12 },
              className: "flex justify-between items-center",
              children: [
                /* @__PURE__ */ e(c, { children: /* @__PURE__ */ e(
                  T,
                  {
                    variant: "body2",
                    className: "font-bold font-sans text-lg text-customBlue uppercase",
                    "data-testid": "notification-list-typography-title",
                    children: h("Widget Management")
                  }
                ) }),
                /* @__PURE__ */ e(
                  O,
                  {
                    name: "searchQuery",
                    id: "searchQuery",
                    placeholder: "Search Text",
                    size: "small",
                    onChange: F,
                    value: p,
                    "data-testid": "widgetlist-textfield-search",
                    slotProps: {
                      input: {
                        className: "custom-input-root"
                      }
                    },
                    sx: {
                      "& .MuiInputBase-root": {
                        backgroundColor: (t) => t.palette.background.paper
                      }
                    }
                  }
                )
              ]
            }
          ),
          /* @__PURE__ */ e(
            c,
            {
              size: { xs: 12 },
              mt: 2,
              "data-testid": "widgetlist-table-container",
              children: /* @__PURE__ */ e(
                Q,
                {
                  component: "paper",
                  sx: { borderRadius: "12px" },
                  "data-testid": "widgetlist-table-paper",
                  children: /* @__PURE__ */ e(
                    te,
                    {
                      columns: A,
                      actions: W,
                      tableData: L,
                      paginationConfig: { pagination: !1 },
                      dataTestId: "widgetlist-table-customized",
                      isLoading: m,
                      styleConfig: { tableStyle: { maxHeight: 55 } }
                    }
                  )
                }
              )
            }
          )
        ] })
      ] })
    }
  );
}
export {
  we as default
};
//# sourceMappingURL=WidgetList-D-fIf3N2.js.map
