import { E as compilerRuntimeExports, a as r, j as jsxRuntimeExports, r as reactExports } from "./vendor-react-DYNCg6N5.js";
import { M as Modal } from "./index-DqcA8P_y.js";
import { u as useStyles } from "./styles-rKP3r-bS.js";
import { E as EmailServerIntegrationType, a as TEMPLATE_API_AUTH20, T as TEMPLATE_MAIL_SERVER } from "./types-DVpDEwlm.js";
import { u as useTranslation } from "./vendor-i18n-wisIXUFi.js";
import { W as useMediaQuery, E as TextInput, ad as NumberInput, af as Switch, ai as Textarea, F as Flex, a0 as SimpleGrid, d as Checkbox, J as PasswordInput, B as Button, s as showNotification, z as useForm, a4 as Select, b as Box, R as Radio, l as ScrollArea, U as UnstyledButton, V as LoadingOverlay } from "./vendor-mantine-h0WlM2Mj.js";
import { aU as axiosInstance } from "./index-DfebxkL9.js";
import { e as emailServerConnectionType, C as ConnectionTypeOptions, A as AuthTypeSelectOptions } from "./utiils-DzEu0_6s.js";
import { n as numberType, s as stringType, o as objectType, e as nativeEnumType, c as anyType, l as literalType, a as arrayType, b as booleanType, Z as ZodIssueCode } from "./types-espwwxTQ.js";
import { g as getValidateErrors } from "./validation-Ds00Zghx.js";
import { b as gq } from "./vendor-icons-xWhXK_Ui.js";
const SshForm = (props) => {
  var _a, _b, _c, _d, _e, _f, _g, _h;
  const $ = compilerRuntimeExports.c(55);
  const {
    form
  } = props;
  const [showKey, setShowKey] = r.useState(!((_b = (_a = form.values.Integration) == null ? void 0 : _a.Ssh) == null ? void 0 : _b.HasKey));
  const {
    t
  } = useTranslation();
  const {
    classes
  } = useStyles();
  const isMobile = useMediaQuery("(max-width: 992px)");
  let t0;
  if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
    t0 = () => setShowKey(_temp$4);
    $[0] = t0;
  } else {
    t0 = $[0];
  }
  const toggleShowKey = t0;
  const t1 = isMobile ? 1 : 2;
  const t2 = classes.textFieldInput;
  let t3;
  if ($[1] !== t) {
    t3 = t("servers.server");
    $[1] = t;
    $[2] = t3;
  } else {
    t3 = $[2];
  }
  let t4;
  if ($[3] !== t) {
    t4 = t("servers.server");
    $[3] = t;
    $[4] = t4;
  } else {
    t4 = $[4];
  }
  let t5;
  if ($[5] !== form) {
    t5 = form.getInputProps("Integration.Ssh.Server");
    $[5] = form;
    $[6] = t5;
  } else {
    t5 = $[6];
  }
  let t6;
  if ($[7] !== classes.textFieldInput || $[8] !== t3 || $[9] !== t4 || $[10] !== t5) {
    t6 = /* @__PURE__ */ jsxRuntimeExports.jsx(TextInput, { className: t2, placeholder: t3, label: t4, withAsterisk: true, ...t5 });
    $[7] = classes.textFieldInput;
    $[8] = t3;
    $[9] = t4;
    $[10] = t5;
    $[11] = t6;
  } else {
    t6 = $[11];
  }
  const t7 = classes.rightSideContainerTwoItems;
  const t8 = isMobile ? "column" : "row";
  const t9 = classes.textFieldInput;
  const t10 = isMobile ? "auto" : 70;
  let t11;
  if ($[12] !== t) {
    t11 = t("servers.port");
    $[12] = t;
    $[13] = t11;
  } else {
    t11 = $[13];
  }
  let t12;
  if ($[14] !== t) {
    t12 = t("servers.port");
    $[14] = t;
    $[15] = t12;
  } else {
    t12 = $[15];
  }
  const t13 = isMobile ? "20px" : "";
  let t14;
  if ($[16] !== form) {
    t14 = form.getInputProps("Integration.Ssh.Port");
    $[16] = form;
    $[17] = t14;
  } else {
    t14 = $[17];
  }
  let t15;
  if ($[18] !== classes.textFieldInput || $[19] !== t10 || $[20] !== t11 || $[21] !== t12 || $[22] !== t13 || $[23] !== t14) {
    t15 = /* @__PURE__ */ jsxRuntimeExports.jsx(NumberInput, { className: t9, autoComplete: "off", maw: t10, placeholder: t11, label: t12, withAsterisk: true, hideControls: true, defaultValue: "", mb: t13, ...t14 });
    $[18] = classes.textFieldInput;
    $[19] = t10;
    $[20] = t11;
    $[21] = t12;
    $[22] = t13;
    $[23] = t14;
    $[24] = t15;
  } else {
    t15 = $[24];
  }
  const t16 = classes.textFieldInput;
  let t17;
  if ($[25] !== form) {
    t17 = form.getInputProps("Integration.Ssh.User");
    $[25] = form;
    $[26] = t17;
  } else {
    t17 = $[26];
  }
  let t18;
  if ($[27] !== classes.textFieldInput || $[28] !== t17) {
    t18 = /* @__PURE__ */ jsxRuntimeExports.jsx(TextInput, { w: "100%", className: t16, placeholder: "Login", label: "Login", withAsterisk: true, ...t17 });
    $[27] = classes.textFieldInput;
    $[28] = t17;
    $[29] = t18;
  } else {
    t18 = $[29];
  }
  let t19;
  if ($[30] !== classes.rightSideContainerTwoItems || $[31] !== t15 || $[32] !== t18 || $[33] !== t8) {
    t19 = /* @__PURE__ */ jsxRuntimeExports.jsxs(Flex, { className: t7, gap: "24px", direction: t8, children: [
      t15,
      t18
    ] });
    $[30] = classes.rightSideContainerTwoItems;
    $[31] = t15;
    $[32] = t18;
    $[33] = t8;
    $[34] = t19;
  } else {
    t19 = $[34];
  }
  let t20;
  if ($[35] !== t1 || $[36] !== t19 || $[37] !== t6) {
    t20 = /* @__PURE__ */ jsxRuntimeExports.jsxs(SimpleGrid, { cols: t1, mt: 16, w: "100%", children: [
      t6,
      t19
    ] });
    $[35] = t1;
    $[36] = t19;
    $[37] = t6;
    $[38] = t20;
  } else {
    t20 = $[38];
  }
  let t21;
  if ($[39] !== ((_d = (_c = form.values.Integration) == null ? void 0 : _c.Ssh) == null ? void 0 : _d.HasKey) || $[40] !== showKey || $[41] !== t) {
    t21 = ((_f = (_e = form.values.Integration) == null ? void 0 : _e.Ssh) == null ? void 0 : _f.HasKey) && /* @__PURE__ */ jsxRuntimeExports.jsx(Switch, { checked: showKey, size: "xs", onChange: toggleShowKey, label: t("servers.changeKey") });
    $[39] = (_h = (_g = form.values.Integration) == null ? void 0 : _g.Ssh) == null ? void 0 : _h.HasKey;
    $[40] = showKey;
    $[41] = t;
    $[42] = t21;
  } else {
    t21 = $[42];
  }
  let t22;
  if ($[43] !== classes.textAreaInput || $[44] !== classes.textFieldInput || $[45] !== form || $[46] !== showKey || $[47] !== t) {
    t22 = showKey && /* @__PURE__ */ jsxRuntimeExports.jsx(Textarea, { withAsterisk: true, className: classes.textFieldInput, classNames: {
      input: classes.textAreaInput
    }, label: t("servers.key"), size: "xs", minRows: 3, ...form.getInputProps("Integration.Ssh.PrivateKeyBase64") });
    $[43] = classes.textAreaInput;
    $[44] = classes.textFieldInput;
    $[45] = form;
    $[46] = showKey;
    $[47] = t;
    $[48] = t22;
  } else {
    t22 = $[48];
  }
  let t23;
  if ($[49] !== t21 || $[50] !== t22) {
    t23 = /* @__PURE__ */ jsxRuntimeExports.jsxs(SimpleGrid, { cols: 1, mt: 16, w: "100%", children: [
      t21,
      t22
    ] });
    $[49] = t21;
    $[50] = t22;
    $[51] = t23;
  } else {
    t23 = $[51];
  }
  let t24;
  if ($[52] !== t20 || $[53] !== t23) {
    t24 = /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
      t20,
      t23
    ] });
    $[52] = t20;
    $[53] = t23;
    $[54] = t24;
  } else {
    t24 = $[54];
  }
  return t24;
};
function _temp$4(prev) {
  return !prev;
}
class EmailServerService {
  PrepareValues(value) {
    var _a, _b, _c, _d, _e;
    if (value.Integration.Type === EmailServerIntegrationType.None) {
      return {
        ...value,
        Integration: {
          ...value.Integration,
          Ssh: null,
          Api: null
        }
      };
    }
    const preparedApi = ((_a = value.Integration) == null ? void 0 : _a.Api) ? {
      Login: value.Integration.Api.Login,
      Host: value.Integration.Api.Host,
      HasLdapAuth: value.Integration.Api.HasLdapAuth,
      // HasPassword не отправляем - бекенд сам выставит на основе наличия пароля
      // Отправляем пароль только если он заполнен (пользователь решил заменить)
      ...value.Integration.Api.Password && value.Integration.Api.Password.length > 0 ? {
        Password: value.Integration.Api.Password
      } : {},
      ApiAuth20Settings: value.Integration.Api.ApiAuth20Settings ? {
        UrlAuth20: value.Integration.Api.ApiAuth20Settings.UrlAuth20,
        ValidRedirectUris: value.Integration.Api.ApiAuth20Settings.ValidRedirectUris,
        ClientId: value.Integration.Api.ApiAuth20Settings.ClientId,
        Secret: value.Integration.Api.ApiAuth20Settings.Secret
      } : null
    } : null;
    return {
      ...value,
      Integration: {
        ...value.Integration,
        Ssh: ((_b = value.Integration) == null ? void 0 : _b.Ssh) ? {
          ...(_c = value.Integration) == null ? void 0 : _c.Ssh,
          HasKey: ((_e = (_d = value == null ? void 0 : value.Integration) == null ? void 0 : _d.Ssh) == null ? void 0 : _e.PrivateKeyBase64.length) !== 0
        } : null,
        Api: preparedApi
      }
    };
  }
  async GetEmailServer(params) {
    try {
      const {
        data
      } = await axiosInstance.post("v1/EmailServer", params);
      return data;
    } catch (e) {
      throw new Error("Unable to update customer. Please try again later.");
    }
  }
  async EmailServerSave(params) {
    try {
      const {
        data
      } = await axiosInstance.post("v1/EmailServer/Save", params);
      return data;
    } catch (e) {
      throw new Error("Unable to update customer. Please try again later.");
    }
  }
  async EmailServerCheckIntegration(params) {
    try {
      await axiosInstance.post("v1/EmailServer/CheckIntegration", params);
    } catch (e) {
      throw new Error("Unable to update customer. Please try again later.");
    }
  }
}
const emailServerApiArea = () => new EmailServerService();
const ApiForm = (props) => {
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
  const {
    form
  } = props;
  const {
    t
  } = useTranslation();
  const {
    classes
  } = useStyles();
  const isMobile = useMediaQuery("(max-width: 992px)");
  const [connection, setConnection] = r.useState(void 0);
  const [isLoading, setIsLoading] = r.useState(false);
  const oauthSettings = (_b = (_a = form.values.Integration) == null ? void 0 : _a.Api) == null ? void 0 : _b.ApiAuth20Settings;
  const formUris = oauthSettings == null ? void 0 : oauthSettings.ValidRedirectUris;
  const [redirectUrisString, setRedirectUrisString] = reactExports.useState(() => (formUris ?? []).join(", "));
  const [isOAuth2Enabled, setIsOAuth2Enabled] = reactExports.useState(() => {
    var _a2, _b2;
    return !!(((_a2 = oauthSettings == null ? void 0 : oauthSettings.ClientId) == null ? void 0 : _a2.trim()) || ((_b2 = oauthSettings == null ? void 0 : oauthSettings.Secret) == null ? void 0 : _b2.trim()));
  });
  const handleOAuth2Toggle = (e) => {
    const checked = e.currentTarget.checked;
    setIsOAuth2Enabled(checked);
    if (checked) {
      form.setFieldValue("Integration.Api.ApiAuth20Settings", structuredClone(TEMPLATE_API_AUTH20));
    } else {
      form.setFieldValue("Integration.Api.ApiAuth20Settings", null);
      setRedirectUrisString("");
    }
  };
  reactExports.useEffect(() => {
    setRedirectUrisString((formUris ?? []).join(", "));
  }, [JSON.stringify(formUris)]);
  const handleCheckConnection = () => {
    const Integration = form.values.Integration;
    const params = {
      smtp: Integration.Smtp,
      ssh: Integration.Ssh,
      api: Integration.Api,
      type: Integration.Type
    };
    setIsLoading(true);
    emailServerApiArea().EmailServerCheckIntegration(params).then(() => {
      setConnection(true);
      showNotification({
        title: t("servers.api.connect.title"),
        message: t("servers.api.connect.success"),
        autoClose: true,
        color: "green"
      });
    }).catch(() => {
      setConnection(false);
      showNotification({
        title: t("servers.api.connect.title"),
        message: t("servers.api.connect.failed"),
        autoClose: true,
        color: "warning"
      });
    }).finally(() => setIsLoading(false));
  };
  const isDisabled = reactExports.useMemo(() => {
    const {
      Login,
      Password,
      Host
    } = form.values.Integration.Api ?? {};
    if (!Login || !Password || !Host) {
      setConnection(void 0);
      return true;
    }
    return false;
  }, [(_d = (_c = form.values.Integration) == null ? void 0 : _c.Api) == null ? void 0 : _d.Login, (_f = (_e = form.values.Integration) == null ? void 0 : _e.Api) == null ? void 0 : _f.Password, (_h = (_g = form.values.Integration) == null ? void 0 : _g.Api) == null ? void 0 : _h.Host]);
  const color = reactExports.useMemo(() => {
    if (connection === void 0) {
      return "primary";
    }
    return connection ? "green" : "red";
  }, [connection]);
  return /* @__PURE__ */ jsxRuntimeExports.jsxs(SimpleGrid, { cols: 1, mt: 16, w: "100%", children: [
    /* @__PURE__ */ jsxRuntimeExports.jsx(TextInput, { w: "100%", className: classes.textFieldInput, placeholder: t("servers.api.Login"), label: t("servers.api.Login"), withAsterisk: true, ...form.getInputProps("Integration.Api.Login") }),
    /* @__PURE__ */ jsxRuntimeExports.jsx(TextInput, { w: "100%", className: classes.textFieldInput, placeholder: t("servers.api.Password"), label: t("servers.api.Password"), withAsterisk: true, ...form.getInputProps("Integration.Api.Password") }),
    /* @__PURE__ */ jsxRuntimeExports.jsx(TextInput, { w: "100%", className: classes.textFieldInput, placeholder: t("servers.api.Host"), label: t("servers.api.Host"), withAsterisk: true, ...form.getInputProps("Integration.Api.Host") }),
    /* @__PURE__ */ jsxRuntimeExports.jsx(Checkbox, { className: classes.checkbox, label: t("servers.api.HasLdapAuth"), size: "xs", ...form.getInputProps("Integration.Api.HasLdapAuth", {
      type: "checkbox"
    }) }),
    /* @__PURE__ */ jsxRuntimeExports.jsx(Checkbox, { className: classes.checkbox, label: t("servers.api.oauth20.enable"), size: "xs", checked: isOAuth2Enabled, onChange: handleOAuth2Toggle }),
    isOAuth2Enabled && /* @__PURE__ */ jsxRuntimeExports.jsxs(SimpleGrid, { cols: isMobile ? 1 : 2, w: "100%", mt: 8, children: [
      /* @__PURE__ */ jsxRuntimeExports.jsx(TextInput, { className: classes.textFieldInput, label: t("servers.api.oauth20.title"), readOnly: true, value: ((_k = (_j = (_i = form.values.Integration) == null ? void 0 : _i.Api) == null ? void 0 : _j.ApiAuth20Settings) == null ? void 0 : _k.UrlAuth20) ?? "" }),
      /* @__PURE__ */ jsxRuntimeExports.jsx(TextInput, { className: classes.textFieldInput, placeholder: t("servers.api.oauth20.clientId"), label: t("servers.api.oauth20.clientId"), withAsterisk: true, ...form.getInputProps("Integration.Api.ApiAuth20Settings.ClientId") }),
      /* @__PURE__ */ jsxRuntimeExports.jsx(TextInput, { className: classes.textFieldInput, placeholder: t("servers.api.oauth20.redirectUrl"), label: t("servers.api.oauth20.redirectUrl"), value: redirectUrisString, onChange: (e_0) => {
        const raw = e_0.currentTarget.value;
        setRedirectUrisString(raw);
        form.setFieldValue("Integration.Api.ApiAuth20Settings.ValidRedirectUris", raw.split(",").map((s) => s.trim()).filter(Boolean));
      }, error: form.errors["Integration.Api.ApiAuth20Settings.ValidRedirectUris"] || form.errors["Integration.Api.ApiAuth20Settings.ValidRedirectUris.0"] }),
      /* @__PURE__ */ jsxRuntimeExports.jsx(PasswordInput, { className: classes.textFieldInput, placeholder: t("servers.api.oauth20.secretId"), label: t("servers.api.oauth20.secretId"), withAsterisk: true, ...form.getInputProps("Integration.Api.ApiAuth20Settings.Secret") })
    ] }),
    /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { type: "submit", loading: isLoading, color, w: isMobile ? "100%" : "fit-content", disabled: isDisabled, onClick: handleCheckConnection, children: t("servers.api.connect.button") })
  ] });
};
const MailServerIntegration = (props) => {
  var _a, _b;
  const $ = compilerRuntimeExports.c(4);
  const {
    form
  } = props;
  if (!((_a = form == null ? void 0 : form.values) == null ? void 0 : _a.Integration) || ((_b = form == null ? void 0 : form.values) == null ? void 0 : _b.Integration.Type) === EmailServerIntegrationType.None) {
    return;
  }
  if (form.values.Integration.Type === EmailServerIntegrationType.Ssh) {
    let t02;
    if ($[0] !== form) {
      t02 = /* @__PURE__ */ jsxRuntimeExports.jsx(SshForm, { form });
      $[0] = form;
      $[1] = t02;
    } else {
      t02 = $[1];
    }
    return t02;
  }
  let t0;
  if ($[2] !== form) {
    t0 = /* @__PURE__ */ jsxRuntimeExports.jsx(ApiForm, { form });
    $[2] = form;
    $[3] = t0;
  } else {
    t0 = $[3];
  }
  return t0;
};
const useGetMailServerSchemes = (hasKey, t0) => {
  const $ = compilerRuntimeExports.c(16);
  const hasPassword = t0 === void 0 ? false : t0;
  const {
    t
  } = useTranslation();
  let SSHSchema;
  let noSSHSchema;
  let t1;
  if ($[0] !== hasKey || $[1] !== hasPassword || $[2] !== t) {
    const portSchema = numberType({
      required_error: t("filials.authorization.addPort"),
      invalid_type_error: t("filials.authorization.numberPort")
    }).positive({
      message: t("errors.positive")
    }).lt(65536, {
      message: t("errors.maxValue")
    });
    const domainsRequiredSchema = stringType({
      invalid_type_error: t("validation.addDomains")
    }).refine(_temp$3, {
      message: t("validation.emptyInput")
    }).refine(_temp2, {
      message: t("validation.required")
    });
    const domainsOptionalSchema = stringType().optional();
    const basicSchema = objectType({
      Name: stringType().max(120, {
        message: t("validation.maxLengthSymbolsWithCount.symbols", {
          count: 120
        })
      }).refine(_temp3, {
        message: t("validation.emptyInput")
      }).refine(_temp4, {
        message: t("errors.enterName")
      }),
      Domains: domainsRequiredSchema,
      PopServer: stringType().refine(_temp5, {
        message: t("validation.emptyInput")
      }).refine(_temp6, {
        message: t("errors.enterPop")
      }),
      PopPort: portSchema,
      PopConnectionType: nativeEnumType(emailServerConnectionType),
      ImapServer: stringType().refine(_temp7, {
        message: t("validation.emptyInput")
      }).refine(_temp8, {
        message: t("errors.enterImap")
      }),
      ImapPort: portSchema,
      ImapConnectionType: nativeEnumType(emailServerConnectionType),
      SmtpServer: stringType().refine(_temp9, {
        message: t("validation.emptyInput")
      }).refine(_temp0, {
        message: t("errors.enterSmtp")
      }),
      SmtpPort: portSchema,
      SmtpConnectionType: nativeEnumType(emailServerConnectionType),
      Json: stringType().nullable(),
      CustomerId: numberType().nullable().optional()
    });
    noSSHSchema = basicSchema.extend({
      Integration: objectType({
        Type: literalType(EmailServerIntegrationType.None),
        Ssh: anyType().nullable().optional(),
        Api: anyType().nullable().optional(),
        Smtp: anyType().nullable().optional()
      }).nullable()
    });
    let t22;
    if ($[6] !== hasKey) {
      t22 = (val) => {
        if (hasKey && val.length === 0) {
          return true;
        }
        return !(!hasKey && val.length === 0);
      };
      $[6] = hasKey;
      $[7] = t22;
    } else {
      t22 = $[7];
    }
    SSHSchema = basicSchema.extend({
      Integration: objectType({
        Type: literalType(EmailServerIntegrationType.Ssh),
        Ssh: objectType({
          Server: stringType().refine(_temp1, {
            message: t("validation.emptyInput")
          }).refine(_temp10, {
            message: t("servers.addSshServer")
          }),
          User: stringType().refine(_temp11, {
            message: t("validation.emptyInput")
          }).refine(_temp12, {
            message: t("servers.addLogin")
          }),
          Port: portSchema,
          PrivateKeyBase64: stringType().refine(t22, {
            message: t("servers.addKey")
          })
        })
      })
    });
    let t3;
    if ($[8] !== hasPassword) {
      t3 = (val_0) => {
        if (hasPassword && val_0.length === 0) {
          return true;
        }
        return !(!hasPassword && val_0.length === 0);
      };
      $[8] = hasPassword;
      $[9] = t3;
    } else {
      t3 = $[9];
    }
    let t4;
    if ($[10] !== t) {
      t4 = (data, ctx) => {
        var _a, _b;
        const hasClientId = (((_a = data.ClientId) == null ? void 0 : _a.trim().length) ?? 0) > 0;
        const hasSecret = (((_b = data.Secret) == null ? void 0 : _b.trim().length) ?? 0) > 0;
        if (!hasClientId && !hasSecret) {
          return;
        }
        if (!hasClientId) {
          ctx.addIssue({
            code: ZodIssueCode.custom,
            message: t("validation.emptyInput"),
            path: ["ClientId"]
          });
        } else {
          if (!stringType().uuid().safeParse(data.ClientId).success) {
            ctx.addIssue({
              code: ZodIssueCode.custom,
              message: t("validation.invalidUuid"),
              path: ["ClientId"]
            });
          }
        }
        if (!hasSecret) {
          ctx.addIssue({
            code: ZodIssueCode.custom,
            message: t("validation.emptyInput"),
            path: ["Secret"]
          });
        } else {
          if (!stringType().uuid().safeParse(data.Secret).success) {
            ctx.addIssue({
              code: ZodIssueCode.custom,
              message: t("validation.invalidUuid"),
              path: ["Secret"]
            });
          }
        }
      };
      $[10] = t;
      $[11] = t4;
    } else {
      t4 = $[11];
    }
    t1 = basicSchema.omit({
      Domains: true
    }).extend({
      Domains: domainsOptionalSchema,
      Integration: objectType({
        Type: literalType(EmailServerIntegrationType.Api),
        Api: objectType({
          Login: stringType().refine(_temp13, {
            message: t("servers.addLogin")
          }),
          Password: stringType().refine(t3, {
            message: t("servers.addPassword")
          }),
          Host: stringType().refine(_temp14, {
            message: t("servers.addHost")
          }),
          HasLdapAuth: booleanType().optional(),
          ApiAuth20Settings: objectType({
            UrlAuth20: stringType().optional(),
            ValidRedirectUris: arrayType(stringType()).optional().default([]),
            ClientId: stringType().optional().default(""),
            Secret: stringType().optional().default("")
          }).superRefine(t4).nullable()
        })
      })
    });
    $[0] = hasKey;
    $[1] = hasPassword;
    $[2] = t;
    $[3] = SSHSchema;
    $[4] = noSSHSchema;
    $[5] = t1;
  } else {
    SSHSchema = $[3];
    noSSHSchema = $[4];
    t1 = $[5];
  }
  const ApiSchema = t1;
  let t2;
  if ($[12] !== ApiSchema || $[13] !== SSHSchema || $[14] !== noSSHSchema) {
    t2 = {
      noSSHSchema,
      SSHSchema,
      ApiSchema
    };
    $[12] = ApiSchema;
    $[13] = SSHSchema;
    $[14] = noSSHSchema;
    $[15] = t2;
  } else {
    t2 = $[15];
  }
  return t2;
};
function _temp$3(value) {
  return value.trim().length > 0;
}
function _temp2(value_0) {
  return value_0.length > 0;
}
function _temp3(value_1) {
  return value_1.trim().length > 0;
}
function _temp4(value_2) {
  return value_2.length > 0;
}
function _temp5(value_3) {
  return value_3.trim().length > 0;
}
function _temp6(value_4) {
  return value_4.length > 0;
}
function _temp7(value_5) {
  return value_5.trim().length > 0;
}
function _temp8(value_6) {
  return value_6.length > 0;
}
function _temp9(value_7) {
  return value_7.trim().length > 0;
}
function _temp0(value_8) {
  return value_8.length > 0;
}
function _temp1(value_9) {
  return value_9.trim().length > 0;
}
function _temp10(value_10) {
  return value_10.length > 0;
}
function _temp11(value_11) {
  return value_11.trim().length > 0;
}
function _temp12(value_12) {
  return value_12.length > 0;
}
function _temp13(value_13) {
  return value_13.trim().length > 0;
}
function _temp14(value_14) {
  return value_14.trim().length > 0;
}
const useServerModalForm = (params) => {
  var _a, _b, _c, _d;
  const $ = compilerRuntimeExports.c(25);
  const {
    t
  } = useTranslation();
  const {
    mailServer,
    CustomerId,
    handleClose,
    handleChange
  } = params;
  const [isOnIntegration, setIsOnIntegration] = reactExports.useState(!!(mailServer == null ? void 0 : mailServer.Integration));
  const [isFetching, setIsFetching] = reactExports.useState(false);
  const {
    noSSHSchema,
    SSHSchema,
    ApiSchema
  } = useGetMailServerSchemes(!!((_b = (_a = mailServer == null ? void 0 : mailServer.Integration) == null ? void 0 : _a.Ssh) == null ? void 0 : _b.HasKey), !!((_d = (_c = mailServer == null ? void 0 : mailServer.Integration) == null ? void 0 : _c.Api) == null ? void 0 : _d.HasPassword));
  let t0;
  if ($[0] !== mailServer) {
    t0 = structuredClone(mailServer);
    $[0] = mailServer;
    $[1] = t0;
  } else {
    t0 = $[1];
  }
  let t1;
  if ($[2] !== CustomerId || $[3] !== t0) {
    t1 = {
      ...t0,
      CustomerId
    };
    $[2] = CustomerId;
    $[3] = t0;
    $[4] = t1;
  } else {
    t1 = $[4];
  }
  let t2;
  if ($[5] !== ApiSchema || $[6] !== SSHSchema || $[7] !== noSSHSchema) {
    t2 = (values) => {
      var _a2;
      const type = (_a2 = values.Integration) == null ? void 0 : _a2.Type;
      if (type === EmailServerIntegrationType.Api) {
        return getValidateErrors(ApiSchema, values);
      }
      if (type === EmailServerIntegrationType.Ssh) {
        return getValidateErrors(SSHSchema, values);
      }
      return getValidateErrors(noSSHSchema, values);
    };
    $[5] = ApiSchema;
    $[6] = SSHSchema;
    $[7] = noSSHSchema;
    $[8] = t2;
  } else {
    t2 = $[8];
  }
  let t3;
  if ($[9] !== t1 || $[10] !== t2) {
    t3 = {
      initialValues: t1,
      validateInputOnChange: true,
      validate: t2
    };
    $[9] = t1;
    $[10] = t2;
    $[11] = t3;
  } else {
    t3 = $[11];
  }
  const form = useForm(t3);
  let t4;
  if ($[12] !== form || $[13] !== handleClose) {
    t4 = () => {
      handleClose();
      form.reset();
    };
    $[12] = form;
    $[13] = handleClose;
    $[14] = t4;
  } else {
    t4 = $[14];
  }
  const modalClose = t4;
  let t5;
  if ($[15] !== handleChange || $[16] !== handleClose || $[17] !== t) {
    t5 = (values_0) => {
      const preparedValues = emailServerApiArea().PrepareValues(values_0);
      setIsFetching(true);
      emailServerApiArea().EmailServerSave(preparedValues).then(() => {
        showNotification({
          title: t("servers.createSuccess"),
          message: "",
          autoClose: true,
          color: "green",
          style: {
            zIndex: 1003
          }
        });
        handleChange == null ? void 0 : handleChange();
        handleClose();
      }).catch(_temp$2).finally(() => setIsFetching(false));
    };
    $[15] = handleChange;
    $[16] = handleClose;
    $[17] = t;
    $[18] = t5;
  } else {
    t5 = $[18];
  }
  const handleSubmit = t5;
  let t6;
  if ($[19] !== form || $[20] !== handleSubmit || $[21] !== isFetching || $[22] !== isOnIntegration || $[23] !== modalClose) {
    t6 = {
      form,
      isFetching,
      isOnIntegration,
      modalClose,
      handleSubmit,
      setIsOnIntegration
    };
    $[19] = form;
    $[20] = handleSubmit;
    $[21] = isFetching;
    $[22] = isOnIntegration;
    $[23] = modalClose;
    $[24] = t6;
  } else {
    t6 = $[24];
  }
  return t6;
};
function _temp$2(err) {
  var _a;
  showNotification({
    title: `${(_a = err == null ? void 0 : err.error) == null ? void 0 : _a.data}`,
    message: "",
    autoClose: true,
    color: "red",
    style: {
      zIndex: 1003
    }
  });
  throw err;
}
const ConnectionsSelect = (t0) => {
  const $ = compilerRuntimeExports.c(17);
  const {
    label,
    placeholder,
    value,
    form,
    fieldName,
    disabled
  } = t0;
  let t1;
  if ($[0] !== fieldName || $[1] !== form) {
    t1 = (query) => {
      form == null ? void 0 : form.setFieldValue(fieldName, query ? Number(query) : null);
    };
    $[0] = fieldName;
    $[1] = form;
    $[2] = t1;
  } else {
    t1 = $[2];
  }
  const handleChangeConnection = t1;
  let t2;
  if ($[3] === Symbol.for("react.memo_cache_sentinel")) {
    t2 = /* @__PURE__ */ jsxRuntimeExports.jsx(gq, { size: "1rem", color: "#98A2B3" });
    $[3] = t2;
  } else {
    t2 = $[3];
  }
  let t3;
  if ($[4] !== value) {
    t3 = (value == null ? void 0 : value.toString()) || "";
    $[4] = value;
    $[5] = t3;
  } else {
    t3 = $[5];
  }
  let t4;
  if ($[6] !== fieldName || $[7] !== form) {
    t4 = form == null ? void 0 : form.getInputProps(fieldName).error;
    $[6] = fieldName;
    $[7] = form;
    $[8] = t4;
  } else {
    t4 = $[8];
  }
  let t5;
  if ($[9] === Symbol.for("react.memo_cache_sentinel")) {
    t5 = {
      zIndex: 1300
    };
    $[9] = t5;
  } else {
    t5 = $[9];
  }
  let t6;
  if ($[10] !== disabled || $[11] !== handleChangeConnection || $[12] !== label || $[13] !== placeholder || $[14] !== t3 || $[15] !== t4) {
    t6 = /* @__PURE__ */ jsxRuntimeExports.jsx(Select, { data: ConnectionTypeOptions, required: true, allowDeselect: false, disabled, rightSectionWidth: 30, rightSection: t2, label, value: t3, placeholder, onChange: handleChangeConnection, error: t4, w: "100%", comboboxProps: t5, styles: _temp$1 });
    $[10] = disabled;
    $[11] = handleChangeConnection;
    $[12] = label;
    $[13] = placeholder;
    $[14] = t3;
    $[15] = t4;
    $[16] = t6;
  } else {
    t6 = $[16];
  }
  return t6;
};
function _temp$1() {
  return {
    rightSection: {
      pointerEvents: "none"
    }
  };
}
const AuthTypeSelect = (t0) => {
  const $ = compilerRuntimeExports.c(17);
  const {
    label,
    placeholder,
    value,
    form,
    fieldName,
    disabled
  } = t0;
  let t1;
  if ($[0] !== fieldName || $[1] !== form) {
    t1 = (query) => {
      form == null ? void 0 : form.setFieldValue(fieldName, query ? Number(query) : null);
    };
    $[0] = fieldName;
    $[1] = form;
    $[2] = t1;
  } else {
    t1 = $[2];
  }
  const handleChangeConnection = t1;
  let t2;
  if ($[3] === Symbol.for("react.memo_cache_sentinel")) {
    t2 = /* @__PURE__ */ jsxRuntimeExports.jsx(gq, { size: "1rem", color: "#98A2B3" });
    $[3] = t2;
  } else {
    t2 = $[3];
  }
  let t3;
  if ($[4] !== value) {
    t3 = (value == null ? void 0 : value.toString()) || "";
    $[4] = value;
    $[5] = t3;
  } else {
    t3 = $[5];
  }
  let t4;
  if ($[6] !== fieldName || $[7] !== form) {
    t4 = form == null ? void 0 : form.getInputProps(fieldName).error;
    $[6] = fieldName;
    $[7] = form;
    $[8] = t4;
  } else {
    t4 = $[8];
  }
  let t5;
  if ($[9] === Symbol.for("react.memo_cache_sentinel")) {
    t5 = {
      zIndex: 1300
    };
    $[9] = t5;
  } else {
    t5 = $[9];
  }
  let t6;
  if ($[10] !== disabled || $[11] !== handleChangeConnection || $[12] !== label || $[13] !== placeholder || $[14] !== t3 || $[15] !== t4) {
    t6 = /* @__PURE__ */ jsxRuntimeExports.jsx(Select, { data: AuthTypeSelectOptions, required: true, allowDeselect: false, disabled, rightSectionWidth: 30, rightSection: t2, label, value: t3, placeholder, onChange: handleChangeConnection, error: t4, w: "100%", comboboxProps: t5, styles: _temp });
    $[10] = disabled;
    $[11] = handleChangeConnection;
    $[12] = label;
    $[13] = placeholder;
    $[14] = t3;
    $[15] = t4;
    $[16] = t6;
  } else {
    t6 = $[16];
  }
  return t6;
};
function _temp() {
  return {
    rightSection: {
      pointerEvents: "none"
    }
  };
}
const MainForm = (props) => {
  const $ = compilerRuntimeExports.c(200);
  const {
    form,
    isOnIntegration,
    integrationType,
    toggleIntegration
  } = props;
  const isMobile = useMediaQuery("(max-width: 992px)");
  const {
    t
  } = useTranslation();
  const {
    classes
  } = useStyles();
  const isApiIntegration = integrationType === EmailServerIntegrationType.Api;
  const t0 = isMobile ? 1 : 2;
  const t1 = classes.textFieldInput;
  let t2;
  if ($[0] !== t) {
    t2 = t("servers.name");
    $[0] = t;
    $[1] = t2;
  } else {
    t2 = $[1];
  }
  let t3;
  if ($[2] !== t) {
    t3 = t("servers.nameLabel");
    $[2] = t;
    $[3] = t3;
  } else {
    t3 = $[3];
  }
  let t4;
  if ($[4] !== form) {
    t4 = form.getInputProps("Name");
    $[4] = form;
    $[5] = t4;
  } else {
    t4 = $[5];
  }
  let t5;
  if ($[6] !== classes.textFieldInput || $[7] !== t2 || $[8] !== t3 || $[9] !== t4) {
    t5 = /* @__PURE__ */ jsxRuntimeExports.jsx(TextInput, { className: t1, placeholder: t2, label: t3, withAsterisk: true, ...t4 });
    $[6] = classes.textFieldInput;
    $[7] = t2;
    $[8] = t3;
    $[9] = t4;
    $[10] = t5;
  } else {
    t5 = $[10];
  }
  const t6 = classes.textFieldInput;
  let t7;
  if ($[11] !== t) {
    t7 = t("servers.domains");
    $[11] = t;
    $[12] = t7;
  } else {
    t7 = $[12];
  }
  let t8;
  if ($[13] !== t) {
    t8 = t("servers.domainsLabel");
    $[13] = t;
    $[14] = t8;
  } else {
    t8 = $[14];
  }
  const t9 = !isApiIntegration;
  let t10;
  if ($[15] !== form) {
    t10 = form.getInputProps("Domains");
    $[15] = form;
    $[16] = t10;
  } else {
    t10 = $[16];
  }
  let t11;
  if ($[17] !== classes.textFieldInput || $[18] !== isApiIntegration || $[19] !== t10 || $[20] !== t7 || $[21] !== t8 || $[22] !== t9) {
    t11 = /* @__PURE__ */ jsxRuntimeExports.jsx(TextInput, { className: t6, placeholder: t7, label: t8, withAsterisk: t9, disabled: isApiIntegration, ...t10 });
    $[17] = classes.textFieldInput;
    $[18] = isApiIntegration;
    $[19] = t10;
    $[20] = t7;
    $[21] = t8;
    $[22] = t9;
    $[23] = t11;
  } else {
    t11 = $[23];
  }
  let t12;
  if ($[24] !== t0 || $[25] !== t11 || $[26] !== t5) {
    t12 = /* @__PURE__ */ jsxRuntimeExports.jsxs(SimpleGrid, { cols: t0, w: "100%", children: [
      t5,
      t11
    ] });
    $[24] = t0;
    $[25] = t11;
    $[26] = t5;
    $[27] = t12;
  } else {
    t12 = $[27];
  }
  const t13 = isMobile ? 1 : 2;
  const t14 = classes.textFieldInput;
  let t15;
  if ($[28] !== t) {
    t15 = t("servers.popServer");
    $[28] = t;
    $[29] = t15;
  } else {
    t15 = $[29];
  }
  let t16;
  if ($[30] !== t) {
    t16 = t("servers.popServer");
    $[30] = t;
    $[31] = t16;
  } else {
    t16 = $[31];
  }
  let t17;
  if ($[32] !== form) {
    t17 = form.getInputProps("PopServer");
    $[32] = form;
    $[33] = t17;
  } else {
    t17 = $[33];
  }
  let t18;
  if ($[34] !== classes.textFieldInput || $[35] !== t15 || $[36] !== t16 || $[37] !== t17) {
    t18 = /* @__PURE__ */ jsxRuntimeExports.jsx(TextInput, { className: t14, placeholder: t15, label: t16, withAsterisk: true, ...t17 });
    $[34] = classes.textFieldInput;
    $[35] = t15;
    $[36] = t16;
    $[37] = t17;
    $[38] = t18;
  } else {
    t18 = $[38];
  }
  const t19 = classes.rightSideContainerTwoItems;
  const t20 = isMobile ? "column" : "row";
  const t21 = classes.textFieldInput;
  const t22 = isMobile ? "auto" : 70;
  let t23;
  if ($[39] !== t) {
    t23 = t("servers.port");
    $[39] = t;
    $[40] = t23;
  } else {
    t23 = $[40];
  }
  let t24;
  if ($[41] !== t) {
    t24 = t("servers.port");
    $[41] = t;
    $[42] = t24;
  } else {
    t24 = $[42];
  }
  const t25 = isMobile ? "20px" : "";
  let t26;
  if ($[43] !== form) {
    t26 = form.getInputProps("PopPort");
    $[43] = form;
    $[44] = t26;
  } else {
    t26 = $[44];
  }
  let t27;
  if ($[45] !== classes.textFieldInput || $[46] !== t22 || $[47] !== t23 || $[48] !== t24 || $[49] !== t25 || $[50] !== t26) {
    t27 = /* @__PURE__ */ jsxRuntimeExports.jsx(NumberInput, { className: t21, autoComplete: "off", maw: t22, placeholder: t23, label: t24, withAsterisk: true, hideControls: true, defaultValue: "", mb: t25, ...t26 });
    $[45] = classes.textFieldInput;
    $[46] = t22;
    $[47] = t23;
    $[48] = t24;
    $[49] = t25;
    $[50] = t26;
    $[51] = t27;
  } else {
    t27 = $[51];
  }
  let t28;
  if ($[52] !== t) {
    t28 = t("servers.connection");
    $[52] = t;
    $[53] = t28;
  } else {
    t28 = $[53];
  }
  let t29;
  if ($[54] !== t) {
    t29 = t("servers.connectionType");
    $[54] = t;
    $[55] = t29;
  } else {
    t29 = $[55];
  }
  let t30;
  if ($[56] !== form) {
    t30 = form.getInputProps("PopConnectionType");
    $[56] = form;
    $[57] = t30;
  } else {
    t30 = $[57];
  }
  let t31;
  if ($[58] !== form || $[59] !== t28 || $[60] !== t29 || $[61] !== t30.value) {
    t31 = /* @__PURE__ */ jsxRuntimeExports.jsx(ConnectionsSelect, { placeholder: t28, form, fieldName: "PopConnectionType", label: t29, value: t30.value });
    $[58] = form;
    $[59] = t28;
    $[60] = t29;
    $[61] = t30.value;
    $[62] = t31;
  } else {
    t31 = $[62];
  }
  let t32;
  if ($[63] !== classes.rightSideContainerTwoItems || $[64] !== t20 || $[65] !== t27 || $[66] !== t31) {
    t32 = /* @__PURE__ */ jsxRuntimeExports.jsxs(Flex, { className: t19, gap: "24px", direction: t20, children: [
      t27,
      t31
    ] });
    $[63] = classes.rightSideContainerTwoItems;
    $[64] = t20;
    $[65] = t27;
    $[66] = t31;
    $[67] = t32;
  } else {
    t32 = $[67];
  }
  let t33;
  if ($[68] !== t13 || $[69] !== t18 || $[70] !== t32) {
    t33 = /* @__PURE__ */ jsxRuntimeExports.jsxs(SimpleGrid, { cols: t13, mt: 16, w: "100%", children: [
      t18,
      t32
    ] });
    $[68] = t13;
    $[69] = t18;
    $[70] = t32;
    $[71] = t33;
  } else {
    t33 = $[71];
  }
  const t34 = isMobile ? 1 : 2;
  const t35 = classes.textFieldInput;
  let t36;
  if ($[72] !== t) {
    t36 = t("servers.imapServer");
    $[72] = t;
    $[73] = t36;
  } else {
    t36 = $[73];
  }
  let t37;
  if ($[74] !== t) {
    t37 = t("servers.imapServer");
    $[74] = t;
    $[75] = t37;
  } else {
    t37 = $[75];
  }
  let t38;
  if ($[76] !== form) {
    t38 = form.getInputProps("ImapServer");
    $[76] = form;
    $[77] = t38;
  } else {
    t38 = $[77];
  }
  let t39;
  if ($[78] !== classes.textFieldInput || $[79] !== t36 || $[80] !== t37 || $[81] !== t38) {
    t39 = /* @__PURE__ */ jsxRuntimeExports.jsx(TextInput, { className: t35, placeholder: t36, label: t37, withAsterisk: true, ...t38 });
    $[78] = classes.textFieldInput;
    $[79] = t36;
    $[80] = t37;
    $[81] = t38;
    $[82] = t39;
  } else {
    t39 = $[82];
  }
  const t40 = classes.rightSideContainer;
  const t41 = isMobile ? "column" : "row";
  const t42 = classes.textFieldInput;
  const t43 = isMobile ? "auto" : 70;
  let t44;
  if ($[83] !== t) {
    t44 = t("servers.port");
    $[83] = t;
    $[84] = t44;
  } else {
    t44 = $[84];
  }
  let t45;
  if ($[85] !== t) {
    t45 = t("servers.port");
    $[85] = t;
    $[86] = t45;
  } else {
    t45 = $[86];
  }
  const t46 = isMobile ? "20px" : "";
  let t47;
  if ($[87] !== form) {
    t47 = form.getInputProps("ImapPort");
    $[87] = form;
    $[88] = t47;
  } else {
    t47 = $[88];
  }
  let t48;
  if ($[89] !== classes.textFieldInput || $[90] !== t43 || $[91] !== t44 || $[92] !== t45 || $[93] !== t46 || $[94] !== t47) {
    t48 = /* @__PURE__ */ jsxRuntimeExports.jsx(NumberInput, { className: t42, autoComplete: "off", maw: t43, placeholder: t44, label: t45, withAsterisk: true, hideControls: true, defaultValue: "", mb: t46, ...t47 });
    $[89] = classes.textFieldInput;
    $[90] = t43;
    $[91] = t44;
    $[92] = t45;
    $[93] = t46;
    $[94] = t47;
    $[95] = t48;
  } else {
    t48 = $[95];
  }
  let t49;
  if ($[96] !== t) {
    t49 = t("servers.connection");
    $[96] = t;
    $[97] = t49;
  } else {
    t49 = $[97];
  }
  let t50;
  if ($[98] !== t) {
    t50 = t("servers.connectionType");
    $[98] = t;
    $[99] = t50;
  } else {
    t50 = $[99];
  }
  let t51;
  if ($[100] !== form) {
    t51 = form.getInputProps("ImapConnectionType");
    $[100] = form;
    $[101] = t51;
  } else {
    t51 = $[101];
  }
  let t52;
  if ($[102] !== form || $[103] !== t49 || $[104] !== t50 || $[105] !== t51.value) {
    t52 = /* @__PURE__ */ jsxRuntimeExports.jsx(ConnectionsSelect, { placeholder: t49, form, fieldName: "ImapConnectionType", label: t50, value: t51.value });
    $[102] = form;
    $[103] = t49;
    $[104] = t50;
    $[105] = t51.value;
    $[106] = t52;
  } else {
    t52 = $[106];
  }
  let t53;
  if ($[107] !== t) {
    t53 = t("servers.authType");
    $[107] = t;
    $[108] = t53;
  } else {
    t53 = $[108];
  }
  let t54;
  if ($[109] !== t) {
    t54 = t("servers.authType");
    $[109] = t;
    $[110] = t54;
  } else {
    t54 = $[110];
  }
  let t55;
  if ($[111] !== form) {
    t55 = form.getInputProps("ImapLoginType");
    $[111] = form;
    $[112] = t55;
  } else {
    t55 = $[112];
  }
  let t56;
  if ($[113] !== form || $[114] !== t53 || $[115] !== t54 || $[116] !== t55.value) {
    t56 = /* @__PURE__ */ jsxRuntimeExports.jsx(AuthTypeSelect, { form, placeholder: t53, fieldName: "ImapLoginType", label: t54, value: t55.value });
    $[113] = form;
    $[114] = t53;
    $[115] = t54;
    $[116] = t55.value;
    $[117] = t56;
  } else {
    t56 = $[117];
  }
  let t57;
  if ($[118] !== classes.rightSideContainer || $[119] !== t41 || $[120] !== t48 || $[121] !== t52 || $[122] !== t56) {
    t57 = /* @__PURE__ */ jsxRuntimeExports.jsxs(Flex, { className: t40, gap: "24px", direction: t41, children: [
      t48,
      t52,
      t56
    ] });
    $[118] = classes.rightSideContainer;
    $[119] = t41;
    $[120] = t48;
    $[121] = t52;
    $[122] = t56;
    $[123] = t57;
  } else {
    t57 = $[123];
  }
  let t58;
  if ($[124] !== t34 || $[125] !== t39 || $[126] !== t57) {
    t58 = /* @__PURE__ */ jsxRuntimeExports.jsxs(SimpleGrid, { cols: t34, mt: 16, w: "100%", children: [
      t39,
      t57
    ] });
    $[124] = t34;
    $[125] = t39;
    $[126] = t57;
    $[127] = t58;
  } else {
    t58 = $[127];
  }
  const t59 = isMobile ? 1 : 2;
  const t60 = classes.textFieldInput;
  let t61;
  if ($[128] !== t) {
    t61 = t("servers.smtpServer");
    $[128] = t;
    $[129] = t61;
  } else {
    t61 = $[129];
  }
  let t62;
  if ($[130] !== t) {
    t62 = t("servers.smtpServer");
    $[130] = t;
    $[131] = t62;
  } else {
    t62 = $[131];
  }
  let t63;
  if ($[132] !== form) {
    t63 = form.getInputProps("SmtpServer");
    $[132] = form;
    $[133] = t63;
  } else {
    t63 = $[133];
  }
  let t64;
  if ($[134] !== classes.textFieldInput || $[135] !== t61 || $[136] !== t62 || $[137] !== t63) {
    t64 = /* @__PURE__ */ jsxRuntimeExports.jsx(TextInput, { className: t60, placeholder: t61, label: t62, withAsterisk: true, ...t63 });
    $[134] = classes.textFieldInput;
    $[135] = t61;
    $[136] = t62;
    $[137] = t63;
    $[138] = t64;
  } else {
    t64 = $[138];
  }
  const t65 = classes.rightSideContainer;
  const t66 = isMobile ? "column" : "row";
  const t67 = classes.textFieldInput;
  const t68 = isMobile ? "auto" : 70;
  let t69;
  if ($[139] !== t) {
    t69 = t("servers.port");
    $[139] = t;
    $[140] = t69;
  } else {
    t69 = $[140];
  }
  let t70;
  if ($[141] !== t) {
    t70 = t("servers.port");
    $[141] = t;
    $[142] = t70;
  } else {
    t70 = $[142];
  }
  const t71 = isMobile ? "20px" : "";
  let t72;
  if ($[143] !== form) {
    t72 = form.getInputProps("SmtpPort");
    $[143] = form;
    $[144] = t72;
  } else {
    t72 = $[144];
  }
  let t73;
  if ($[145] !== classes.textFieldInput || $[146] !== t68 || $[147] !== t69 || $[148] !== t70 || $[149] !== t71 || $[150] !== t72) {
    t73 = /* @__PURE__ */ jsxRuntimeExports.jsx(NumberInput, { className: t67, autoComplete: "off", maw: t68, placeholder: t69, label: t70, withAsterisk: true, hideControls: true, defaultValue: "", mb: t71, ...t72 });
    $[145] = classes.textFieldInput;
    $[146] = t68;
    $[147] = t69;
    $[148] = t70;
    $[149] = t71;
    $[150] = t72;
    $[151] = t73;
  } else {
    t73 = $[151];
  }
  let t74;
  if ($[152] !== t) {
    t74 = t("servers.connection");
    $[152] = t;
    $[153] = t74;
  } else {
    t74 = $[153];
  }
  let t75;
  if ($[154] !== t) {
    t75 = t("servers.connectionType");
    $[154] = t;
    $[155] = t75;
  } else {
    t75 = $[155];
  }
  let t76;
  if ($[156] !== form) {
    t76 = form.getInputProps("SmtpConnectionType");
    $[156] = form;
    $[157] = t76;
  } else {
    t76 = $[157];
  }
  let t77;
  if ($[158] !== form || $[159] !== t74 || $[160] !== t75 || $[161] !== t76.value) {
    t77 = /* @__PURE__ */ jsxRuntimeExports.jsx(ConnectionsSelect, { placeholder: t74, form, fieldName: "SmtpConnectionType", label: t75, value: t76.value });
    $[158] = form;
    $[159] = t74;
    $[160] = t75;
    $[161] = t76.value;
    $[162] = t77;
  } else {
    t77 = $[162];
  }
  let t78;
  if ($[163] !== t) {
    t78 = t("servers.authType");
    $[163] = t;
    $[164] = t78;
  } else {
    t78 = $[164];
  }
  let t79;
  if ($[165] !== t) {
    t79 = t("servers.authType");
    $[165] = t;
    $[166] = t79;
  } else {
    t79 = $[166];
  }
  let t80;
  if ($[167] !== form) {
    t80 = form.getInputProps("SmtpLoginType");
    $[167] = form;
    $[168] = t80;
  } else {
    t80 = $[168];
  }
  let t81;
  if ($[169] !== form || $[170] !== t78 || $[171] !== t79 || $[172] !== t80.value) {
    t81 = /* @__PURE__ */ jsxRuntimeExports.jsx(AuthTypeSelect, { form, placeholder: t78, fieldName: "SmtpLoginType", label: t79, value: t80.value });
    $[169] = form;
    $[170] = t78;
    $[171] = t79;
    $[172] = t80.value;
    $[173] = t81;
  } else {
    t81 = $[173];
  }
  let t82;
  if ($[174] !== classes.rightSideContainer || $[175] !== t66 || $[176] !== t73 || $[177] !== t77 || $[178] !== t81) {
    t82 = /* @__PURE__ */ jsxRuntimeExports.jsxs(Flex, { className: t65, gap: "24px", direction: t66, children: [
      t73,
      t77,
      t81
    ] });
    $[174] = classes.rightSideContainer;
    $[175] = t66;
    $[176] = t73;
    $[177] = t77;
    $[178] = t81;
    $[179] = t82;
  } else {
    t82 = $[179];
  }
  let t83;
  if ($[180] !== t59 || $[181] !== t64 || $[182] !== t82) {
    t83 = /* @__PURE__ */ jsxRuntimeExports.jsxs(SimpleGrid, { cols: t59, mt: 16, w: "100%", children: [
      t64,
      t82
    ] });
    $[180] = t59;
    $[181] = t64;
    $[182] = t82;
    $[183] = t83;
  } else {
    t83 = $[183];
  }
  const t84 = isMobile ? 1 : 2;
  const t85 = classes.checkbox;
  let t86;
  if ($[184] !== t) {
    t86 = t("servers.turnOnConnection");
    $[184] = t;
    $[185] = t86;
  } else {
    t86 = $[185];
  }
  let t87;
  if ($[186] !== classes.checkbox || $[187] !== isOnIntegration || $[188] !== t86 || $[189] !== toggleIntegration) {
    t87 = /* @__PURE__ */ jsxRuntimeExports.jsx(Checkbox, { className: t85, label: t86, size: "xs", checked: isOnIntegration, onChange: toggleIntegration });
    $[186] = classes.checkbox;
    $[187] = isOnIntegration;
    $[188] = t86;
    $[189] = toggleIntegration;
    $[190] = t87;
  } else {
    t87 = $[190];
  }
  let t88;
  if ($[191] !== t84 || $[192] !== t87) {
    t88 = /* @__PURE__ */ jsxRuntimeExports.jsx(SimpleGrid, { cols: t84, mt: 16, w: "100%", children: t87 });
    $[191] = t84;
    $[192] = t87;
    $[193] = t88;
  } else {
    t88 = $[193];
  }
  let t89;
  if ($[194] !== t12 || $[195] !== t33 || $[196] !== t58 || $[197] !== t83 || $[198] !== t88) {
    t89 = /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
      t12,
      t33,
      t58,
      t83,
      t88
    ] });
    $[194] = t12;
    $[195] = t33;
    $[196] = t58;
    $[197] = t83;
    $[198] = t88;
    $[199] = t89;
  } else {
    t89 = $[199];
  }
  return t89;
};
const MailServerForm = (props) => {
  var _a, _b, _c, _d, _e;
  const $ = compilerRuntimeExports.c(71);
  const {
    mailServer,
    opened,
    isEditing,
    handleClose
  } = props;
  const {
    classes,
    cx
  } = useStyles();
  let t0;
  if ($[0] !== props) {
    t0 = {
      ...props
    };
    $[0] = props;
    $[1] = t0;
  } else {
    t0 = $[1];
  }
  const {
    form,
    setIsOnIntegration,
    handleSubmit,
    modalClose,
    isOnIntegration,
    isFetching
  } = useServerModalForm(t0);
  const isMobile = useMediaQuery("(max-width: 992px)");
  const isTablet = useMediaQuery("(max-width: 1400px)");
  const {
    t
  } = useTranslation();
  let t1;
  if ($[2] !== form || $[3] !== ((_a = mailServer == null ? void 0 : mailServer.Integration) == null ? void 0 : _a.Ssh)) {
    t1 = () => {
      var _a2, _b2;
      const currentIntegration = ((_a2 = form == null ? void 0 : form.values) == null ? void 0 : _a2.Integration) || {};
      form.setFieldValue("Integration", {
        ...currentIntegration,
        Type: Number(EmailServerIntegrationType.Ssh),
        Ssh: structuredClone(((_b2 = mailServer == null ? void 0 : mailServer.Integration) == null ? void 0 : _b2.Ssh) || TEMPLATE_MAIL_SERVER.TEMPLATE_SSH)
      });
    };
    $[2] = form;
    $[3] = (_b = mailServer == null ? void 0 : mailServer.Integration) == null ? void 0 : _b.Ssh;
    $[4] = t1;
  } else {
    t1 = $[4];
  }
  const handleSetSshType = t1;
  let t2;
  if ($[5] !== form || $[6] !== ((_c = mailServer == null ? void 0 : mailServer.Integration) == null ? void 0 : _c.Api)) {
    t2 = () => {
      var _a2, _b2, _c2, _d2;
      const currentIntegration_0 = ((_a2 = form == null ? void 0 : form.values) == null ? void 0 : _a2.Integration) || {};
      form.setFieldValue("Integration", {
        ...currentIntegration_0,
        Type: Number(EmailServerIntegrationType.Api),
        Api: structuredClone({
          ...TEMPLATE_MAIL_SERVER.TEMPLATE_API,
          ...((_b2 = mailServer == null ? void 0 : mailServer.Integration) == null ? void 0 : _b2.Api) || {},
          ApiAuth20Settings: ((_d2 = (_c2 = mailServer == null ? void 0 : mailServer.Integration) == null ? void 0 : _c2.Api) == null ? void 0 : _d2.ApiAuth20Settings) ?? null
        })
      });
    };
    $[5] = form;
    $[6] = (_d = mailServer == null ? void 0 : mailServer.Integration) == null ? void 0 : _d.Api;
    $[7] = t2;
  } else {
    t2 = $[7];
  }
  const handleSetApiType = t2;
  let t3;
  if ($[8] !== form || $[9] !== handleSetSshType || $[10] !== setIsOnIntegration) {
    t3 = () => {
      setIsOnIntegration((prev) => {
        const nextValue = !prev;
        if (nextValue) {
          handleSetSshType();
          return nextValue;
        }
        form.setFieldValue("Integration", {
          Type: EmailServerIntegrationType.None,
          Ssh: null,
          Api: null,
          Smtp: null
        });
        return nextValue;
      });
    };
    $[8] = form;
    $[9] = handleSetSshType;
    $[10] = setIsOnIntegration;
    $[11] = t3;
  } else {
    t3 = $[11];
  }
  const toggleIntegration = t3;
  let t4;
  if ($[12] !== isEditing || $[13] !== t) {
    t4 = isEditing ? t("servers.edit") : t("servers.add");
    $[12] = isEditing;
    $[13] = t;
    $[14] = t4;
  } else {
    t4 = $[14];
  }
  const t5 = isTablet ? "90%" : "60%";
  const t6 = classes.modalRoot;
  let t7;
  if ($[15] !== form || $[16] !== handleSubmit) {
    t7 = form.onSubmit(handleSubmit);
    $[15] = form;
    $[16] = handleSubmit;
    $[17] = t7;
  } else {
    t7 = $[17];
  }
  const t8 = (_e = form.values.Integration) == null ? void 0 : _e.Type;
  let t9;
  if ($[18] !== form || $[19] !== isOnIntegration || $[20] !== t8 || $[21] !== toggleIntegration) {
    t9 = /* @__PURE__ */ jsxRuntimeExports.jsx(MainForm, { form, toggleIntegration, isOnIntegration, integrationType: t8 });
    $[18] = form;
    $[19] = isOnIntegration;
    $[20] = t8;
    $[21] = toggleIntegration;
    $[22] = t9;
  } else {
    t9 = $[22];
  }
  let t10;
  if ($[23] !== classes.radio || $[24] !== form || $[25] !== handleSetApiType || $[26] !== handleSetSshType || $[27] !== isMobile || $[28] !== isOnIntegration) {
    t10 = isOnIntegration && /* @__PURE__ */ jsxRuntimeExports.jsxs(Box, { pl: isMobile ? 0 : 34, w: "100%", children: [
      /* @__PURE__ */ jsxRuntimeExports.jsx(Radio, { checked: form.values.Integration.Type === EmailServerIntegrationType.Ssh, className: classes.radio, mt: 18, label: "SSH", size: "xs", "data-cy": "enableGeneratePassword", onChange: handleSetSshType }),
      /* @__PURE__ */ jsxRuntimeExports.jsx(Radio, { checked: form.values.Integration.Type === EmailServerIntegrationType.Api, className: classes.radio, label: "API", size: "xs", "data-cy": "enableGeneratePassword", onChange: handleSetApiType }),
      /* @__PURE__ */ jsxRuntimeExports.jsx(MailServerIntegration, { form })
    ] });
    $[23] = classes.radio;
    $[24] = form;
    $[25] = handleSetApiType;
    $[26] = handleSetSshType;
    $[27] = isMobile;
    $[28] = isOnIntegration;
    $[29] = t10;
  } else {
    t10 = $[29];
  }
  let t11;
  if ($[30] !== classes.modalContainer || $[31] !== t10 || $[32] !== t9) {
    t11 = /* @__PURE__ */ jsxRuntimeExports.jsx(ScrollArea.Autosize, { mah: "calc(90dvh - 200px)", w: "100%", children: /* @__PURE__ */ jsxRuntimeExports.jsxs(Box, { className: classes.modalContainer, children: [
      t9,
      t10
    ] }) });
    $[30] = classes.modalContainer;
    $[31] = t10;
    $[32] = t9;
    $[33] = t11;
  } else {
    t11 = $[33];
  }
  let t12;
  if ($[34] !== classes.customFooter || $[35] !== classes.modalFooter || $[36] !== cx) {
    t12 = cx(classes.modalFooter, classes.customFooter);
    $[34] = classes.customFooter;
    $[35] = classes.modalFooter;
    $[36] = cx;
    $[37] = t12;
  } else {
    t12 = $[37];
  }
  const t13 = isMobile ? 0 : 24;
  const t14 = isMobile ? "100%" : "49%";
  let t15;
  if ($[38] !== isEditing || $[39] !== t) {
    t15 = isEditing ? t("save") : t("add");
    $[38] = isEditing;
    $[39] = t;
    $[40] = t15;
  } else {
    t15 = $[40];
  }
  let t16;
  if ($[41] !== t13 || $[42] !== t14 || $[43] !== t15) {
    t16 = /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { type: "submit", mb: "0", mr: t13, w: t14, children: t15 });
    $[41] = t13;
    $[42] = t14;
    $[43] = t15;
    $[44] = t16;
  } else {
    t16 = $[44];
  }
  const t17 = classes.modalCancelBtn;
  const t18 = isMobile ? "100%" : "49%";
  let t19;
  if ($[45] !== t) {
    t19 = t("cancel");
    $[45] = t;
    $[46] = t19;
  } else {
    t19 = $[46];
  }
  let t20;
  if ($[47] !== classes.modalCancelBtn || $[48] !== handleClose || $[49] !== t18 || $[50] !== t19) {
    t20 = /* @__PURE__ */ jsxRuntimeExports.jsx(UnstyledButton, { ml: 8, className: t17, w: t18, onClick: handleClose, children: t19 });
    $[47] = classes.modalCancelBtn;
    $[48] = handleClose;
    $[49] = t18;
    $[50] = t19;
    $[51] = t20;
  } else {
    t20 = $[51];
  }
  let t21;
  if ($[52] !== t12 || $[53] !== t16 || $[54] !== t20) {
    t21 = /* @__PURE__ */ jsxRuntimeExports.jsxs(Box, { className: t12, children: [
      t16,
      t20
    ] });
    $[52] = t12;
    $[53] = t16;
    $[54] = t20;
    $[55] = t21;
  } else {
    t21 = $[55];
  }
  let t22;
  if ($[56] === Symbol.for("react.memo_cache_sentinel")) {
    t22 = {
      blur: 2
    };
    $[56] = t22;
  } else {
    t22 = $[56];
  }
  let t23;
  if ($[57] !== isFetching) {
    t23 = /* @__PURE__ */ jsxRuntimeExports.jsx(LoadingOverlay, { visible: isFetching, overlayProps: t22 });
    $[57] = isFetching;
    $[58] = t23;
  } else {
    t23 = $[58];
  }
  let t24;
  if ($[59] !== classes.modalRoot || $[60] !== t11 || $[61] !== t21 || $[62] !== t23 || $[63] !== t7) {
    t24 = /* @__PURE__ */ jsxRuntimeExports.jsxs("form", { className: t6, onSubmit: t7, children: [
      t11,
      t21,
      t23
    ] });
    $[59] = classes.modalRoot;
    $[60] = t11;
    $[61] = t21;
    $[62] = t23;
    $[63] = t7;
    $[64] = t24;
  } else {
    t24 = $[64];
  }
  let t25;
  if ($[65] !== modalClose || $[66] !== opened || $[67] !== t24 || $[68] !== t4 || $[69] !== t5) {
    t25 = /* @__PURE__ */ jsxRuntimeExports.jsx(Modal, { opened, onClose: modalClose, title: t4, zIndex: 1300, size: t5, children: t24 });
    $[65] = modalClose;
    $[66] = opened;
    $[67] = t24;
    $[68] = t4;
    $[69] = t5;
    $[70] = t25;
  } else {
    t25 = $[70];
  }
  return t25;
};
export {
  MailServerForm as M
};
//# sourceMappingURL=serverForm-BbGb2r52.js.map
