import { jsx as e, jsxs as l } from "react/jsx-runtime";
import { api as A } from "@/common/interceptors/AxiosInterceptor";
import { showToast as T } from "@/common/toaster/toaster";
import { Typography as w, TextField as S, Button as I, TableContainer as k, Paper as j, Table as L, TableHead as R, TableRow as u, TableCell as t, TableBody as E, IconButton as W } from "@mui/material";
import f from "@mui/material/Grid2";
import { Box as B } from "@mui/system";
import { useState as m, useEffect as J } from "react";
import { useNavigate as O } from "react-router";
import z from "@/common/fontAwesomeIcons/FontAwesomeIcons";
const F = "/mobilemenu/v2", P = {
  getMobileMenuList: () => A.get(F + "/list")
};
function X() {
  const [p, y] = m([]), [x, C] = m(""), [c, h] = m([]), g = O(), N = (o, r, a) => {
    const s = `addMenuConfiguration?${new URLSearchParams({ id: o }).toString()}`;
    g(s, { state: { mobileMenuList: c[a], roleId: r } });
  };
  J(() => {
    (async () => await M())();
  }, []);
  const M = async () => {
    try {
      const o = ((await P.getMobileMenuList()).data || []).map((r) => {
        const a = JSON.parse(r.configJson);
        let s = [];
        Object.values(a).forEach((i) => {
          let d = [];
          i.features && Array.isArray(i.features) ? d = i.features : i.layout && Array.isArray(i.layout) && (d = i.layout.flatMap((n) => n.type === "SECTION" && n.features && Array.isArray(n.features) ? n.features : [])), d.forEach((n) => {
            n.menuName && !n.menus && s.push(n.menuName), n.menus && Array.isArray(n.menus) && n.menus.forEach((b) => {
              b.menuName && s.push(b.menuName);
            });
          });
        });
        const v = [...new Set(s)].join(", ");
        return {
          id: r.id,
          roleId: r.roleId,
          name: r.roleName,
          features: v,
          configJson: a
        };
      });
      y(o), h(o);
    } catch (o) {
      T({ message: o, type: "error" });
    }
  };
  return /* @__PURE__ */ e(f, { children: /* @__PURE__ */ l(B, { sx: { p: 3, backgroundColor: "background.default" }, children: [
    /* @__PURE__ */ l(f, { container: !0, sx: { justifyContent: "space-between", alignItems: "center", mb: 2 }, children: [
      /* @__PURE__ */ e(w, { variant: "h5", sx: { mb: 2, fontWeight: "bold" }, children: "Mobile Menu Management" }),
      /* @__PURE__ */ e(
        S,
        {
          size: "small",
          placeholder: "Search Role",
          variant: "outlined",
          value: x,
          onChange: (o) => {
            const r = o.target.value.toLowerCase();
            C(r), h(p.filter((a) => a.name.toLowerCase().includes(r)));
          },
          sx: { mb: 2, backgroundColor: "#fff", borderRadius: 1 }
        }
      )
    ] }),
    /* @__PURE__ */ e(f, { sx: { justifyContent: "center", alignItems: "center", mb: 2 }, children: /* @__PURE__ */ e(
      I,
      {
        sx: { float: "right", mb: 2 },
        size: "small",
        variant: "contained",
        color: "success",
        onClick: () => {
          g("addMenuConfiguration");
        },
        children: "Add configuration"
      }
    ) }),
    /* @__PURE__ */ e(k, { component: j, elevation: 1, sx: { borderRadius: 2, maxHeight: 700 }, children: /* @__PURE__ */ l(L, { children: [
      /* @__PURE__ */ e(R, { children: /* @__PURE__ */ l(u, { sx: { backgroundColor: "#f2f2f2" }, children: [
        /* @__PURE__ */ e(t, { sx: { fontWeight: "bold" }, children: "Sr. No." }),
        /* @__PURE__ */ e(t, { sx: { fontWeight: "bold" }, children: "Role Name" }),
        /* @__PURE__ */ e(t, { sx: { fontWeight: "bold" }, children: "Features" }),
        /* @__PURE__ */ e(t, { align: "center", sx: { fontWeight: "bold" }, children: "Actions" })
      ] }) }),
      /* @__PURE__ */ l(E, { children: [
        c.map((o, r) => /* @__PURE__ */ l(
          u,
          {
            sx: {
              backgroundColor: r % 2 === 0 ? "#fff" : "#f9f9f9",
              "&:hover": { backgroundColor: "#e9f3ff" }
            },
            children: [
              /* @__PURE__ */ e(t, { children: r + 1 }),
              /* @__PURE__ */ e(t, { children: o.name }),
              /* @__PURE__ */ e(t, { children: o.features }),
              /* @__PURE__ */ e(t, { align: "center", children: /* @__PURE__ */ e(W, { color: "primary", onClick: () => N(o.id, o.roleId, r), children: /* @__PURE__ */ e(z, { iconName: "faPen", size: "sm" }) }) })
            ]
          },
          r
        )),
        c.length === 0 && /* @__PURE__ */ e(u, { children: /* @__PURE__ */ e(t, { colSpan: 4, align: "center", sx: { py: 4, color: "gray" }, children: "No roles found." }) })
      ] })
    ] }) })
  ] }) });
}
export {
  X as default
};
//# sourceMappingURL=MobileMenuManagement-BmrO-7MN-xFkU87j6.js.map
