import { E as compilerRuntimeExports, j as jsxRuntimeExports, T as useNavigate, J as useLocation, r as reactExports } from "./vendor-react-DYNCg6N5.js";
import { H as HEADER_HEIGHT, b as useActions, W as useLazyLogoutQuery, c as useAppSelector, X as AppsMenu, Y as UserMenu, Z as getMenu, _ as TailType, $ as MainHeader, a0 as UserAvatar } from "./index-DfebxkL9.js";
import { c as createStyles, b as Box, I as Image, T as Text, B as Button, n as useDisclosure, G as Group, M as Menu } from "./vendor-mantine-h0WlM2Mj.js";
import { M as Modal } from "./index-DqcA8P_y.js";
import { u as useTranslation } from "./vendor-i18n-wisIXUFi.js";
import "./vendor-icons-xWhXK_Ui.js";
import "./styles-3NoIlzov.js";
const useStyles$1 = createStyles(() => ({
  container: {
    backgroundColor: "#F5F6F8"
  },
  root: {
    height: `calc(100vh - ${HEADER_HEIGHT}px)`,
    marginTop: HEADER_HEIGHT,
    width: "100%",
    display: "flex"
  },
  user_box: {
    display: "flex",
    flexDirection: "column",
    backgroundColor: "#F5F6F8",
    margin: "auto",
    paddingTop: "20px",
    width: "auto",
    maxWidth: "1000px",
    justifyContent: "center",
    alignItems: "center",
    boxSizing: "border-box"
  },
  user_box_avatar: {
    display: "flex",
    flexDirection: "column",
    alignItems: "center",
    justifyContent: "space-between",
    width: "320px",
    marginBottom: "36px"
  },
  menu: {
    display: "flex!important",
    backgroundColor: "inehrit",
    marginTop: "30px",
    flexWrap: "wrap",
    justifyContent: "center"
  },
  menu_item: {
    display: "flex",
    flexDirection: "column",
    backgroundColor: "#FFFFFF",
    size: "16px",
    width: "180px",
    height: "100px",
    margin: "8px",
    "@media (max-width: 760px)": {
      width: "100%",
      maxWidth: "180px"
    },
    "& .mantine-Menu-itemIcon": {
      marginRight: "0"
    },
    "& .mantine-Menu-itemSection": {
      margin: 0
    },
    "&[data-hovered]": {
      backgroundColor: "#FFFFFF"
    }
  },
  user_box_buttons: {
    display: "flex",
    justifyContent: "center",
    width: "100%",
    gap: "15px",
    "& button": {
      height: "42px",
      fontWeight: "normal",
      fontSize: "16px"
    }
  }
}));
const useStyles = createStyles((theme) => ({
  container: {
    width: "100%",
    display: "flex",
    flexDirection: "column",
    justifyContent: "start",
    alignItems: "start",
    padding: theme.spacing.xl
  },
  logoContainer: {
    marginBottom: theme.spacing.xl,
    display: "flex",
    justifyContent: "flex-start",
    alignItems: "center"
  },
  descriptionTitle: {
    fontSize: "32px",
    lineHeight: "100%",
    fontWeight: 500,
    marginBottom: theme.spacing.sm
  },
  descriptionText: {
    fontSize: theme.fontSizes.md,
    color: theme.colors.gray[6],
    marginBottom: theme.spacing.xl
  },
  buttonText: {
    margin: theme.spacing.xl,
    padding: theme.spacing.xl
  },
  closeButton: {
    "&:focus": {
      border: "none",
      outline: "none"
    }
  }
}));
const NoAccessModuleCard = (t0) => {
  const $ = compilerRuntimeExports.c(38);
  const {
    iconSrc,
    moduleTitle,
    handleClose
  } = t0;
  const {
    classes
  } = useStyles();
  const {
    t
  } = useTranslation();
  const t1 = classes.container;
  let t2;
  if ($[0] !== iconSrc || $[1] !== moduleTitle) {
    t2 = /* @__PURE__ */ jsxRuntimeExports.jsx(Image, { src: iconSrc, width: 32, h: 32, alt: moduleTitle });
    $[0] = iconSrc;
    $[1] = moduleTitle;
    $[2] = t2;
  } else {
    t2 = $[2];
  }
  let t3;
  if ($[3] !== moduleTitle) {
    t3 = moduleTitle == null ? void 0 : moduleTitle.toUpperCase();
    $[3] = moduleTitle;
    $[4] = t3;
  } else {
    t3 = $[4];
  }
  let t4;
  if ($[5] !== t3) {
    t4 = /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { fz: "xl", fw: "bold", ml: "sm", children: t3 });
    $[5] = t3;
    $[6] = t4;
  } else {
    t4 = $[6];
  }
  let t5;
  if ($[7] !== classes.logoContainer || $[8] !== t2 || $[9] !== t4) {
    t5 = /* @__PURE__ */ jsxRuntimeExports.jsxs(Box, { className: classes.logoContainer, children: [
      t2,
      t4
    ] });
    $[7] = classes.logoContainer;
    $[8] = t2;
    $[9] = t4;
    $[10] = t5;
  } else {
    t5 = $[10];
  }
  const t6 = classes.descriptionTitle;
  let t7;
  if ($[11] !== t) {
    t7 = t("errors.accessError");
    $[11] = t;
    $[12] = t7;
  } else {
    t7 = $[12];
  }
  let t8;
  if ($[13] !== classes.descriptionTitle || $[14] !== t7) {
    t8 = /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { className: t6, children: t7 });
    $[13] = classes.descriptionTitle;
    $[14] = t7;
    $[15] = t8;
  } else {
    t8 = $[15];
  }
  const t9 = classes.descriptionText;
  let t10;
  if ($[16] !== moduleTitle || $[17] !== t) {
    t10 = t("errors.doNotAccessToModule", {
      module: moduleTitle
    });
    $[16] = moduleTitle;
    $[17] = t;
    $[18] = t10;
  } else {
    t10 = $[18];
  }
  let t11;
  if ($[19] !== classes.descriptionText || $[20] !== t10) {
    t11 = /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { className: t9, children: t10 });
    $[19] = classes.descriptionText;
    $[20] = t10;
    $[21] = t11;
  } else {
    t11 = $[21];
  }
  let t12;
  if ($[22] !== t11 || $[23] !== t8) {
    t12 = /* @__PURE__ */ jsxRuntimeExports.jsxs(Box, { children: [
      t8,
      t11
    ] });
    $[22] = t11;
    $[23] = t8;
    $[24] = t12;
  } else {
    t12 = $[24];
  }
  const t13 = classes.closeButton;
  let t14;
  if ($[25] !== t) {
    t14 = t("close");
    $[25] = t;
    $[26] = t14;
  } else {
    t14 = $[26];
  }
  let t15;
  if ($[27] !== t14) {
    t15 = /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { children: t14 });
    $[27] = t14;
    $[28] = t15;
  } else {
    t15 = $[28];
  }
  let t16;
  if ($[29] !== classes.closeButton || $[30] !== handleClose || $[31] !== t15) {
    t16 = /* @__PURE__ */ jsxRuntimeExports.jsx(Box, { w: "100%", children: /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { className: t13, size: "lg", fullWidth: true, onClick: handleClose, children: t15 }) });
    $[29] = classes.closeButton;
    $[30] = handleClose;
    $[31] = t15;
    $[32] = t16;
  } else {
    t16 = $[32];
  }
  let t17;
  if ($[33] !== classes.container || $[34] !== t12 || $[35] !== t16 || $[36] !== t5) {
    t17 = /* @__PURE__ */ jsxRuntimeExports.jsxs(Box, { className: t1, children: [
      t5,
      t12,
      t16
    ] });
    $[33] = classes.container;
    $[34] = t12;
    $[35] = t16;
    $[36] = t5;
    $[37] = t17;
  } else {
    t17 = $[37];
  }
  return t17;
};
const Dashboard = () => {
  const {
    classes
  } = useStyles$1();
  const {
    t
  } = useTranslation();
  const navigate = useNavigate();
  const location = useLocation();
  const {
    setSelectedUserId
  } = useActions();
  const {
    setUserInfo,
    setUserTokens
  } = useActions();
  const [fetchLogout] = useLazyLogoutQuery();
  const {
    User
  } = useAppSelector((state) => state.userInfo);
  const [opened, {
    open,
    close
  }] = useDisclosure(false);
  const [fromValue, setFromValue] = reactExports.useState();
  const handleCloseAccessCard = () => {
    close();
  };
  const rightSection = reactExports.useMemo(() => !User ? null : /* @__PURE__ */ jsxRuntimeExports.jsxs(Group, { gap: "sm", children: [
    /* @__PURE__ */ jsxRuntimeExports.jsx(AppsMenu, {}),
    /* @__PURE__ */ jsxRuntimeExports.jsx(UserMenu, { user: User })
  ] }), [User]);
  const handleClickListItem = reactExports.useCallback(async (event) => {
    const value = event.currentTarget.dataset.value ?? "";
    switch (value) {
      case "profile":
        if (User) {
          setSelectedUserId(User == null ? void 0 : User.Id);
          navigate("/profile/" + (User == null ? void 0 : User.Id));
        }
        break;
      case "logout":
        setUserInfo({});
        setUserTokens({});
        navigate("/login");
        await fetchLogout();
        localStorage.removeItem("AuthToken");
        break;
    }
  }, [User]);
  const modules = useAppSelector((state_0) => {
    var _a;
    return (_a = state_0.userInfo.Settings) == null ? void 0 : _a.ModuleSettings;
  });
  const menu = modules ? getMenu(modules) : [];
  reactExports.useEffect(() => {
    var _a;
    const searchParams = new URLSearchParams(location.search);
    const fromParam = searchParams.get("from");
    if (fromParam) {
      const fromModule = (_a = modules == null ? void 0 : modules.ModuleUrls) == null ? void 0 : _a.find((module) => (module == null ? void 0 : module.Name) === fromParam);
      if (!fromValue && (fromModule == null ? void 0 : fromModule.Title) && (fromModule == null ? void 0 : fromModule.Icon)) {
        setFromValue({
          moduleTitle: fromModule == null ? void 0 : fromModule.Title,
          iconSrc: fromModule == null ? void 0 : fromModule.Icon
        });
        open();
      }
    }
  }, [location]);
  const filteredMenu = menu.filter((i) => i.tailType === TailType.Integration || i.tailType === TailType.Module);
  return /* @__PURE__ */ jsxRuntimeExports.jsxs(Box, { className: classes.container, children: [
    /* @__PURE__ */ jsxRuntimeExports.jsx(MainHeader, { list: [], rightSection, dashboardPage: true }),
    /* @__PURE__ */ jsxRuntimeExports.jsx(Box, { className: classes.root, children: /* @__PURE__ */ jsxRuntimeExports.jsxs(Box, { "data-id": User == null ? void 0 : User.Id, className: classes.user_box, children: [
      /* @__PURE__ */ jsxRuntimeExports.jsxs(Box, { className: classes.user_box_avatar, children: [
        /* @__PURE__ */ jsxRuntimeExports.jsx(UserAvatar, { user: User, src: User == null ? void 0 : User.Avatar, size: 100, notClickable: true }),
        /* @__PURE__ */ jsxRuntimeExports.jsx(Box, { children: /* @__PURE__ */ jsxRuntimeExports.jsxs(Text, { ta: "center", fw: 400, fz: 20, mt: 16, mb: 16, children: [
          t("hello"),
          ", ",
          User == null ? void 0 : User.FirstName,
          " ",
          User == null ? void 0 : User.MiddleName
        ] }) }),
        /* @__PURE__ */ jsxRuntimeExports.jsxs(Box, { className: classes.user_box_buttons, children: [
          /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { variant: "default", "data-value": "profile", onClick: handleClickListItem, children: t("goToProfile") }),
          /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { variant: "default", "data-value": "logout", onClick: handleClickListItem, children: t("exit") })
        ] })
      ] }),
      /* @__PURE__ */ jsxRuntimeExports.jsx(Box, { className: classes.menu, children: filteredMenu.length > 0 && /* @__PURE__ */ jsxRuntimeExports.jsx(Menu, { transitionProps: {
        transition: "fade",
        duration: 150
      }, children: filteredMenu.map((item, index) => item.url && item.label && /* @__PURE__ */ jsxRuntimeExports.jsx(Menu.Item, { className: classes.menu_item, component: "a", href: item.url, fz: 14, leftSection: item.iconSrc ? /* @__PURE__ */ jsxRuntimeExports.jsx(Box, { component: "img", src: item.iconSrc, height: 48, mt: 6, mb: 6 }) : /* @__PURE__ */ jsxRuntimeExports.jsx(Image, { height: 48, mt: 6, mb: 6, src: null }), children: /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { fw: 400, fz: 16, children: item == null ? void 0 : item.label }) }, index)) }) })
    ] }) }),
    /* @__PURE__ */ jsxRuntimeExports.jsx(Modal, { onClose: handleCloseAccessCard, opened, withCloseButton: false, size: "lg", centered: true, children: /* @__PURE__ */ jsxRuntimeExports.jsx(NoAccessModuleCard, { iconSrc: fromValue == null ? void 0 : fromValue.iconSrc, moduleTitle: fromValue == null ? void 0 : fromValue.moduleTitle, handleClose: handleCloseAccessCard }) })
  ] });
};
export {
  Dashboard
};
//# sourceMappingURL=index-dNCk3QFy.js.map
