import { r as reactExports, j as jsxRuntimeExports, E as compilerRuntimeExports, a as r } from "./vendor-react-DYNCg6N5.js";
import { E as EditUserInfoContext } from "./index-TL41xEJi.js";
import { S as SectionTemplate } from "./index-CbTPqI7c.js";
import { E as EmailServerIntegrationType$1 } from "./types-Cx44Kkix.js";
import { cD as useLazyCheckExistsEmailForLinkQuery, cE as useGetEmailServerQuery, b3 as useLazyGetDomainsQuery, cF as useLazyGetPasswordRulesQuery, O as themeColors, t as extractErrorCode, v as generateErrorMessage, cG as useLazyCreateEmailWithoutLinkedUserQuery, m as universalNotification, c as useAppSelector, bT as isAdmin, cH as useLazyChangeEmailLoginQuery, cI as useLazyChangePasswordLinkedUserEmailQuery, bU as ErrorsEnum, aU as axiosInstance } from "./index-DfebxkL9.js";
import { m as modalTheme } from "./styles-3NoIlzov.js";
import { c as createStyles, z as useForm, F as Flex, a4 as Select, E as TextInput, a0 as SimpleGrid, J as PasswordInput, B as Button, V as LoadingOverlay, s as showNotification, b as Box, T as Text, n as useDisclosure, W as useMediaQuery, g as Loader, h as ActionIcon, K as Divider } from "./vendor-mantine-h0WlM2Mj.js";
import { aa as $c, b as gq, y as IconTrash, ab as IconCheck, F as IconX, a8 as IconPlus, ac as CEe, ad as mEe, ae as IconMail, T as CX } from "./vendor-icons-xWhXK_Ui.js";
import { M as Modal } from "./index-DqcA8P_y.js";
import { g as getValidateErrors } from "./validation-Ds00Zghx.js";
import { E as EmailServerIntegrationType } from "./types-DVpDEwlm.js";
import { a as useMailServerPasswordSchema, u as usePasswordSchema } from "./useGeneratePolicy-B4rO5xUa.js";
import { a as useGenerateMailServerRules, R as RulesConditionList, d as defaultMailServerPasswordOptions, u as useGenerateRules } from "./passwordOptions-b-kjbiiT.js";
import { u as useTranslation } from "./vendor-i18n-wisIXUFi.js";
import { s as stringType, o as objectType } from "./types-espwwxTQ.js";
import { u as useUpdateInfo, a as ProfileUpdateTypeEnum, P as ProfileSectionEnum } from "./useUpdateUser-innD962A.js";
import { P as PopUpUI } from "./index-DGrXxZ89.js";
import { A as AddButton } from "./index-72JBTuLT.js";
import "./index-B7nmdYVM.js";
import "./utils-D5kCyTRM.js";
import "./types-B9VC9FeZ.js";
import "./passwordUtils-B3CN2t6O.js";
const useStyles = createStyles((theme, _, utils) => ({
  modalRoot: {
    padding: "8px 0 0 0",
    width: "100%",
    height: "100%",
    display: "flex",
    flexDirection: "column",
    alignItems: "center",
    justifyContent: "space-between"
  },
  LDAP: {
    borderRadius: "14px",
    color: "rgba(255, 255, 255, 1)",
    backgroundColor: "rgba(51, 154, 240, 1)",
    fontWeight: "500",
    fontSize: "11px",
    textAlign: "center",
    marginRight: "14px",
    padding: "4px 7px",
    verticalAlign: "middle",
    textTransform: "uppercase"
  },
  modalContainer: {
    gap: 8
  },
  modalFooter: {
    display: "flex",
    justifyContent: "space-between"
  },
  modalCancelBtn: modalTheme(theme).cancelBtn,
  accountName: {
    marginBottom: "16px"
  },
  listWrapper: {
    display: "flex",
    flexDirection: "column",
    gap: "16px",
    width: "100%"
  },
  addBtn: {
    width: 300,
    borderRadius: "8px",
    border: `1px solid ${theme.colors.brandGray[0]}`,
    marginBottom: "auto",
    "&:hover": {
      backgroundColor: "#f6f7f8"
    },
    "& .mantine-Button-inner": {
      display: "flex",
      flexDirection: "row",
      alignItems: "center",
      justifyContent: "space-between"
    },
    "& .mantine-Button-label": {
      color: theme.black
    }
  },
  changePasswordButton: {
    backgroundColor: theme.colors.backgroundGray[6],
    borderRadius: "8px",
    border: `1px solid ${theme.colors.backgroundGray[6]}`,
    marginBottom: "auto",
    "&:hover": {
      backgroundColor: "#f6f7f8"
    },
    "& .mantine-Button-label": {
      color: theme.black
    },
    marginTop: "0!important"
  },
  listRow: {
    maxWidth: 600,
    position: "relative",
    alignItems: "center",
    gap: 20,
    "& .mantine-TextInput-input": {
      borderRadius: "8px",
      border: "1px solid #D0D5DD"
    },
    "@media (min-width: 576px)": {
      gridTemplateColumns: "1fr 1fr 60px",
      width: "100%"
    },
    "@media (max-width: 576px)": {
      width: "100%",
      gap: "8px"
    }
  },
  nameMail: {
    width: "350px"
  },
  badge: {
    paddingRight: 3,
    backgroundColor: theme.colors.backgroundGray[6],
    color: "black",
    borderRadius: "16px",
    marginBottom: "4px",
    border: "none",
    textTransform: "inherit",
    fontSize: "14px",
    padding: theme.spacing.sm,
    fontWeight: 400,
    marginTop: "24px",
    height: "2.25rem"
  },
  removeButton: {
    marginBottom: "2px",
    marginTop: "auto",
    display: "flex",
    alignItems: "center",
    "& .mantine-ActionIcon-root": {
      display: "flex",
      alignItems: "center",
      height: "100%",
      alignSelf: "center"
    },
    "& button:hover": {
      backgroundColor: "transparent"
    },
    [utils.smallerThan("xs")]: {
      position: "absolute",
      right: "5px",
      top: "1px"
    }
  },
  title: {
    fontWeight: 600
  },
  textFieldInput: {
    "& .mantine-TextInput-label, .mantine-InputWrapper-label": {
      fontSize: "14px",
      fontWeight: 500
    },
    "& .mantine-TextInput-input": {
      borderRadius: "4px",
      border: "1px solid #D0D5DD"
    }
  },
  createContainer: {
    flexGrow: 1,
    display: "flex",
    justifyContent: "space-between",
    alignItems: "flex-end"
  },
  controlsButtons: {
    justifyContent: "space-between",
    [utils.smallerThan("xs")]: {
      flexDirection: "column",
      "button:first-of-type": {
        margin: "0 0 15px 0"
      }
    }
  },
  dropdown: {
    display: "none"
  },
  select: {
    "& .mantine-Select-input": {
      cursor: "default",
      "&:focus": {
        borderColor: "#D0D5DD"
      }
    }
  }
}));
const LinkEmailModal = ({
  handleAddEmail,
  opened,
  handleClose,
  filialId,
  isLoading,
  isSuccess,
  editUser
}) => {
  const {
    classes
  } = useStyles();
  const {
    t
  } = useTranslation();
  const [checkLinkEmail, {
    isError,
    isFetching
  }] = useLazyCheckExistsEmailForLinkQuery();
  const [selectedServerId, setSelectedServerId] = reactExports.useState(null);
  const [selectedDomain, setSelectedDomain] = reactExports.useState(null);
  const schemaRef = reactExports.useRef(stringType());
  const {
    data: emailServers,
    isLoading: isLoadingServers
  } = useGetEmailServerQuery({
    Id: filialId || 0
  }, {
    skip: !filialId
  });
  const [getDomains, {
    data: domains,
    isLoading: isLoadingDomains,
    reset: resetDomains
  }] = useLazyGetDomainsQuery();
  const [getPasswordRules, {
    data: passwordRulesData
  }] = useLazyGetPasswordRulesQuery();
  const linkForm = useForm({
    initialValues: {
      Email: "",
      Login: "",
      Password: ""
    },
    validateInputOnChange: true,
    validate: (values) => getValidateErrors(schemaRef.current, values)
  });
  const emailServerList = reactExports.useMemo(() => Array.isArray(emailServers) ? emailServers == null ? void 0 : emailServers.map((server) => {
    var _a, _b, _c;
    const t_0 = (_a = server == null ? void 0 : server.Integration) == null ? void 0 : _a.Type;
    let suffix = "";
    if (t_0 === EmailServerIntegrationType.Ssh || ((_b = server == null ? void 0 : server.Integration) == null ? void 0 : _b.Ssh)) suffix = " (SSH)";
    else if (t_0 === EmailServerIntegrationType.Api || ((_c = server == null ? void 0 : server.Integration) == null ? void 0 : _c.Api)) suffix = " (API)";
    return {
      label: `${server.Name || `Server ${server.Id}`}${suffix}`,
      value: String(server.Id)
    };
  }) : [], [emailServers]);
  const domainList = reactExports.useMemo(() => {
    if (!domains) return [];
    if (Array.isArray(domains) && domains.length > 0) {
      return domains.map((domain) => ({
        label: String(domain == null ? void 0 : domain.Domain),
        value: domain == null ? void 0 : domain.Domain
      }));
    }
    return [];
  }, [domains]);
  const selectedServer = reactExports.useMemo(() => Array.isArray(emailServers) ? emailServers.find((s) => String(s.Id) === selectedServerId) : void 0, [emailServers, selectedServerId]);
  const integrationType = reactExports.useMemo(() => {
    var _a, _b, _c;
    if (!selectedServer) return EmailServerIntegrationType.None;
    const t_1 = (_a = selectedServer == null ? void 0 : selectedServer.Integration) == null ? void 0 : _a.Type;
    if (t_1 === EmailServerIntegrationType.Ssh) return EmailServerIntegrationType.Ssh;
    if (t_1 === EmailServerIntegrationType.Api) return EmailServerIntegrationType.Api;
    if ((_b = selectedServer == null ? void 0 : selectedServer.Integration) == null ? void 0 : _b.Ssh) return EmailServerIntegrationType.Ssh;
    if ((_c = selectedServer == null ? void 0 : selectedServer.Integration) == null ? void 0 : _c.Api) return EmailServerIntegrationType.Api;
    return EmailServerIntegrationType.None;
  }, [selectedServer]);
  const activeRules = reactExports.useMemo(() => {
    if (!passwordRulesData) return null;
    if (integrationType === EmailServerIntegrationType.Ssh) return passwordRulesData.SshRules;
    if (integrationType === EmailServerIntegrationType.Api) return passwordRulesData.ApiRules;
    return null;
  }, [passwordRulesData, integrationType]);
  const hasIntegration = integrationType !== EmailServerIntegrationType.None;
  const serverPasswordSchema = useMailServerPasswordSchema(activeRules, t);
  const simplePasswordSchema = stringType().min(1, {
    message: t("servers.addPassword")
  });
  const passwordRulesZ = activeRules ? serverPasswordSchema : simplePasswordSchema;
  const linkFormSchema = objectType({
    Email: stringType().min(1, {
      message: t("emailMinError")
    }).refine((data) => !/\s/.test(data), {
      message: t("validation.emptyEmail")
    }),
    Password: passwordRulesZ
  });
  schemaRef.current = linkFormSchema;
  const password = linkForm.values.Password;
  const serverDisplayRules = useGenerateMailServerRules(password, activeRules);
  const isDisabled = Object.keys(linkForm.errors).length !== 0 || !linkForm.isDirty();
  reactExports.useEffect(() => {
    if (selectedServerId && filialId) {
      resetDomains();
      setSelectedDomain(null);
      getDomains({
        ServerId: Number(selectedServerId),
        CustomerId: filialId
      });
    }
  }, [selectedServerId, filialId, getDomains, resetDomains]);
  reactExports.useEffect(() => {
    if (selectedServerId && integrationType !== EmailServerIntegrationType.None) {
      getPasswordRules({
        serverId: Number(selectedServerId)
      });
    }
  }, [selectedServerId, integrationType]);
  reactExports.useEffect(() => {
    var _a;
    if (domains !== void 0) {
      if (domains && domains.length > 0) {
        const firstDomain = (_a = domains[0]) == null ? void 0 : _a.Domain;
        if (firstDomain) {
          setSelectedDomain(firstDomain);
        }
      }
    }
  }, [domains]);
  reactExports.useEffect(() => {
    if (linkForm.values.Password) {
      linkForm.validateField("Password");
    }
  }, [activeRules]);
  const modalClose = () => {
    linkForm.reset();
    setSelectedServerId(null);
    setSelectedDomain(null);
    handleClose();
  };
  const handleEmailChange = (event) => {
    const {
      value
    } = event.currentTarget;
    if (!value.includes("@")) {
      linkForm.setFieldValue("Email", value);
    }
  };
  const handleSubmit = async () => {
    var _a, _b, _c, _d;
    linkForm.validate();
    if (!linkForm.isValid()) return;
    const {
      Email,
      Login,
      Password
    } = linkForm.values;
    const fullEmail = selectedDomain ? `${Email.toLowerCase()}@${selectedDomain}` : Email;
    try {
      const res = await checkLinkEmail({
        Email: fullEmail,
        Login,
        CustomerId: filialId,
        ServerId: selectedServerId ? Number(selectedServerId) : void 0
      });
      if ("error" in res) {
        const codeError = extractErrorCode(res.error);
        showNotification({
          title: generateErrorMessage(codeError),
          message: "",
          autoClose: true,
          color: "red"
        });
      } else {
        if (!editUser) {
          modalClose();
        }
        if (handleAddEmail && res.data) {
          const {
            Id,
            UserId
          } = res.data;
          handleAddEmail({
            Email: fullEmail,
            Password,
            Id,
            Login: Login || res.data.Login,
            UserId,
            EmailServer: {
              Id: ((_b = (_a = res == null ? void 0 : res.data) == null ? void 0 : _a.EmailServer) == null ? void 0 : _b.Id) || 0,
              Name: (_d = (_c = res == null ? void 0 : res.data) == null ? void 0 : _c.EmailServer) == null ? void 0 : _d.Name,
              IntegrationType: EmailServerIntegrationType.None
            }
          });
        }
      }
    } catch (err) {
      console.warn(t("profile.error.createEmail"), err);
    }
  };
  reactExports.useEffect(() => {
    if (isSuccess && !isLoading) {
      modalClose();
    }
  }, [isSuccess, isLoading]);
  return /* @__PURE__ */ jsxRuntimeExports.jsx(Modal, { opened, onClose: modalClose, title: t("profile.addEmailAccount"), zIndex: 1300, children: /* @__PURE__ */ jsxRuntimeExports.jsxs("form", { className: classes.modalRoot, children: [
    /* @__PURE__ */ jsxRuntimeExports.jsxs(Flex, { gap: "8px", direction: "column", p: "16px 34px", w: "100%", className: classes.modalContainer, children: [
      /* @__PURE__ */ jsxRuntimeExports.jsx(Flex, { w: "100%", children: /* @__PURE__ */ jsxRuntimeExports.jsx(Select, { comboboxProps: {
        zIndex: 1300
      }, w: "100%", label: t("profile.emailServer") || "Email Server", placeholder: isLoadingServers ? t("loading") || "Loading..." : emailServerList.length === 0 ? t("profile.noEmailServers") || "No email servers available" : t("profile.selectServer") || "Select email server", data: emailServerList, value: selectedServerId, onChange: setSelectedServerId, disabled: isLoadingServers || emailServerList.length === 0, withAsterisk: true }) }),
      /* @__PURE__ */ jsxRuntimeExports.jsx(Flex, { w: "100%", children: /* @__PURE__ */ jsxRuntimeExports.jsx(TextInput, { w: "100%", label: t("profile.login") || "Login", className: classes.textFieldInput, placeholder: t("validation.enterLogin") || "Enter login", ...linkForm.getInputProps("Login") }) }),
      /* @__PURE__ */ jsxRuntimeExports.jsxs(Flex, { w: "100%", align: "start", children: [
        /* @__PURE__ */ jsxRuntimeExports.jsx(TextInput, { w: "100%", label: t("profile.email") || "E-mail", className: classes.textFieldInput, placeholder: t("profile.email"), withAsterisk: true, ...linkForm.getInputProps("Email"), onChange: handleEmailChange }),
        /* @__PURE__ */ jsxRuntimeExports.jsx(Flex, { mr: "xs", ml: "xs", mt: "32px", children: /* @__PURE__ */ jsxRuntimeExports.jsx($c, { size: 22, color: themeColors.brandGray[0] }) }),
        /* @__PURE__ */ jsxRuntimeExports.jsx(Flex, { className: classes.createContainer, children: /* @__PURE__ */ jsxRuntimeExports.jsx(Select, { label: t("profile.domain") || "Domain", data: domainList, w: "100%", rightSectionWidth: domainList.length > 1 ? 25 : 0, comboboxProps: {
          zIndex: 1300
        }, rightSection: domainList.length > 1 ? /* @__PURE__ */ jsxRuntimeExports.jsx(gq, { color: "#98A2B3", size: 18 }) : null, styles: {
          rightSection: {
            pointerEvents: "none"
          }
        }, maxDropdownHeight: 150, allowDeselect: false, value: selectedDomain, onChange: setSelectedDomain, disabled: !selectedServerId || isLoadingDomains }) })
      ] }),
      /* @__PURE__ */ jsxRuntimeExports.jsxs(SimpleGrid, { cols: 1, w: "100%", children: [
        /* @__PURE__ */ jsxRuntimeExports.jsx(PasswordInput, { "data-lpignore": "true", autoComplete: "new-password", className: classes.textFieldInput, placeholder: t("profile.password"), label: t("profile.password"), withAsterisk: true, ...linkForm.getInputProps("Password") }),
        hasIntegration && /* @__PURE__ */ jsxRuntimeExports.jsx(RulesConditionList, { rules: serverDisplayRules, check: password.length > 0 })
      ] })
    ] }),
    /* @__PURE__ */ jsxRuntimeExports.jsxs(Flex, { p: "16px 34px", w: "100%", justify: "space-between", gap: 12, children: [
      /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { variant: "filled", radius: 8, fullWidth: true, disabled: isDisabled, onClick: handleSubmit, children: t("profile.add") }),
      /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { fullWidth: true, color: "gray", variant: "outline", onClick: modalClose, children: t("cancel") })
    ] }),
    /* @__PURE__ */ jsxRuntimeExports.jsx(LoadingOverlay, { visible: isFetching && !isError || isLoading, overlayProps: {
      blur: 2
    } })
  ] }) });
};
const CreateEmailAccount = ({
  opened,
  handleClose,
  handleAddEmail,
  filialId
}) => {
  const {
    classes
  } = useStyles();
  const {
    t
  } = useTranslation();
  const [createEmail, {
    isFetching: createEmailFetching
  }] = useLazyCreateEmailWithoutLinkedUserQuery();
  const {
    data: emailServers,
    isLoading: isLoadingServers
  } = useGetEmailServerQuery({
    Id: filialId
  });
  const [getDomains, {
    data: serverDomains,
    isLoading: isLoadingDomains,
    reset: resetDomains
  }] = useLazyGetDomainsQuery();
  const NO_DOMAIN_VALUE = "__NO_DOMAIN__";
  const [getPasswordRules, {
    data: passwordRulesData,
    isFetching: isLoadingRules
  }] = useLazyGetPasswordRulesQuery();
  const schemaRef = reactExports.useRef(stringType());
  const createAccountForm = useForm({
    initialValues: {
      EmailServer: "",
      Login: "",
      Email: "",
      Password: "",
      Domain: ""
    },
    validateInputOnChange: true,
    validate: (values) => getValidateErrors(schemaRef.current, values)
  });
  const selectedServer = reactExports.useMemo(() => Array.isArray(emailServers) ? emailServers.find((s) => String(s.Id) === createAccountForm.values.EmailServer) : void 0, [emailServers, createAccountForm.values.EmailServer]);
  const integrationType = reactExports.useMemo(() => {
    var _a, _b, _c;
    if (!selectedServer) return EmailServerIntegrationType.None;
    const t_0 = (_a = selectedServer == null ? void 0 : selectedServer.Integration) == null ? void 0 : _a.Type;
    if (t_0 === EmailServerIntegrationType.Ssh) return EmailServerIntegrationType.Ssh;
    if (t_0 === EmailServerIntegrationType.Api) return EmailServerIntegrationType.Api;
    if ((_b = selectedServer == null ? void 0 : selectedServer.Integration) == null ? void 0 : _b.Ssh) return EmailServerIntegrationType.Ssh;
    if ((_c = selectedServer == null ? void 0 : selectedServer.Integration) == null ? void 0 : _c.Api) return EmailServerIntegrationType.Api;
    return EmailServerIntegrationType.None;
  }, [selectedServer]);
  const activeRules = reactExports.useMemo(() => {
    if (!passwordRulesData) return null;
    if (integrationType === EmailServerIntegrationType.Ssh) return passwordRulesData.SshRules;
    if (integrationType === EmailServerIntegrationType.Api) return passwordRulesData.ApiRules;
    return null;
  }, [passwordRulesData, integrationType]);
  const fallbackPasswordSchema = usePasswordSchema(defaultMailServerPasswordOptions, t);
  const serverPasswordSchema = useMailServerPasswordSchema(activeRules, t);
  const passwordRulesZ = activeRules ? serverPasswordSchema : fallbackPasswordSchema;
  const password = createAccountForm.values.Password;
  const defaultDisplayRules = useGenerateRules(password, defaultMailServerPasswordOptions);
  const serverDisplayRules = useGenerateMailServerRules(password, activeRules);
  const displayRules = activeRules ? serverDisplayRules : defaultDisplayRules;
  const createAccountSchema = objectType({
    EmailServer: stringType().min(1, {
      message: t("validation.required")
    }),
    Login: stringType().min(1, {
      message: t("validation.enterLogin")
    }).refine((data) => !/\s/.test(data), {
      message: t("validation.emptyLogin")
    }),
    Email: stringType().min(1, {
      message: t("emailMinError")
    }).refine((data_0) => !/\s/.test(data_0), {
      message: t("validation.emptyEmail")
    }),
    Password: passwordRulesZ,
    Domain: stringType().min(1, {
      message: t("domainMinError")
    }).refine((data_1) => data_1 !== NO_DOMAIN_VALUE, {
      message: t("noDomainsForMailServer")
    })
  });
  schemaRef.current = createAccountSchema;
  const isDisabled = Object.keys(createAccountForm.errors).length !== 0 || createEmailFetching || !createAccountForm.isDirty() || createAccountForm.values.Domain === NO_DOMAIN_VALUE;
  const emailServerList = reactExports.useMemo(() => Array.isArray(emailServers) ? emailServers.filter((server) => {
    var _a, _b, _c;
    const t_1 = (_a = server == null ? void 0 : server.Integration) == null ? void 0 : _a.Type;
    return t_1 === EmailServerIntegrationType.Ssh || t_1 === EmailServerIntegrationType.Api || ((_b = server == null ? void 0 : server.Integration) == null ? void 0 : _b.Ssh) || ((_c = server == null ? void 0 : server.Integration) == null ? void 0 : _c.Api);
  }).map((server_0) => {
    var _a, _b;
    const t_2 = (_a = server_0 == null ? void 0 : server_0.Integration) == null ? void 0 : _a.Type;
    const suffix = t_2 === EmailServerIntegrationType.Ssh || ((_b = server_0 == null ? void 0 : server_0.Integration) == null ? void 0 : _b.Ssh) ? " (SSH)" : " (API)";
    return {
      label: `${server_0.Name || `Server ${server_0.Id}`}${suffix}`,
      value: String(server_0.Id)
    };
  }) : [], [emailServers]);
  const domainList = reactExports.useMemo(() => {
    if (!serverDomains) return [];
    if (Array.isArray(serverDomains) && serverDomains.length > 0) {
      return serverDomains.map((Item) => ({
        label: String(Item == null ? void 0 : Item.Domain),
        value: Item == null ? void 0 : Item.Domain
      }));
    }
    return [{
      label: t("noDomain"),
      value: NO_DOMAIN_VALUE,
      disabled: true
    }];
  }, [serverDomains, t]);
  reactExports.useEffect(() => {
    const selectedServerId = createAccountForm.values.EmailServer;
    if (selectedServerId && filialId) {
      resetDomains();
      createAccountForm.setFieldValue("Domain", "");
      getDomains({
        ServerId: Number(selectedServerId),
        CustomerId: filialId
      });
    }
  }, [createAccountForm.values.EmailServer, filialId]);
  reactExports.useEffect(() => {
    const selectedServerId_0 = createAccountForm.values.EmailServer;
    if (selectedServerId_0 && integrationType !== EmailServerIntegrationType.None) {
      getPasswordRules({
        serverId: Number(selectedServerId_0)
      });
    }
  }, [createAccountForm.values.EmailServer, integrationType]);
  reactExports.useEffect(() => {
    if (createAccountForm.values.Password) {
      createAccountForm.validateField("Password");
    }
  }, [activeRules]);
  reactExports.useEffect(() => {
    var _a;
    if (serverDomains !== void 0) {
      if (serverDomains && serverDomains.length > 0) {
        const firstDomain = (_a = serverDomains[0]) == null ? void 0 : _a.Domain;
        if (firstDomain) {
          createAccountForm.setFieldValue("Domain", firstDomain);
        }
      } else {
        createAccountForm.setFieldValue("Domain", NO_DOMAIN_VALUE);
      }
    }
  }, [serverDomains]);
  const modalClose = () => {
    createAccountForm.reset();
    handleClose();
  };
  const getCurrentError = (code) => {
    switch (code) {
      case 54001:
        return t("requestsErrors.notConfiguredCustomersEmail");
      case 54002:
        return t("requestsErrors.notSendEmail");
      case 54003:
        return t("requestsErrors.dontHaveEmail");
      case 54004:
        return t("requestsErrors.emailAlreadyActivated");
      case 54005:
        return t("requestsErrors.emailNotActivated");
      case 54006:
        return t("requestsErrors.inputEmptyEmail");
      case 54007:
        return t("requestsErrors.notExistsMxRecords");
      case 54008:
        return t("requestsErrors.cantCreateDomain");
      case 54009:
        return t("requestsErrors.notFoundEmailServer");
      case 54010:
        return t("requestsErrors.emailAlreadyLinked");
      case 54011:
        return t("requestsErrors.emailIsNotExists");
      case 54012:
        return t("requestsErrors.notFoundImapFolder");
      case 54013:
        return t("requestsErrors.cantCreateEmail");
      case 54014:
        return t("requestsErrors.cantLinkEmail");
      case 54015:
        return t("requestsErrors.emailExists");
      case 54016:
        return t("requestsErrors.invalidEmail");
      case 54017:
        return t("requestsErrors.emailServerError");
      case 54018:
        return t("requestsErrors.additionalEmailEqualsEmail");
      case 54019:
        return t("requestsErrors.invalidPassword");
      case 54020:
        return t("notifications.errors.integrationNotConfigured");
      case 54021:
        return t("requestsErrors.emailExists");
      default:
        return void 0;
    }
  };
  const handleCreate = async () => {
    var _a, _b, _c;
    createAccountForm.validate();
    if (!createAccountForm.isValid()) return;
    const {
      Email,
      Domain,
      Password,
      EmailServer,
      Login
    } = createAccountForm.values;
    try {
      const {
        data: data_2,
        error,
        isError,
        isSuccess
      } = await createEmail({
        Login,
        Password,
        Email: `${Email.toLowerCase()}@${Domain}`,
        EmailServer: {
          Id: Number(EmailServer)
        }
      });
      const errorTitle = isError ? getCurrentError((_a = error.data) == null ? void 0 : _a.Code) : void 0;
      universalNotification({
        error,
        isError,
        isSuccess,
        errorTitle,
        successTitle: t("notifications.success.createdMailAccount")
      });
      if (error) {
        return;
      }
      if (handleAddEmail && data_2) {
        handleAddEmail({
          Login: data_2.Login,
          Id: data_2 == null ? void 0 : data_2.Id,
          Password,
          UserId: data_2 == null ? void 0 : data_2.UserId,
          Email: data_2 == null ? void 0 : data_2.Email,
          EmailServer: {
            Id: ((_b = data_2 == null ? void 0 : data_2.EmailServer) == null ? void 0 : _b.Id) || 0,
            Name: (_c = data_2 == null ? void 0 : data_2.EmailServer) == null ? void 0 : _c.Name,
            IntegrationType: EmailServerIntegrationType.None
          }
        });
      }
      if (isSuccess) {
        modalClose();
      }
    } catch {
    }
  };
  const handleChange = (event) => {
    const {
      value
    } = event.currentTarget;
    if (!value.includes("@")) {
      createAccountForm.setFieldValue("Email", value);
    }
  };
  return /* @__PURE__ */ jsxRuntimeExports.jsx(Modal, { size: "450px", opened, onClose: modalClose, title: t("profile.createAccount"), zIndex: 1300, children: /* @__PURE__ */ jsxRuntimeExports.jsxs(Box, { className: classes.modalRoot, children: [
    (emailServerList == null ? void 0 : emailServerList.length) ? /* @__PURE__ */ jsxRuntimeExports.jsxs("form", { className: classes.modalRoot, children: [
      /* @__PURE__ */ jsxRuntimeExports.jsxs(Flex, { gap: "8px", direction: "column", className: classes.modalContainer, children: [
        /* @__PURE__ */ jsxRuntimeExports.jsx(Flex, { w: "100%", children: /* @__PURE__ */ jsxRuntimeExports.jsx(Select, { comboboxProps: {
          zIndex: 1300
        }, w: "100%", label: t("profile.emailServer") || "Email Server", placeholder: t("profile.selectEmailServer") || "Select email server", data: emailServerList, withAsterisk: true, ...createAccountForm.getInputProps("EmailServer") }) }),
        /* @__PURE__ */ jsxRuntimeExports.jsx(Flex, { w: "100%", children: /* @__PURE__ */ jsxRuntimeExports.jsx(TextInput, { w: "100%", label: t("profile.login") || "Login", className: classes.textFieldInput, placeholder: t("validation.enterLogin") || "Enter login", withAsterisk: true, ...createAccountForm.getInputProps("Login") }) }),
        /* @__PURE__ */ jsxRuntimeExports.jsxs(Flex, { w: "100%", align: "start", children: [
          /* @__PURE__ */ jsxRuntimeExports.jsx(TextInput, { w: "100%", label: t("profile.email") || "E-mail", className: classes.textFieldInput, placeholder: t("profile.email"), withAsterisk: true, ...createAccountForm.getInputProps("Email"), onChange: handleChange }),
          /* @__PURE__ */ jsxRuntimeExports.jsx(Flex, { mr: "xs", ml: "xs", mt: "32px", children: /* @__PURE__ */ jsxRuntimeExports.jsx($c, { size: 22, color: themeColors.brandGray[0] }) }),
          /* @__PURE__ */ jsxRuntimeExports.jsx(Flex, { className: classes.createContainer, children: /* @__PURE__ */ jsxRuntimeExports.jsx(Select, { label: t("profile.domain") || "Domain", data: domainList, w: "100%", rightSectionWidth: domainList.length > 1 ? 25 : 0, comboboxProps: {
            zIndex: 1300
          }, rightSection: domainList.length > 1 ? /* @__PURE__ */ jsxRuntimeExports.jsx(gq, { color: "#98A2B3", size: 18 }) : null, styles: {
            rightSection: {
              pointerEvents: "none"
            }
          }, maxDropdownHeight: 150, allowDeselect: false, "data-cy": "selectDomain", className: domainList.length > 1 ? "" : classes.select, classNames: {
            dropdown: domainList.length > 1 ? "" : classes.dropdown
          }, ...createAccountForm.getInputProps("Domain"), value: createAccountForm.values.Domain, onChange: (value_0) => createAccountForm.setFieldValue("Domain", value_0 || "") }) })
        ] }),
        /* @__PURE__ */ jsxRuntimeExports.jsxs(SimpleGrid, { cols: 1, w: "100%", children: [
          /* @__PURE__ */ jsxRuntimeExports.jsx(PasswordInput, { "data-lpignore": "true", autoComplete: "new-password", className: classes.textFieldInput, placeholder: t("profile.password"), label: t("profile.password"), withAsterisk: true, ...createAccountForm.getInputProps("Password") }),
          createAccountForm.values.EmailServer && /* @__PURE__ */ jsxRuntimeExports.jsx(RulesConditionList, { rules: displayRules, check: password.length > 0 })
        ] })
      ] }),
      /* @__PURE__ */ jsxRuntimeExports.jsxs(Flex, { justify: "space-between", gap: 12, p: "16px 34px", w: "100%", children: [
        /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { size: "sm", variant: "filled", fullWidth: true, disabled: isDisabled, onClick: handleCreate, children: t("create") }),
        /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { fullWidth: true, color: "gray", variant: "outline", onClick: modalClose, children: t("profile.cancel") })
      ] })
    ] }) : /* @__PURE__ */ jsxRuntimeExports.jsx(Box, { className: classes.modalContainer, children: /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { children: t("profile.createMailAccountRequiring") }) }),
    /* @__PURE__ */ jsxRuntimeExports.jsx(LoadingOverlay, { visible: isLoadingServers || isLoadingDomains || createEmailFetching || isLoadingRules, overlayProps: {
      blur: 2
    } })
  ] }) });
};
const LinkEmailsModals = (props) => {
  const $ = compilerRuntimeExports.c(17);
  const {
    opened,
    isOpenedCreateModal,
    filialId,
    editUser,
    isLoading,
    isSuccess,
    closeCreateModal,
    close,
    handleAddEmail
  } = props;
  const visibleCreateEmailModal = isOpenedCreateModal && filialId;
  let t0;
  if ($[0] !== close || $[1] !== editUser || $[2] !== filialId || $[3] !== handleAddEmail || $[4] !== isLoading || $[5] !== isSuccess || $[6] !== opened) {
    t0 = /* @__PURE__ */ jsxRuntimeExports.jsx(LinkEmailModal, { opened, handleClose: close, handleAddEmail, filialId, isLoading, isSuccess, editUser });
    $[0] = close;
    $[1] = editUser;
    $[2] = filialId;
    $[3] = handleAddEmail;
    $[4] = isLoading;
    $[5] = isSuccess;
    $[6] = opened;
    $[7] = t0;
  } else {
    t0 = $[7];
  }
  let t1;
  if ($[8] !== closeCreateModal || $[9] !== filialId || $[10] !== handleAddEmail || $[11] !== isOpenedCreateModal || $[12] !== visibleCreateEmailModal) {
    t1 = visibleCreateEmailModal && /* @__PURE__ */ jsxRuntimeExports.jsx(CreateEmailAccount, { handleClose: closeCreateModal, opened: isOpenedCreateModal, handleAddEmail, filialId });
    $[8] = closeCreateModal;
    $[9] = filialId;
    $[10] = handleAddEmail;
    $[11] = isOpenedCreateModal;
    $[12] = visibleCreateEmailModal;
    $[13] = t1;
  } else {
    t1 = $[13];
  }
  let t2;
  if ($[14] !== t0 || $[15] !== t1) {
    t2 = /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
      t0,
      t1
    ] });
    $[14] = t0;
    $[15] = t1;
    $[16] = t2;
  } else {
    t2 = $[16];
  }
  return t2;
};
const useLinkedEmail = (props) => {
  const $ = compilerRuntimeExports.c(25);
  const {
    listLinkedEmails,
    sectionFormKey,
    form,
    editUser,
    currentId,
    isCreateUserPage
  } = props;
  const [opened, t0] = useDisclosure(false);
  const {
    open,
    close
  } = t0;
  const [isOpenedCreateModal, t1] = useDisclosure(false);
  const {
    open: openCreateModal,
    close: closeCreateModal
  } = t1;
  const currentUser = useAppSelector(_temp$1);
  const {
    saveUpdate,
    isLoading,
    isSuccess
  } = useUpdateInfo();
  let t2;
  if ($[0] !== currentId || $[1] !== editUser || $[2] !== form || $[3] !== listLinkedEmails || $[4] !== saveUpdate || $[5] !== sectionFormKey) {
    t2 = async (email) => {
      form == null ? void 0 : form.insertListItem(`${sectionFormKey}`, {
        ...email
      });
      if (editUser && currentId) {
        await saveUpdate({
          Type: ProfileUpdateTypeEnum.Email,
          Data: {
            [ProfileSectionEnum.LinkedEmail]: [...listLinkedEmails ?? [], email],
            Id: currentId
          }
        });
      }
    };
    $[0] = currentId;
    $[1] = editUser;
    $[2] = form;
    $[3] = listLinkedEmails;
    $[4] = saveUpdate;
    $[5] = sectionFormKey;
    $[6] = t2;
  } else {
    t2 = $[6];
  }
  const handleAddEmail = t2;
  let t3;
  if ($[7] !== currentUser || $[8] !== editUser || $[9] !== isCreateUserPage) {
    t3 = isCreateUserPage || isAdmin(currentUser) && editUser;
    $[7] = currentUser;
    $[8] = editUser;
    $[9] = isCreateUserPage;
    $[10] = t3;
  } else {
    t3 = $[10];
  }
  const visibleCreateButton = t3;
  let t4;
  if ($[11] !== listLinkedEmails) {
    t4 = (listLinkedEmails == null ? void 0 : listLinkedEmails.filter(_temp2$1)) || [];
    $[11] = listLinkedEmails;
    $[12] = t4;
  } else {
    t4 = $[12];
  }
  const listEmails = t4;
  let t5;
  if ($[13] !== close || $[14] !== closeCreateModal || $[15] !== handleAddEmail || $[16] !== isLoading || $[17] !== isOpenedCreateModal || $[18] !== isSuccess || $[19] !== listEmails || $[20] !== open || $[21] !== openCreateModal || $[22] !== opened || $[23] !== visibleCreateButton) {
    t5 = {
      handleAddEmail,
      openCreateModal,
      closeCreateModal,
      open,
      opened,
      close,
      isLoading,
      isSuccess,
      isOpenedCreateModal,
      visibleCreateButton,
      listEmails
    };
    $[13] = close;
    $[14] = closeCreateModal;
    $[15] = handleAddEmail;
    $[16] = isLoading;
    $[17] = isOpenedCreateModal;
    $[18] = isSuccess;
    $[19] = listEmails;
    $[20] = open;
    $[21] = openCreateModal;
    $[22] = opened;
    $[23] = visibleCreateButton;
    $[24] = t5;
  } else {
    t5 = $[24];
  }
  return t5;
};
function _temp$1(state) {
  return state.userInfo.User;
}
function _temp2$1(email_0) {
  return email_0.Email;
}
const RenameMail = (t0) => {
  const $ = compilerRuntimeExports.c(72);
  const {
    selectedEmail,
    setIsOpen,
    onSuccess
  } = t0;
  const {
    t
  } = useTranslation();
  const [newLogin, setNewLogin] = reactExports.useState((selectedEmail == null ? void 0 : selectedEmail.Login) || (selectedEmail == null ? void 0 : selectedEmail.Email) || "");
  const [changeEmailLogin, t1] = useLazyChangeEmailLoginQuery();
  const {
    isLoading
  } = t1;
  let t2;
  if ($[0] !== setIsOpen) {
    t2 = () => setIsOpen(false);
    $[0] = setIsOpen;
    $[1] = t2;
  } else {
    t2 = $[1];
  }
  const modalClose = t2;
  let t3;
  if ($[2] !== t) {
    t3 = (login) => {
      if (!login || !login.trim()) {
        return t("validation.emptyInput");
      }
      if (/\s/.test(login)) {
        return t("validation.loginWithoutSpaces");
      }
      if (login.length < 3) {
        return t("validation.minLengthSymbolsWithCount.symbols_other", {
          count: 3
        });
      }
      if (login.length > 50) {
        return t("validation.maxLengthSymbolsWithCount.symbols_other", {
          count: 50
        });
      }
      return null;
    };
    $[2] = t;
    $[3] = t3;
  } else {
    t3 = $[3];
  }
  const validateLogin = t3;
  let t4;
  if ($[4] !== changeEmailLogin || $[5] !== modalClose || $[6] !== newLogin || $[7] !== onSuccess || $[8] !== selectedEmail || $[9] !== t || $[10] !== validateLogin) {
    t4 = async () => {
      if (!(selectedEmail == null ? void 0 : selectedEmail.IsCanRename)) {
        showNotification({
          title: t("errors.noRights"),
          message: "",
          autoClose: true,
          color: "red",
          style: {
            zIndex: 1003
          }
        });
        return;
      }
      const validationError = validateLogin(newLogin);
      if (validationError) {
        showNotification({
          title: validationError,
          message: "",
          autoClose: true,
          color: "red",
          style: {
            zIndex: 1003
          }
        });
        return;
      }
      if (!(selectedEmail == null ? void 0 : selectedEmail.Id)) {
        showNotification({
          title: t("errors.somethingWentWrong"),
          message: "",
          autoClose: true,
          color: "red",
          style: {
            zIndex: 1003
          }
        });
        return;
      }
      try {
        const result = await changeEmailLogin({
          id: selectedEmail.Id,
          newEmail: newLogin.trim()
        });
        if ("error" in result) {
          showNotification({
            title: t("errors.somethingWentWrong"),
            message: "",
            autoClose: true,
            color: "red",
            style: {
              zIndex: 1003
            }
          });
        } else {
          showNotification({
            title: t("profile.renameEmailSuccess"),
            message: "",
            autoClose: true,
            color: "green",
            style: {
              zIndex: 1003
            }
          });
          if (onSuccess) {
            onSuccess();
          }
          modalClose();
        }
      } catch (t52) {
        const err = t52;
        console.error("Ошибка переименования email", err);
        showNotification({
          title: t("errors.somethingWentWrong"),
          message: "",
          autoClose: true,
          color: "red",
          style: {
            zIndex: 1003
          }
        });
      }
    };
    $[4] = changeEmailLogin;
    $[5] = modalClose;
    $[6] = newLogin;
    $[7] = onSuccess;
    $[8] = selectedEmail;
    $[9] = t;
    $[10] = validateLogin;
    $[11] = t4;
  } else {
    t4 = $[11];
  }
  const handleRenameEmail = t4;
  let t5;
  if ($[12] === Symbol.for("react.memo_cache_sentinel")) {
    t5 = /\s/;
    $[12] = t5;
  } else {
    t5 = $[12];
  }
  let t6;
  if ($[13] !== newLogin) {
    t6 = t5.test(newLogin);
    $[13] = newLogin;
    $[14] = t6;
  } else {
    t6 = $[14];
  }
  const hasSpaces = t6;
  let t7;
  if ($[15] !== newLogin) {
    t7 = newLogin.trim();
    $[15] = newLogin;
    $[16] = t7;
  } else {
    t7 = $[16];
  }
  const isTooShort = t7.length < 3;
  let t8;
  if ($[17] !== newLogin) {
    t8 = newLogin.trim();
    $[17] = newLogin;
    $[18] = t8;
  } else {
    t8 = $[18];
  }
  const isTooLong = t8.length > 50;
  const hasValidationError = hasSpaces || isTooShort || isTooLong;
  const isMobile = useMediaQuery("(max-width: 768px)");
  const t9 = isMobile ? "100%" : 300;
  let t10;
  if ($[19] !== t) {
    t10 = t("profile.renameEmailTitle");
    $[19] = t;
    $[20] = t10;
  } else {
    t10 = $[20];
  }
  let t11;
  if ($[21] !== t10) {
    t11 = /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { fz: "md", children: t10 });
    $[21] = t10;
    $[22] = t11;
  } else {
    t11 = $[22];
  }
  let t12;
  if ($[23] !== t) {
    t12 = t("profile.renameEmailPlaceholder");
    $[23] = t;
    $[24] = t12;
  } else {
    t12 = $[24];
  }
  let t13;
  if ($[25] !== t) {
    t13 = t("profile.renameEmailLabel");
    $[25] = t;
    $[26] = t13;
  } else {
    t13 = $[26];
  }
  let t14;
  if ($[27] === Symbol.for("react.memo_cache_sentinel")) {
    t14 = (e) => setNewLogin(e.target.value);
    $[27] = t14;
  } else {
    t14 = $[27];
  }
  const t15 = isLoading || !(selectedEmail == null ? void 0 : selectedEmail.IsCanRename);
  let t16;
  if ($[28] !== hasSpaces || $[29] !== isTooLong || $[30] !== isTooShort || $[31] !== t) {
    t16 = hasSpaces ? t("validation.loginWithoutSpaces") : isTooShort ? t("validation.minLengthSymbolsWithCount.symbols_other", {
      count: 3
    }) : isTooLong ? t("validation.maxLengthSymbolsWithCount.symbols_other", {
      count: 50
    }) : void 0;
    $[28] = hasSpaces;
    $[29] = isTooLong;
    $[30] = isTooShort;
    $[31] = t;
    $[32] = t16;
  } else {
    t16 = $[32];
  }
  let t17;
  if ($[33] !== newLogin || $[34] !== t12 || $[35] !== t13 || $[36] !== t15 || $[37] !== t16) {
    t17 = /* @__PURE__ */ jsxRuntimeExports.jsx(TextInput, { placeholder: t12, label: t13, withAsterisk: true, value: newLogin, onChange: t14, disabled: t15, error: t16 });
    $[33] = newLogin;
    $[34] = t12;
    $[35] = t13;
    $[36] = t15;
    $[37] = t16;
    $[38] = t17;
  } else {
    t17 = $[38];
  }
  let t18;
  if ($[39] !== (selectedEmail == null ? void 0 : selectedEmail.IsCanRename) || $[40] !== t) {
    t18 = !(selectedEmail == null ? void 0 : selectedEmail.IsCanRename) && /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { size: "xs", c: "red", children: t("errors.noRights") });
    $[39] = selectedEmail == null ? void 0 : selectedEmail.IsCanRename;
    $[40] = t;
    $[41] = t18;
  } else {
    t18 = $[41];
  }
  let t19;
  if ($[42] !== hasValidationError || $[43] !== isLoading || $[44] !== newLogin || $[45] !== (selectedEmail == null ? void 0 : selectedEmail.IsCanRename)) {
    t19 = !newLogin.trim() || isLoading || hasValidationError || !(selectedEmail == null ? void 0 : selectedEmail.IsCanRename);
    $[42] = hasValidationError;
    $[43] = isLoading;
    $[44] = newLogin;
    $[45] = selectedEmail == null ? void 0 : selectedEmail.IsCanRename;
    $[46] = t19;
  } else {
    t19 = $[46];
  }
  let t20;
  if ($[47] !== t) {
    t20 = t("save");
    $[47] = t;
    $[48] = t20;
  } else {
    t20 = $[48];
  }
  let t21;
  if ($[49] !== handleRenameEmail || $[50] !== t19 || $[51] !== t20) {
    t21 = /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { fullWidth: true, variant: "filled", onClick: handleRenameEmail, disabled: t19, children: t20 });
    $[49] = handleRenameEmail;
    $[50] = t19;
    $[51] = t20;
    $[52] = t21;
  } else {
    t21 = $[52];
  }
  let t22;
  if ($[53] !== t) {
    t22 = t("profile.cancel");
    $[53] = t;
    $[54] = t22;
  } else {
    t22 = $[54];
  }
  let t23;
  if ($[55] !== isLoading || $[56] !== modalClose || $[57] !== t22) {
    t23 = /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { fullWidth: true, color: "gray", variant: "outline", onClick: modalClose, disabled: isLoading, children: t22 });
    $[55] = isLoading;
    $[56] = modalClose;
    $[57] = t22;
    $[58] = t23;
  } else {
    t23 = $[58];
  }
  let t24;
  if ($[59] !== t21 || $[60] !== t23) {
    t24 = /* @__PURE__ */ jsxRuntimeExports.jsxs(Flex, { justify: "space-between", gap: 12, children: [
      t21,
      t23
    ] });
    $[59] = t21;
    $[60] = t23;
    $[61] = t24;
  } else {
    t24 = $[61];
  }
  let t25;
  if ($[62] === Symbol.for("react.memo_cache_sentinel")) {
    t25 = {
      blur: 2
    };
    $[62] = t25;
  } else {
    t25 = $[62];
  }
  let t26;
  if ($[63] !== isLoading) {
    t26 = /* @__PURE__ */ jsxRuntimeExports.jsx(LoadingOverlay, { visible: isLoading, overlayProps: t25 });
    $[63] = isLoading;
    $[64] = t26;
  } else {
    t26 = $[64];
  }
  let t27;
  if ($[65] !== t11 || $[66] !== t17 || $[67] !== t18 || $[68] !== t24 || $[69] !== t26 || $[70] !== t9) {
    t27 = /* @__PURE__ */ jsxRuntimeExports.jsxs(Flex, { direction: "column", gap: 12, p: 12, w: t9, pos: "relative", children: [
      t11,
      t17,
      t18,
      t24,
      t26
    ] });
    $[65] = t11;
    $[66] = t17;
    $[67] = t18;
    $[68] = t24;
    $[69] = t26;
    $[70] = t9;
    $[71] = t27;
  } else {
    t27 = $[71];
  }
  return t27;
};
const ChangePasswordModal = (props) => {
  var _a;
  const {
    selectedEmail,
    setIsOpen,
    onSuccess
  } = props;
  const {
    t
  } = useTranslation();
  const {
    classes
  } = useStyles();
  const [changeEmailPassword, {
    isFetching,
    isError
  }] = useLazyChangePasswordLinkedUserEmailQuery();
  const [getPasswordRules, {
    data: passwordRulesData
  }] = useLazyGetPasswordRulesQuery();
  const emailServerIntegrationType = reactExports.useMemo(() => {
    var _a2, _b, _c;
    const server = selectedEmail == null ? void 0 : selectedEmail.EmailServer;
    if (!server) return EmailServerIntegrationType$1.None;
    if (server.IntegrationType === EmailServerIntegrationType$1.Ssh) return EmailServerIntegrationType$1.Ssh;
    if (server.IntegrationType === EmailServerIntegrationType$1.Api) return EmailServerIntegrationType$1.Api;
    const t_0 = (_a2 = server.Integration) == null ? void 0 : _a2.Type;
    if (t_0 === EmailServerIntegrationType$1.Ssh) return EmailServerIntegrationType$1.Ssh;
    if (t_0 === EmailServerIntegrationType$1.Api) return EmailServerIntegrationType$1.Api;
    if ((_b = server.Integration) == null ? void 0 : _b.Ssh) return EmailServerIntegrationType$1.Ssh;
    if ((_c = server.Integration) == null ? void 0 : _c.Api) return EmailServerIntegrationType$1.Api;
    return EmailServerIntegrationType$1.None;
  }, [selectedEmail == null ? void 0 : selectedEmail.EmailServer]);
  reactExports.useEffect(() => {
    var _a2;
    const serverId = (_a2 = selectedEmail == null ? void 0 : selectedEmail.EmailServer) == null ? void 0 : _a2.Id;
    if (serverId && (emailServerIntegrationType === EmailServerIntegrationType$1.Ssh || emailServerIntegrationType === EmailServerIntegrationType$1.Api)) {
      getPasswordRules({
        serverId
      });
    }
  }, [(_a = selectedEmail == null ? void 0 : selectedEmail.EmailServer) == null ? void 0 : _a.Id, emailServerIntegrationType]);
  const activeRules = reactExports.useMemo(() => {
    if (!passwordRulesData) return null;
    if (emailServerIntegrationType === EmailServerIntegrationType$1.Ssh) return passwordRulesData.SshRules;
    if (emailServerIntegrationType === EmailServerIntegrationType$1.Api) return passwordRulesData.ApiRules;
    return null;
  }, [passwordRulesData, emailServerIntegrationType]);
  const modalClose = () => {
    passwordsForm.reset();
    setIsOpen(false);
  };
  const fallbackPasswordSchema = usePasswordSchema(defaultMailServerPasswordOptions, t);
  const serverPasswordSchema = useMailServerPasswordSchema(activeRules, t);
  const passwordRulesZ = activeRules ? serverPasswordSchema : fallbackPasswordSchema;
  const passwordsFormSchema = objectType({
    Password: stringType().min(1, {
      message: t("profile.addOldPassword")
    }),
    NewPassword: passwordRulesZ
  });
  const passwordsForm = useForm({
    initialValues: {
      Password: "",
      NewPassword: ""
    },
    validateInputOnChange: true,
    validate: (values) => getValidateErrors(passwordsFormSchema, values)
  });
  const handleChangePasswords = async () => {
    var _a2;
    const {
      Password,
      NewPassword
    } = passwordsForm.values;
    try {
      const res = await changeEmailPassword({
        EmailId: (selectedEmail == null ? void 0 : selectedEmail.Id) || 0,
        Password,
        NewPassword
      });
      if ("error" in res) {
        const codeError = extractErrorCode(res.error);
        const nativeErrorCode = (_a2 = res == null ? void 0 : res.error) == null ? void 0 : _a2.data.ErrorCode;
        showNotification({
          title: nativeErrorCode === 406 || codeError === ErrorsEnum.InvalidLoginOrPassword ? t("incorrectOldEmailPassword") : "",
          message: "",
          autoClose: true,
          color: "red",
          style: {
            zIndex: 1003
          }
        });
      } else {
        showNotification({
          title: t("profile.updatePasswordSuccessMessage"),
          message: "",
          autoClose: true,
          color: "green",
          style: {
            zIndex: 1003
          }
        });
        if (onSuccess) {
          onSuccess();
        }
        modalClose();
      }
    } catch (err) {
      console.warn("Ошибка смены пароля", err);
    }
  };
  const newPassword = passwordsForm.values.NewPassword;
  const defaultDisplayRules = useGenerateRules(newPassword, defaultMailServerPasswordOptions);
  const serverDisplayRules = useGenerateMailServerRules(newPassword, activeRules);
  const displayRules = activeRules ? serverDisplayRules : defaultDisplayRules;
  const isMobile = useMediaQuery("(max-width: 768px)");
  return /* @__PURE__ */ jsxRuntimeExports.jsxs(Flex, { w: isMobile ? "100%" : 400, p: 12, direction: "column", gap: 12, children: [
    /* @__PURE__ */ jsxRuntimeExports.jsxs(Box, { className: classes.modalContainer, children: [
      /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { children: t("profile.passwordChangeWarning") }),
      /* @__PURE__ */ jsxRuntimeExports.jsxs(SimpleGrid, { cols: 1, mt: 16, w: "100%", children: [
        /* @__PURE__ */ jsxRuntimeExports.jsx(PasswordInput, { placeholder: t("profile.password"), label: t("profile.oldPassword"), withAsterisk: true, ...passwordsForm.getInputProps("Password") }),
        /* @__PURE__ */ jsxRuntimeExports.jsx(PasswordInput, { placeholder: t("profile.newPassword"), label: t("profile.newPassword"), withAsterisk: true, ...passwordsForm.getInputProps("NewPassword") }),
        /* @__PURE__ */ jsxRuntimeExports.jsx(RulesConditionList, { rules: displayRules, check: newPassword.length > 0 })
      ] })
    ] }),
    /* @__PURE__ */ jsxRuntimeExports.jsxs(Flex, { justify: "space-between", gap: 12, children: [
      /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { fullWidth: true, disabled: !passwordsForm.isValid() || !selectedEmail, onClick: handleChangePasswords, variant: "filled", children: t("profile.passwordChange") }),
      /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { fullWidth: true, color: "gray", variant: "outline", onClick: modalClose, children: t("profile.cancel") })
    ] }),
    /* @__PURE__ */ jsxRuntimeExports.jsx(LoadingOverlay, { visible: isFetching && !isError, overlayProps: {
      blur: 2
    } })
  ] });
};
const DeleteEmailModal = (t0) => {
  const $ = compilerRuntimeExports.c(35);
  const {
    form,
    selectedEmail,
    sectionFormKey,
    editUser,
    currentId,
    listEmails,
    setIsOpen,
    onSuccess
  } = t0;
  const {
    t
  } = useTranslation();
  const {
    saveUpdate
  } = useUpdateInfo();
  let t1;
  if ($[0] !== setIsOpen) {
    t1 = () => setIsOpen(false);
    $[0] = setIsOpen;
    $[1] = t1;
  } else {
    t1 = $[1];
  }
  const modalClose = t1;
  let t2;
  if ($[2] !== currentId || $[3] !== editUser || $[4] !== form || $[5] !== listEmails || $[6] !== modalClose || $[7] !== onSuccess || $[8] !== saveUpdate || $[9] !== sectionFormKey || $[10] !== (selectedEmail == null ? void 0 : selectedEmail.Id) || $[11] !== t) {
    t2 = async () => {
      if (editUser && currentId) {
        const filteredEmailsList = listEmails == null ? void 0 : listEmails.filter((email) => email.Id !== (selectedEmail == null ? void 0 : selectedEmail.Id));
        await saveUpdate({
          Type: ProfileUpdateTypeEnum.Email,
          Data: {
            [ProfileSectionEnum.LinkedEmail]: filteredEmailsList || [],
            Id: currentId
          }
        });
        if (onSuccess) {
          onSuccess();
        }
        modalClose();
      } else {
        form.setFieldValue(`${sectionFormKey}`, []);
        showNotification({
          title: t("profile.deletedSuccessMessage"),
          message: "",
          autoClose: true,
          color: "green",
          style: {
            zIndex: 1003
          }
        });
        modalClose();
      }
    };
    $[2] = currentId;
    $[3] = editUser;
    $[4] = form;
    $[5] = listEmails;
    $[6] = modalClose;
    $[7] = onSuccess;
    $[8] = saveUpdate;
    $[9] = sectionFormKey;
    $[10] = selectedEmail == null ? void 0 : selectedEmail.Id;
    $[11] = t;
    $[12] = t2;
  } else {
    t2 = $[12];
  }
  const handleDeleteEmail = t2;
  const isMobile = useMediaQuery("(max-width: 768px)");
  const t3 = isMobile ? "100%" : 300;
  let t4;
  if ($[13] !== t) {
    t4 = t("profile.areYouSureToDelete");
    $[13] = t;
    $[14] = t4;
  } else {
    t4 = $[14];
  }
  const t5 = selectedEmail == null ? void 0 : selectedEmail.Email;
  let t6;
  if ($[15] !== t4 || $[16] !== t5) {
    t6 = /* @__PURE__ */ jsxRuntimeExports.jsxs(Text, { mb: "1rem", fz: "md", children: [
      t4,
      " ",
      t5,
      " ?"
    ] });
    $[15] = t4;
    $[16] = t5;
    $[17] = t6;
  } else {
    t6 = $[17];
  }
  let t7;
  if ($[18] !== t) {
    t7 = t("profile.untie");
    $[18] = t;
    $[19] = t7;
  } else {
    t7 = $[19];
  }
  let t8;
  if ($[20] !== handleDeleteEmail || $[21] !== t7) {
    t8 = /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { fullWidth: true, color: "red", variant: "filled", onClick: handleDeleteEmail, children: t7 });
    $[20] = handleDeleteEmail;
    $[21] = t7;
    $[22] = t8;
  } else {
    t8 = $[22];
  }
  let t9;
  if ($[23] !== t) {
    t9 = t("profile.cancel");
    $[23] = t;
    $[24] = t9;
  } else {
    t9 = $[24];
  }
  let t10;
  if ($[25] !== modalClose || $[26] !== t9) {
    t10 = /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { fullWidth: true, color: "gray", variant: "outline", onClick: modalClose, children: t9 });
    $[25] = modalClose;
    $[26] = t9;
    $[27] = t10;
  } else {
    t10 = $[27];
  }
  let t11;
  if ($[28] !== t10 || $[29] !== t8) {
    t11 = /* @__PURE__ */ jsxRuntimeExports.jsxs(Flex, { justify: "space-between", gap: 12, children: [
      t8,
      t10
    ] });
    $[28] = t10;
    $[29] = t8;
    $[30] = t11;
  } else {
    t11 = $[30];
  }
  let t12;
  if ($[31] !== t11 || $[32] !== t3 || $[33] !== t6) {
    t12 = /* @__PURE__ */ jsxRuntimeExports.jsxs(Box, { p: 12, w: t3, children: [
      t6,
      t11
    ] });
    $[31] = t11;
    $[32] = t3;
    $[33] = t6;
    $[34] = t12;
  } else {
    t12 = $[34];
  }
  return t12;
};
class EmailCanonicalNameService {
  async GetCanonicalNames(params) {
    try {
      const {
        data
      } = await axiosInstance.get("v1/EmailCanonicalName", {
        params: {
          emailId: params.emailId
        }
      });
      return data;
    } catch (e) {
      throw new Error(`Unable to get canonical names: ${e}`);
    }
  }
  async AddCanonicalName(params) {
    try {
      await axiosInstance.post("v1/EmailCanonicalName", params);
    } catch (e) {
      throw new Error(`Unable to add canonical name: ${e}`);
    }
  }
  async DeleteCanonicalName(params) {
    try {
      await axiosInstance.delete("v1/EmailCanonicalName", {
        data: params
      });
    } catch (e) {
      throw new Error(`Unable to delete canonical name: ${e}`);
    }
  }
}
const emailCanonicalNameApiArea = () => new EmailCanonicalNameService();
const CanonicalNames = ({
  selectedEmail,
  setIsOpen,
  onSuccess
}) => {
  const {
    t
  } = useTranslation();
  const isMobile = useMediaQuery("(max-width: 768px)");
  const [canonicalEmails, setCanonicalEmails] = reactExports.useState([]);
  const [pendingDeletions, setPendingDeletions] = reactExports.useState([]);
  const [isAdding, setIsAdding] = reactExports.useState(false);
  const [newName, setNewName] = reactExports.useState("");
  const [newDomain, setNewDomain] = reactExports.useState("team.dsd.md");
  const [isLoading, setIsLoading] = reactExports.useState(false);
  const [isSaving, setIsSaving] = reactExports.useState(false);
  reactExports.useEffect(() => {
    const loadCanonicalNames = async () => {
      if (!(selectedEmail == null ? void 0 : selectedEmail.Id)) return;
      setIsLoading(true);
      try {
        const emailCanonicalNameService = emailCanonicalNameApiArea();
        const response = await emailCanonicalNameService.GetCanonicalNames({
          emailId: selectedEmail.Id
        });
        const emails = response.Names.map((name, index) => ({
          id: `${index}`,
          fullEmail: name
        }));
        setCanonicalEmails(emails);
      } catch (error) {
        showNotification({
          title: t("errors.loadError"),
          message: String(error),
          autoClose: true,
          color: "red",
          style: {
            zIndex: 1003
          }
        });
      } finally {
        setIsLoading(false);
      }
    };
    loadCanonicalNames();
  }, [selectedEmail == null ? void 0 : selectedEmail.Id, t]);
  const modalClose = () => setIsOpen(false);
  const handleDelete = (id) => {
    const emailToDelete = canonicalEmails.find((email) => email.id === id);
    if (!emailToDelete) return;
    setCanonicalEmails((prev) => prev.filter((email_0) => email_0.id !== id));
    if (!emailToDelete.isPending) {
      setPendingDeletions((prev_0) => [...prev_0, emailToDelete.fullEmail]);
    }
  };
  const handleAddClick = () => {
    setIsAdding(true);
    setNewName("");
    setNewDomain("team.dsd.md");
  };
  const handleConfirmAdd = () => {
    if (!newName.trim() || !newDomain.trim()) {
      showNotification({
        title: t("validation.emptyInput"),
        message: "",
        autoClose: true,
        color: "red",
        style: {
          zIndex: 1003
        }
      });
      return;
    }
    const fullEmail = `${newName.trim()}@${newDomain.trim()}`;
    const newEmail = {
      id: Date.now().toString(),
      fullEmail,
      isPending: true
    };
    setCanonicalEmails([...canonicalEmails, newEmail]);
    setIsAdding(false);
    setNewName("");
    setNewDomain("team.dsd.md");
  };
  const handleCancelAdd = () => {
    setIsAdding(false);
    setNewName("");
    setNewDomain("team.dsd.md");
  };
  const handleSave = async () => {
    if (!(selectedEmail == null ? void 0 : selectedEmail.Id)) return;
    const pendingEmails = canonicalEmails.filter((email_1) => email_1.isPending);
    const hasChanges = pendingEmails.length > 0 || pendingDeletions.length > 0;
    if (!hasChanges) {
      onSuccess == null ? void 0 : onSuccess();
      modalClose();
      return;
    }
    setIsSaving(true);
    try {
      const emailCanonicalNameService_0 = emailCanonicalNameApiArea();
      await Promise.all(pendingDeletions.map((fullEmail_0) => emailCanonicalNameService_0.DeleteCanonicalName({
        EmailId: selectedEmail.Id,
        CanonicalName: fullEmail_0
      })));
      await Promise.all(pendingEmails.map((email_2) => emailCanonicalNameService_0.AddCanonicalName({
        EmailId: selectedEmail.Id,
        CanonicalName: email_2.fullEmail
      })));
      showNotification({
        title: t("success"),
        message: t("profile.canonicalNameAdded"),
        autoClose: true,
        color: "green",
        style: {
          zIndex: 1003
        }
      });
      onSuccess == null ? void 0 : onSuccess();
      modalClose();
    } catch (error_0) {
      showNotification({
        title: t("errors.addError"),
        message: String(error_0),
        autoClose: true,
        color: "red",
        style: {
          zIndex: 1003
        }
      });
    } finally {
      setIsSaving(false);
    }
  };
  return /* @__PURE__ */ jsxRuntimeExports.jsxs(Flex, { direction: "column", gap: 12, p: 12, w: isMobile ? "100%" : 500, pos: "relative", children: [
    /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { fz: "lg", fw: 500, children: t("profile.canonicalNamesTitle") }),
    isLoading ? /* @__PURE__ */ jsxRuntimeExports.jsx(Flex, { justify: "center", align: "center", py: 20, children: /* @__PURE__ */ jsxRuntimeExports.jsx(Loader, { size: "sm" }) }) : /* @__PURE__ */ jsxRuntimeExports.jsx(Flex, { direction: "column", gap: 8, children: canonicalEmails.map((email_3) => /* @__PURE__ */ jsxRuntimeExports.jsxs(Flex, { align: "center", justify: "space-between", p: 8, style: {
      backgroundColor: "#f5f5f5",
      borderRadius: 4
    }, children: [
      /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { size: "sm", children: email_3.fullEmail }),
      /* @__PURE__ */ jsxRuntimeExports.jsx(ActionIcon, { color: "red", variant: "subtle", onClick: () => handleDelete(email_3.id), disabled: isSaving, children: /* @__PURE__ */ jsxRuntimeExports.jsx(IconTrash, { size: 18 }) })
    ] }, email_3.id)) }),
    isAdding ? /* @__PURE__ */ jsxRuntimeExports.jsx(Box, { children: /* @__PURE__ */ jsxRuntimeExports.jsxs(Flex, { gap: 8, align: "flex-start", children: [
      /* @__PURE__ */ jsxRuntimeExports.jsxs(Box, { flex: 1, children: [
        /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { size: "xs", mb: 4, children: t("profile.canonicalNameField") }),
        /* @__PURE__ */ jsxRuntimeExports.jsx(TextInput, { value: newName, onChange: (e) => setNewName(e.target.value), size: "sm" })
      ] }),
      /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { mt: 28, c: "dimmed", children: "@" }),
      /* @__PURE__ */ jsxRuntimeExports.jsxs(Box, { flex: 1, children: [
        /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { size: "xs", mb: 4, children: t("profile.canonicalDomainField") }),
        /* @__PURE__ */ jsxRuntimeExports.jsx(TextInput, { placeholder: "team.dsd.md", value: newDomain, onChange: (e_0) => setNewDomain(e_0.target.value), size: "sm" })
      ] }),
      /* @__PURE__ */ jsxRuntimeExports.jsxs(Flex, { gap: 4, mt: 28, children: [
        /* @__PURE__ */ jsxRuntimeExports.jsx(ActionIcon, { color: "blue", variant: "light", onClick: handleConfirmAdd, size: "sm", disabled: isSaving, children: /* @__PURE__ */ jsxRuntimeExports.jsx(IconCheck, { size: 16 }) }),
        /* @__PURE__ */ jsxRuntimeExports.jsx(ActionIcon, { color: "gray", variant: "light", onClick: handleCancelAdd, size: "sm", disabled: isSaving, children: /* @__PURE__ */ jsxRuntimeExports.jsx(IconX, { size: 16 }) })
      ] })
    ] }) }) : /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { variant: "subtle", color: "blue", leftSection: /* @__PURE__ */ jsxRuntimeExports.jsx(IconPlus, { size: 16 }), onClick: handleAddClick, size: "sm", style: {
      alignSelf: "flex-start"
    }, children: t("profile.addCanonicalName") }),
    /* @__PURE__ */ jsxRuntimeExports.jsx(Divider, { my: 8 }),
    /* @__PURE__ */ jsxRuntimeExports.jsxs(Flex, { justify: "flex-end", gap: 12, children: [
      /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { color: "gray", variant: "subtle", onClick: modalClose, disabled: isSaving, children: t("profile.cancel") }),
      /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { variant: "filled", onClick: handleSave, disabled: isSaving, children: t("save") })
    ] })
  ] });
};
const ActionResetPassTrigger = (props) => {
  const $ = compilerRuntimeExports.c(8);
  const {
    setIsOpen
  } = props;
  const {
    t
  } = useTranslation();
  let t0;
  if ($[0] !== setIsOpen) {
    t0 = () => setIsOpen(true);
    $[0] = setIsOpen;
    $[1] = t0;
  } else {
    t0 = $[1];
  }
  const handleOpen = t0;
  let t1;
  if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
    t1 = /* @__PURE__ */ jsxRuntimeExports.jsx(mEe, {});
    $[2] = t1;
  } else {
    t1 = $[2];
  }
  let t2;
  if ($[3] !== t) {
    t2 = t("profile.changePassword");
    $[3] = t;
    $[4] = t2;
  } else {
    t2 = $[4];
  }
  let t3;
  if ($[5] !== handleOpen || $[6] !== t2) {
    t3 = /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { justify: "flex-start", fullWidth: true, size: "sm", variant: "white", color: "black", fw: "lighter", onClick: handleOpen, leftSection: t1, children: t2 });
    $[5] = handleOpen;
    $[6] = t2;
    $[7] = t3;
  } else {
    t3 = $[7];
  }
  return t3;
};
const ActionRemoveMailTrigger = (props) => {
  const $ = compilerRuntimeExports.c(8);
  const {
    setIsOpen
  } = props;
  const {
    t
  } = useTranslation();
  let t0;
  if ($[0] !== setIsOpen) {
    t0 = () => setIsOpen(true);
    $[0] = setIsOpen;
    $[1] = t0;
  } else {
    t0 = $[1];
  }
  const handleOpen = t0;
  let t1;
  if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
    t1 = /* @__PURE__ */ jsxRuntimeExports.jsx(IconTrash, {});
    $[2] = t1;
  } else {
    t1 = $[2];
  }
  let t2;
  if ($[3] !== t) {
    t2 = t("profile.removeMail");
    $[3] = t;
    $[4] = t2;
  } else {
    t2 = $[4];
  }
  let t3;
  if ($[5] !== handleOpen || $[6] !== t2) {
    t3 = /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { fullWidth: true, justify: "flex-start", size: "sm", variant: "white", fw: "lighter", color: "red", onClick: handleOpen, leftSection: t1, children: t2 });
    $[5] = handleOpen;
    $[6] = t2;
    $[7] = t3;
  } else {
    t3 = $[7];
  }
  return t3;
};
const ActionRenameMailTrigger = (props) => {
  const $ = compilerRuntimeExports.c(8);
  const {
    setIsOpen
  } = props;
  const {
    t
  } = useTranslation();
  let t0;
  if ($[0] !== setIsOpen) {
    t0 = () => setIsOpen(true);
    $[0] = setIsOpen;
    $[1] = t0;
  } else {
    t0 = $[1];
  }
  const handleOpen = t0;
  let t1;
  if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
    t1 = /* @__PURE__ */ jsxRuntimeExports.jsx(CEe, {});
    $[2] = t1;
  } else {
    t1 = $[2];
  }
  let t2;
  if ($[3] !== t) {
    t2 = t("profile.renameMail");
    $[3] = t;
    $[4] = t2;
  } else {
    t2 = $[4];
  }
  let t3;
  if ($[5] !== handleOpen || $[6] !== t2) {
    t3 = /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { fullWidth: true, size: "sm", justify: "flex-start", variant: "white", color: "black", fw: "lighter", onClick: handleOpen, leftSection: t1, children: t2 });
    $[5] = handleOpen;
    $[6] = t2;
    $[7] = t3;
  } else {
    t3 = $[7];
  }
  return t3;
};
const ActionCanonicalNamesTrigger = (props) => {
  const $ = compilerRuntimeExports.c(8);
  const {
    setIsOpen
  } = props;
  const {
    t
  } = useTranslation();
  let t0;
  if ($[0] !== setIsOpen) {
    t0 = () => setIsOpen(true);
    $[0] = setIsOpen;
    $[1] = t0;
  } else {
    t0 = $[1];
  }
  const handleOpen = t0;
  let t1;
  if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
    t1 = /* @__PURE__ */ jsxRuntimeExports.jsx(IconMail, {});
    $[2] = t1;
  } else {
    t1 = $[2];
  }
  let t2;
  if ($[3] !== t) {
    t2 = t("profile.canonicalNames");
    $[3] = t;
    $[4] = t2;
  } else {
    t2 = $[4];
  }
  let t3;
  if ($[5] !== handleOpen || $[6] !== t2) {
    t3 = /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { fullWidth: true, size: "sm", justify: "flex-start", variant: "white", color: "black", fw: "lighter", onClick: handleOpen, leftSection: t1, children: t2 });
    $[5] = handleOpen;
    $[6] = t2;
    $[7] = t3;
  } else {
    t3 = $[7];
  }
  return t3;
};
const EmailActions = (props) => {
  const $ = compilerRuntimeExports.c(23);
  const {
    isVisibleChangeButton,
    currentId,
    form,
    isApi,
    sectionFormKey,
    email,
    listEmails,
    refetchUserInfo
  } = props;
  let t0;
  if ($[0] !== email || $[1] !== refetchUserInfo) {
    t0 = (email == null ? void 0 : email.IsCanRename) && /* @__PURE__ */ jsxRuntimeExports.jsx(PopUpUI, { mobileSize: "100%", desktopPosition: "right-start", trigger: ActionRenameMailTrigger, children: (params) => /* @__PURE__ */ jsxRuntimeExports.jsx(RenameMail, { ...params, selectedEmail: email, onSuccess: refetchUserInfo }) });
    $[0] = email;
    $[1] = refetchUserInfo;
    $[2] = t0;
  } else {
    t0 = $[2];
  }
  let t1;
  if ($[3] !== email || $[4] !== isApi || $[5] !== refetchUserInfo) {
    t1 = isApi && /* @__PURE__ */ jsxRuntimeExports.jsx(PopUpUI, { mobileSize: "100%", triggerWidth: "100%", desktopPosition: "right-start", trigger: ActionCanonicalNamesTrigger, children: (params_0) => /* @__PURE__ */ jsxRuntimeExports.jsx(CanonicalNames, { ...params_0, selectedEmail: email, onSuccess: refetchUserInfo }) });
    $[3] = email;
    $[4] = isApi;
    $[5] = refetchUserInfo;
    $[6] = t1;
  } else {
    t1 = $[6];
  }
  let t2;
  if ($[7] !== email || $[8] !== isVisibleChangeButton || $[9] !== refetchUserInfo) {
    t2 = !isVisibleChangeButton && /* @__PURE__ */ jsxRuntimeExports.jsx(PopUpUI, { mobileSize: "100%", triggerWidth: "100%", desktopPosition: "right-start", trigger: ActionResetPassTrigger, children: (params_1) => /* @__PURE__ */ jsxRuntimeExports.jsx(ChangePasswordModal, { ...params_1, selectedEmail: email, onSuccess: refetchUserInfo }) });
    $[7] = email;
    $[8] = isVisibleChangeButton;
    $[9] = refetchUserInfo;
    $[10] = t2;
  } else {
    t2 = $[10];
  }
  let t3;
  if ($[11] !== currentId || $[12] !== email || $[13] !== form || $[14] !== listEmails || $[15] !== refetchUserInfo || $[16] !== sectionFormKey) {
    t3 = /* @__PURE__ */ jsxRuntimeExports.jsx(PopUpUI, { mobileSize: "100%", triggerWidth: "100%", desktopPosition: "right-start", trigger: ActionRemoveMailTrigger, children: (params_2) => /* @__PURE__ */ jsxRuntimeExports.jsx(DeleteEmailModal, { ...params_2, selectedEmail: email, editUser: true, currentId, form, sectionFormKey, listEmails, onSuccess: refetchUserInfo }) });
    $[11] = currentId;
    $[12] = email;
    $[13] = form;
    $[14] = listEmails;
    $[15] = refetchUserInfo;
    $[16] = sectionFormKey;
    $[17] = t3;
  } else {
    t3 = $[17];
  }
  let t4;
  if ($[18] !== t0 || $[19] !== t1 || $[20] !== t2 || $[21] !== t3) {
    t4 = /* @__PURE__ */ jsxRuntimeExports.jsxs(Flex, { p: 6, gap: 6, direction: "column", align: "stretch", children: [
      t0,
      t1,
      t2,
      t3
    ] });
    $[18] = t0;
    $[19] = t1;
    $[20] = t2;
    $[21] = t3;
    $[22] = t4;
  } else {
    t4 = $[22];
  }
  return t4;
};
const ActionTrigger = (props) => {
  const $ = compilerRuntimeExports.c(5);
  const {
    setIsOpen
  } = props;
  let t0;
  if ($[0] !== setIsOpen) {
    t0 = () => setIsOpen(true);
    $[0] = setIsOpen;
    $[1] = t0;
  } else {
    t0 = $[1];
  }
  const handleOpen = t0;
  let t1;
  if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
    t1 = /* @__PURE__ */ jsxRuntimeExports.jsx(CX, { color: "#667085", "data-action": "action" });
    $[2] = t1;
  } else {
    t1 = $[2];
  }
  let t2;
  if ($[3] !== handleOpen) {
    t2 = /* @__PURE__ */ jsxRuntimeExports.jsx(ActionIcon, { onClick: handleOpen, children: t1 });
    $[3] = handleOpen;
    $[4] = t2;
  } else {
    t2 = $[4];
  }
  return t2;
};
const EmailItem = (props) => {
  const $ = compilerRuntimeExports.c(20);
  const {
    email,
    currentId,
    form,
    sectionFormKey,
    listEmails,
    isApi,
    refetchUserInfo
  } = props;
  const {
    classes
  } = useStyles();
  const isVisibleChangeButton = email.Id === 0 || !email.IsIntegrated;
  let t0;
  if ($[0] !== classes.LDAP || $[1] !== email.IsLdap) {
    t0 = email.IsLdap ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: classes.LDAP, children: "LDAP" }) : null;
    $[0] = classes.LDAP;
    $[1] = email.IsLdap;
    $[2] = t0;
  } else {
    t0 = $[2];
  }
  let t1;
  if ($[3] !== classes.nameMail || $[4] !== email.Email || $[5] !== t0) {
    t1 = /* @__PURE__ */ jsxRuntimeExports.jsx(TextInput, { className: classes.nameMail, readOnly: true, value: email.Email, rightSection: t0 });
    $[3] = classes.nameMail;
    $[4] = email.Email;
    $[5] = t0;
    $[6] = t1;
  } else {
    t1 = $[6];
  }
  let t2;
  if ($[7] !== currentId || $[8] !== email || $[9] !== form || $[10] !== isApi || $[11] !== isVisibleChangeButton || $[12] !== listEmails || $[13] !== refetchUserInfo || $[14] !== sectionFormKey) {
    t2 = /* @__PURE__ */ jsxRuntimeExports.jsx(PopUpUI, { mobileSize: "100%", desktopPosition: "right-start", trigger: ActionTrigger, children: (params) => /* @__PURE__ */ jsxRuntimeExports.jsx(EmailActions, { ...params, currentId, form, email, isApi, sectionFormKey, listEmails, isVisibleChangeButton, refetchUserInfo }) });
    $[7] = currentId;
    $[8] = email;
    $[9] = form;
    $[10] = isApi;
    $[11] = isVisibleChangeButton;
    $[12] = listEmails;
    $[13] = refetchUserInfo;
    $[14] = sectionFormKey;
    $[15] = t2;
  } else {
    t2 = $[15];
  }
  let t3;
  if ($[16] !== classes.listRow || $[17] !== t1 || $[18] !== t2) {
    t3 = /* @__PURE__ */ jsxRuntimeExports.jsxs(Flex, { className: classes.listRow, children: [
      t1,
      t2
    ] });
    $[16] = classes.listRow;
    $[17] = t1;
    $[18] = t2;
    $[19] = t3;
  } else {
    t3 = $[19];
  }
  return t3;
};
const getIntegrationTypeLabel = (type, t) => {
  switch (type) {
    case EmailServerIntegrationType$1.Ssh:
      return t("profile.integrationTypeSsh");
    case EmailServerIntegrationType$1.Api:
      return t("profile.integrationTypeApi");
    default:
      return t("profile.integrationTypeOther");
  }
};
const ServerGroup = (t0) => {
  const $ = compilerRuntimeExports.c(12);
  const {
    servers,
    form,
    sectionFormKey,
    currentId,
    listEmails,
    isApi: t1,
    editUser,
    refetchUserInfo
  } = t0;
  const isApi = t1 === void 0 ? false : t1;
  const {
    t
  } = useTranslation();
  let t2;
  if ($[0] !== currentId || $[1] !== editUser || $[2] !== form || $[3] !== isApi || $[4] !== listEmails || $[5] !== refetchUserInfo || $[6] !== sectionFormKey || $[7] !== servers || $[8] !== t) {
    t2 = servers == null ? void 0 : servers.map((serverGroup) => /* @__PURE__ */ jsxRuntimeExports.jsxs(r.Fragment, { children: [
      /* @__PURE__ */ jsxRuntimeExports.jsxs(Text, { fw: "500", mt: 16, fz: 15, c: "#000", children: [
        getIntegrationTypeLabel(serverGroup.server.IntegrationType, t),
        " ",
        serverGroup.server.Name
      ] }),
      serverGroup.emails.map((email, index) => /* @__PURE__ */ jsxRuntimeExports.jsx(EmailItem, { email, form, isApi, sectionFormKey, currentId, listEmails, editUser, refetchUserInfo }, index))
    ] }, serverGroup.server.Id));
    $[0] = currentId;
    $[1] = editUser;
    $[2] = form;
    $[3] = isApi;
    $[4] = listEmails;
    $[5] = refetchUserInfo;
    $[6] = sectionFormKey;
    $[7] = servers;
    $[8] = t;
    $[9] = t2;
  } else {
    t2 = $[9];
  }
  let t3;
  if ($[10] !== t2) {
    t3 = /* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: t2 });
    $[10] = t2;
    $[11] = t3;
  } else {
    t3 = $[11];
  }
  return t3;
};
const LinkedListEmails = (props) => {
  const $ = compilerRuntimeExports.c(77);
  const {
    t
  } = useTranslation();
  const {
    classes
  } = useStyles();
  const {
    form,
    sectionFormKey,
    filialId,
    currentId,
    editUser,
    refetchUserInfo
  } = props;
  const {
    opened,
    isLoading,
    isSuccess,
    isOpenedCreateModal,
    visibleCreateButton,
    listEmails,
    handleAddEmail,
    openCreateModal,
    closeCreateModal,
    open,
    close
  } = useLinkedEmail(props);
  let t0;
  if ($[0] !== listEmails) {
    const uniqueServers = Array.from(new Map(listEmails.map(_temp).filter(_temp2).map(_temp3)).values());
    t0 = uniqueServers.reduce((acc, server) => {
      let type = "other";
      if (server.IntegrationType === EmailServerIntegrationType$1.Ssh) {
        type = "ssh";
      } else {
        if (server.IntegrationType === EmailServerIntegrationType$1.Api) {
          type = "api";
        }
      }
      const emails = listEmails.filter((email) => {
        var _a;
        return ((_a = email.EmailServer) == null ? void 0 : _a.Id) === server.Id;
      });
      if (!acc[type]) {
        acc[type] = [];
      }
      acc[type].push({
        server,
        emails
      });
      return acc;
    }, {});
    $[0] = listEmails;
    $[1] = t0;
  } else {
    t0 = $[1];
  }
  const groupedServers = t0;
  let t1;
  if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
    t1 = {
      base: 1,
      xs: 2
    };
    $[2] = t1;
  } else {
    t1 = $[2];
  }
  const t2 = classes.addBtn;
  let t3;
  if ($[3] !== t) {
    t3 = t("profile.linkAccount");
    $[3] = t;
    $[4] = t3;
  } else {
    t3 = $[4];
  }
  let t4;
  if ($[5] !== classes.addBtn || $[6] !== open || $[7] !== t3) {
    t4 = /* @__PURE__ */ jsxRuntimeExports.jsx(SimpleGrid, { cols: t1, w: "100%", children: /* @__PURE__ */ jsxRuntimeExports.jsx(AddButton, { className: t2, fw: "lighter", onClick: open, children: t3 }) });
    $[5] = classes.addBtn;
    $[6] = open;
    $[7] = t3;
    $[8] = t4;
  } else {
    t4 = $[8];
  }
  let t5;
  if ($[9] !== classes.addBtn || $[10] !== filialId || $[11] !== openCreateModal || $[12] !== t || $[13] !== visibleCreateButton) {
    t5 = visibleCreateButton && /* @__PURE__ */ jsxRuntimeExports.jsx(SimpleGrid, { cols: {
      base: 1,
      xs: 2
    }, mt: 16, w: "100%", children: /* @__PURE__ */ jsxRuntimeExports.jsx(AddButton, { className: classes.addBtn, fw: "lighter", disabled: !filialId, onClick: openCreateModal, children: t("profile.createNewAccount") }) });
    $[9] = classes.addBtn;
    $[10] = filialId;
    $[11] = openCreateModal;
    $[12] = t;
    $[13] = visibleCreateButton;
    $[14] = t5;
  } else {
    t5 = $[14];
  }
  let t6;
  if ($[15] !== t4 || $[16] !== t5) {
    t6 = /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
      t4,
      t5
    ] });
    $[15] = t4;
    $[16] = t5;
    $[17] = t6;
  } else {
    t6 = $[17];
  }
  let t7;
  if ($[18] !== classes.accountName || $[19] !== listEmails.length || $[20] !== t) {
    t7 = listEmails.length !== 0 && /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { className: classes.accountName, fw: "500", mt: 16, fz: 15, c: "#000", children: t("profile.mailServers") });
    $[18] = classes.accountName;
    $[19] = listEmails.length;
    $[20] = t;
    $[21] = t7;
  } else {
    t7 = $[21];
  }
  let t8;
  if ($[22] !== groupedServers.ssh) {
    t8 = groupedServers.ssh || [];
    $[22] = groupedServers.ssh;
    $[23] = t8;
  } else {
    t8 = $[23];
  }
  let t9;
  if ($[24] !== currentId || $[25] !== editUser || $[26] !== form || $[27] !== listEmails || $[28] !== refetchUserInfo || $[29] !== sectionFormKey || $[30] !== t8) {
    t9 = /* @__PURE__ */ jsxRuntimeExports.jsx(ServerGroup, { servers: t8, form, sectionFormKey, currentId, listEmails, editUser, refetchUserInfo });
    $[24] = currentId;
    $[25] = editUser;
    $[26] = form;
    $[27] = listEmails;
    $[28] = refetchUserInfo;
    $[29] = sectionFormKey;
    $[30] = t8;
    $[31] = t9;
  } else {
    t9 = $[31];
  }
  let t10;
  if ($[32] !== groupedServers.api) {
    t10 = groupedServers.api || [];
    $[32] = groupedServers.api;
    $[33] = t10;
  } else {
    t10 = $[33];
  }
  let t11;
  if ($[34] !== currentId || $[35] !== editUser || $[36] !== form || $[37] !== listEmails || $[38] !== refetchUserInfo || $[39] !== sectionFormKey || $[40] !== t10) {
    t11 = /* @__PURE__ */ jsxRuntimeExports.jsx(ServerGroup, { servers: t10, form, sectionFormKey, currentId, isApi: true, listEmails, editUser, refetchUserInfo });
    $[34] = currentId;
    $[35] = editUser;
    $[36] = form;
    $[37] = listEmails;
    $[38] = refetchUserInfo;
    $[39] = sectionFormKey;
    $[40] = t10;
    $[41] = t11;
  } else {
    t11 = $[41];
  }
  let t12;
  if ($[42] !== groupedServers.other) {
    t12 = groupedServers.other || [];
    $[42] = groupedServers.other;
    $[43] = t12;
  } else {
    t12 = $[43];
  }
  let t13;
  if ($[44] !== currentId || $[45] !== editUser || $[46] !== form || $[47] !== listEmails || $[48] !== refetchUserInfo || $[49] !== sectionFormKey || $[50] !== t12) {
    t13 = /* @__PURE__ */ jsxRuntimeExports.jsx(ServerGroup, { servers: t12, form, sectionFormKey, currentId, listEmails, editUser, refetchUserInfo });
    $[44] = currentId;
    $[45] = editUser;
    $[46] = form;
    $[47] = listEmails;
    $[48] = refetchUserInfo;
    $[49] = sectionFormKey;
    $[50] = t12;
    $[51] = t13;
  } else {
    t13 = $[51];
  }
  let t14;
  if ($[52] !== classes.listWrapper || $[53] !== t11 || $[54] !== t13 || $[55] !== t9) {
    t14 = /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: classes.listWrapper, children: [
      t9,
      t11,
      t13
    ] });
    $[52] = classes.listWrapper;
    $[53] = t11;
    $[54] = t13;
    $[55] = t9;
    $[56] = t14;
  } else {
    t14 = $[56];
  }
  let t15;
  if ($[57] !== t) {
    t15 = t("profile.infoDescription");
    $[57] = t;
    $[58] = t15;
  } else {
    t15 = $[58];
  }
  let t16;
  if ($[59] !== t15) {
    t16 = /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { mt: 16, fz: 14, c: "#667085", children: t15 });
    $[59] = t15;
    $[60] = t16;
  } else {
    t16 = $[60];
  }
  let t17;
  if ($[61] !== close || $[62] !== closeCreateModal || $[63] !== editUser || $[64] !== filialId || $[65] !== handleAddEmail || $[66] !== isLoading || $[67] !== isOpenedCreateModal || $[68] !== isSuccess || $[69] !== opened) {
    t17 = /* @__PURE__ */ jsxRuntimeExports.jsx(LinkEmailsModals, { isOpenedCreateModal, filialId, editUser, isLoading, isSuccess, close, opened, closeCreateModal, handleAddEmail });
    $[61] = close;
    $[62] = closeCreateModal;
    $[63] = editUser;
    $[64] = filialId;
    $[65] = handleAddEmail;
    $[66] = isLoading;
    $[67] = isOpenedCreateModal;
    $[68] = isSuccess;
    $[69] = opened;
    $[70] = t17;
  } else {
    t17 = $[70];
  }
  let t18;
  if ($[71] !== t14 || $[72] !== t16 || $[73] !== t17 || $[74] !== t6 || $[75] !== t7) {
    t18 = /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
      t6,
      t7,
      t14,
      t16,
      t17
    ] });
    $[71] = t14;
    $[72] = t16;
    $[73] = t17;
    $[74] = t6;
    $[75] = t7;
    $[76] = t18;
  } else {
    t18 = $[76];
  }
  return t18;
};
function _temp(listEmail) {
  return listEmail.EmailServer;
}
function _temp2(emailServer) {
  return emailServer !== null;
}
function _temp3(emailServer_0) {
  return [emailServer_0.Id, emailServer_0];
}
const MailAccount = () => {
  const $ = compilerRuntimeExports.c(17);
  const {
    t
  } = useTranslation();
  const {
    userInfoCommon,
    currentId,
    refetchUserInfo
  } = reactExports.useContext(EditUserInfoContext);
  const {
    LinkedEmail,
    Customer
  } = userInfoCommon;
  let t0;
  if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
    t0 = {
      initialValues: []
    };
    $[0] = t0;
  } else {
    t0 = $[0];
  }
  const mailForm = useForm(t0);
  let t1;
  if ($[1] !== LinkedEmail || $[2] !== mailForm) {
    t1 = () => {
      mailForm.setValues(LinkedEmail);
      mailForm.resetDirty(LinkedEmail);
    };
    $[1] = LinkedEmail;
    $[2] = mailForm;
    $[3] = t1;
  } else {
    t1 = $[3];
  }
  let t2;
  if ($[4] !== LinkedEmail) {
    t2 = [LinkedEmail];
    $[4] = LinkedEmail;
    $[5] = t2;
  } else {
    t2 = $[5];
  }
  reactExports.useEffect(t1, t2);
  let t3;
  if ($[6] !== t) {
    t3 = t("profile.mailModuleAccount");
    $[6] = t;
    $[7] = t3;
  } else {
    t3 = $[7];
  }
  const t4 = Customer == null ? void 0 : Customer.Id;
  let t5;
  if ($[8] !== LinkedEmail || $[9] !== currentId || $[10] !== mailForm || $[11] !== refetchUserInfo || $[12] !== t4) {
    t5 = /* @__PURE__ */ jsxRuntimeExports.jsx(LinkedListEmails, { listLinkedEmails: LinkedEmail, form: mailForm, sectionFormKey: "LinkedEmail", currentId, filialId: t4, editUser: true, refetchUserInfo });
    $[8] = LinkedEmail;
    $[9] = currentId;
    $[10] = mailForm;
    $[11] = refetchUserInfo;
    $[12] = t4;
    $[13] = t5;
  } else {
    t5 = $[13];
  }
  let t6;
  if ($[14] !== t3 || $[15] !== t5) {
    t6 = /* @__PURE__ */ jsxRuntimeExports.jsx(SectionTemplate, { title: t3, children: t5 });
    $[14] = t3;
    $[15] = t5;
    $[16] = t6;
  } else {
    t6 = $[16];
  }
  return t6;
};
export {
  MailAccount as default
};
//# sourceMappingURL=index-Cg5pRT9x.js.map
