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