import { E as compilerRuntimeExports, j as jsxRuntimeExports, L as Link, T as useNavigate, r as reactExports } from "./vendor-react-DYNCg6N5.js";
import { c as useAppSelector, ar as useCreateClientMutation, as as useLazyCheckEmailExistsQuery, i as isSaaS, m as universalNotification } from "./index-DfebxkL9.js";
import { c as createStyles, E as TextInput, T as Text, B as Button, b as Box, S as Stack, J as PasswordInput, d as Checkbox, G as Group, W as useMediaQuery, a0 as SimpleGrid, z as useForm, a9 as zodResolver, aa as Stepper, s as showNotification } from "./vendor-mantine-h0WlM2Mj.js";
import { u as useGenerateRules, R as RulesConditionList, d as defaultMailServerPasswordOptions } from "./passwordOptions-b-kjbiiT.js";
import { u as usePasswordSchema } from "./useGeneratePolicy-B4rO5xUa.js";
import { a as emailPrefixRegExp, b as emailLastCharRegExp, c as emailFirstCharRegExp } from "./validation-Ds00Zghx.js";
import { u as useTranslation } from "./vendor-i18n-wisIXUFi.js";
import { o as objectType, b as booleanType, s as stringType } from "./types-espwwxTQ.js";
const useStyles = createStyles((theme) => ({
  wrapper: {
    marginBottom: "20px"
  },
  titleWrapper: {
    display: "flex",
    alignItems: "center",
    marginBottom: "20px",
    marginTop: "-35px"
  },
  subtitle: {
    color: theme.colors.gray[6]
  },
  link: {
    padding: 0,
    fontWeight: 400,
    marginLeft: "5px",
    fontSize: "16px",
    height: "auto",
    "&:hover": {
      textDecoration: "underline",
      backgroundColor: "transparent"
    }
  },
  checkbox: {
    label: {
      color: theme.colors.gray[8],
      paddingLeft: "7px",
      lineHeight: "18px"
    }
  },
  checkboxLink: {
    fontSize: "14px",
    padding: 0,
    fontWeight: 400,
    height: "auto",
    lineHeight: "18px",
    "&:hover": {
      textDecoration: "underline",
      backgroundColor: "transparent"
    }
  },
  controls: {
    "& .mantine-InputWrapper-error": {
      marginBottom: "10px",
      marginTop: "10px",
      fontSize: "14px",
      position: "relative"
    },
    "& .mantine-Checkbox-error": {
      paddingLeft: "8px"
    },
    "& .mantine-Stepper-steps": {
      display: "none"
    }
  },
  footerForm: {
    display: "flex",
    flexWrap: "nowrap",
    justifyContent: "space-between"
  },
  footerFormPrevButton: {
    border: `1px solid ${theme.colors.blue[6]}`,
    color: theme.colors.blue[6]
  },
  mailButton: {
    textAlign: "center",
    marginTop: "30px",
    lineHeight: "28px",
    height: "100%",
    span: {
      whiteSpace: "inherit"
    },
    "&:hover": {
      backgroundColor: "transparent"
    }
  },
  registerButton: {
    "& .mantine-Button-label": {
      overflow: "visible"
    }
  },
  email: {
    "& .mantine-Input-input": {
      paddingRight: "130px"
    }
  },
  serviceEmailWrapper: {
    position: "relative"
  },
  emailDomain: {
    position: "absolute",
    top: "13px",
    right: "15px"
  },
  iconArrow: {
    position: "absolute",
    left: "60px",
    [`@media (max-width: 575px)`]: {
      left: "40px"
    },
    [`@media (max-width: 435px)`]: {
      left: "20px"
    }
  }
}));
const InfoStep = (t0) => {
  const $ = compilerRuntimeExports.c(47);
  const {
    form,
    t,
    classes,
    isDisableCompany: t1
  } = t0;
  const isDisableCompany = t1 === void 0 ? false : t1;
  const t2 = classes.wrapper;
  const t3 = classes.titleWrapper;
  const t4 = classes.subtitle;
  let t5;
  if ($[0] !== t) {
    t5 = t("register.hasAccount");
    $[0] = t;
    $[1] = t5;
  } else {
    t5 = $[1];
  }
  let t6;
  if ($[2] !== classes.subtitle || $[3] !== t5) {
    t6 = /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { className: t4, children: t5 });
    $[2] = classes.subtitle;
    $[3] = t5;
    $[4] = t6;
  } else {
    t6 = $[4];
  }
  const t7 = classes.link;
  let t8;
  if ($[5] !== t) {
    t8 = t("register.enter");
    $[5] = t;
    $[6] = t8;
  } else {
    t8 = $[6];
  }
  let t9;
  if ($[7] !== classes.link || $[8] !== t8) {
    t9 = /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { className: t7, component: Link, to: "/login", variant: "subtle", children: t8 });
    $[7] = classes.link;
    $[8] = t8;
    $[9] = t9;
  } else {
    t9 = $[9];
  }
  let t10;
  if ($[10] !== classes.titleWrapper || $[11] !== t6 || $[12] !== t9) {
    t10 = /* @__PURE__ */ jsxRuntimeExports.jsxs(Box, { className: t3, children: [
      t6,
      t9
    ] });
    $[10] = classes.titleWrapper;
    $[11] = t6;
    $[12] = t9;
    $[13] = t10;
  } else {
    t10 = $[13];
  }
  let t11;
  if ($[14] === Symbol.for("react.memo_cache_sentinel")) {
    t11 = {
      gap: "10px",
      display: "flex",
      justifyContent: "space-between"
    };
    $[14] = t11;
  } else {
    t11 = $[14];
  }
  let t12;
  if ($[15] !== t) {
    t12 = t("register.firstName");
    $[15] = t;
    $[16] = t12;
  } else {
    t12 = $[16];
  }
  let t13;
  if ($[17] !== form) {
    t13 = form.getInputProps("FirstName");
    $[17] = form;
    $[18] = t13;
  } else {
    t13 = $[18];
  }
  let t14;
  if ($[19] !== t12 || $[20] !== t13) {
    t14 = /* @__PURE__ */ jsxRuntimeExports.jsx(TextInput, { size: "lg", radius: "md", variant: "filled", name: "FirstName", placeholder: t12, ...t13 });
    $[19] = t12;
    $[20] = t13;
    $[21] = t14;
  } else {
    t14 = $[21];
  }
  let t15;
  if ($[22] !== t) {
    t15 = t("register.surname");
    $[22] = t;
    $[23] = t15;
  } else {
    t15 = $[23];
  }
  let t16;
  if ($[24] !== form) {
    t16 = form.getInputProps("Surname");
    $[24] = form;
    $[25] = t16;
  } else {
    t16 = $[25];
  }
  let t17;
  if ($[26] !== t15 || $[27] !== t16) {
    t17 = /* @__PURE__ */ jsxRuntimeExports.jsx(TextInput, { size: "lg", radius: "md", variant: "filled", name: "Surname", placeholder: t15, ...t16 });
    $[26] = t15;
    $[27] = t16;
    $[28] = t17;
  } else {
    t17 = $[28];
  }
  let t18;
  if ($[29] !== t14 || $[30] !== t17) {
    t18 = /* @__PURE__ */ jsxRuntimeExports.jsxs(Box, { sx: t11, children: [
      t14,
      t17
    ] });
    $[29] = t14;
    $[30] = t17;
    $[31] = t18;
  } else {
    t18 = $[31];
  }
  let t19;
  if ($[32] !== t) {
    t19 = t("register.company");
    $[32] = t;
    $[33] = t19;
  } else {
    t19 = $[33];
  }
  let t20;
  if ($[34] !== form) {
    t20 = form.getInputProps("Company");
    $[34] = form;
    $[35] = t20;
  } else {
    t20 = $[35];
  }
  let t21;
  if ($[36] !== isDisableCompany || $[37] !== t19 || $[38] !== t20) {
    t21 = /* @__PURE__ */ jsxRuntimeExports.jsx(TextInput, { size: "lg", radius: "md", variant: "filled", name: "Company", disabled: isDisableCompany, placeholder: t19, ...t20 });
    $[36] = isDisableCompany;
    $[37] = t19;
    $[38] = t20;
    $[39] = t21;
  } else {
    t21 = $[39];
  }
  let t22;
  if ($[40] !== t18 || $[41] !== t21) {
    t22 = /* @__PURE__ */ jsxRuntimeExports.jsxs(Stack, { gap: "xs", children: [
      t18,
      t21
    ] });
    $[40] = t18;
    $[41] = t21;
    $[42] = t22;
  } else {
    t22 = $[42];
  }
  let t23;
  if ($[43] !== classes.wrapper || $[44] !== t10 || $[45] !== t22) {
    t23 = /* @__PURE__ */ jsxRuntimeExports.jsxs(Box, { className: t2, children: [
      t10,
      t22
    ] });
    $[43] = classes.wrapper;
    $[44] = t10;
    $[45] = t22;
    $[46] = t23;
  } else {
    t23 = $[46];
  }
  return t23;
};
const EmailStep = (t0) => {
  const $ = compilerRuntimeExports.c(13);
  const {
    form,
    serviceEmail,
    EMAIL_DOMAIN,
    classes,
    t
  } = t0;
  let t1;
  if ($[0] !== EMAIL_DOMAIN || $[1] !== classes.email || $[2] !== classes.emailDomain || $[3] !== classes.serviceEmailWrapper || $[4] !== classes.subtitle || $[5] !== classes.titleWrapper || $[6] !== form || $[7] !== serviceEmail || $[8] !== t) {
    t1 = serviceEmail ? /* @__PURE__ */ jsxRuntimeExports.jsxs(Box, { children: [
      /* @__PURE__ */ jsxRuntimeExports.jsx(Box, { className: classes.titleWrapper, children: /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { className: classes.subtitle, children: t("register.createEmail") }) }),
      /* @__PURE__ */ jsxRuntimeExports.jsxs(Box, { className: classes.serviceEmailWrapper, children: [
        /* @__PURE__ */ jsxRuntimeExports.jsx(TextInput, { className: classes.email, size: "lg", radius: "md", variant: "filled", name: "Email", placeholder: t("register.email"), ...form.getInputProps("Email") }),
        /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { className: classes.emailDomain, children: EMAIL_DOMAIN })
      ] })
    ] }) : /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
      /* @__PURE__ */ jsxRuntimeExports.jsx(Box, { className: classes.titleWrapper, children: /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { className: classes.subtitle, children: t("register.addExistEmail") }) }),
      /* @__PURE__ */ jsxRuntimeExports.jsx(TextInput, { size: "lg", radius: "md", variant: "filled", name: "Email", placeholder: t("register.email"), ...form.getInputProps("Email") })
    ] });
    $[0] = EMAIL_DOMAIN;
    $[1] = classes.email;
    $[2] = classes.emailDomain;
    $[3] = classes.serviceEmailWrapper;
    $[4] = classes.subtitle;
    $[5] = classes.titleWrapper;
    $[6] = form;
    $[7] = serviceEmail;
    $[8] = t;
    $[9] = t1;
  } else {
    t1 = $[9];
  }
  let t2;
  if ($[10] !== classes.wrapper || $[11] !== t1) {
    t2 = /* @__PURE__ */ jsxRuntimeExports.jsx(Box, { className: classes.wrapper, children: t1 });
    $[10] = classes.wrapper;
    $[11] = t1;
    $[12] = t2;
  } else {
    t2 = $[12];
  }
  return t2;
};
const PasswordStep = (t0) => {
  const $ = compilerRuntimeExports.c(63);
  const {
    form,
    handleChangePassword,
    passwordStrengthOptions,
    classes,
    t
  } = t0;
  const password = form.values.Password;
  const rules = useGenerateRules(password, passwordStrengthOptions);
  const t1 = classes.wrapper;
  const t2 = classes.titleWrapper;
  const t3 = classes.subtitle;
  let t4;
  if ($[0] !== t) {
    t4 = t("register.makeNewPassword");
    $[0] = t;
    $[1] = t4;
  } else {
    t4 = $[1];
  }
  let t5;
  if ($[2] !== classes.subtitle || $[3] !== t4) {
    t5 = /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { className: t3, children: t4 });
    $[2] = classes.subtitle;
    $[3] = t4;
    $[4] = t5;
  } else {
    t5 = $[4];
  }
  let t6;
  if ($[5] !== classes.titleWrapper || $[6] !== t5) {
    t6 = /* @__PURE__ */ jsxRuntimeExports.jsx(Box, { className: t2, children: t5 });
    $[5] = classes.titleWrapper;
    $[6] = t5;
    $[7] = t6;
  } else {
    t6 = $[7];
  }
  const t7 = password.length > 0;
  let t8;
  if ($[8] !== rules || $[9] !== t7) {
    t8 = /* @__PURE__ */ jsxRuntimeExports.jsx(RulesConditionList, { rules, check: t7 });
    $[8] = rules;
    $[9] = t7;
    $[10] = t8;
  } else {
    t8 = $[10];
  }
  let t9;
  if ($[11] !== t) {
    t9 = t("register.password");
    $[11] = t;
    $[12] = t9;
  } else {
    t9 = $[12];
  }
  let t10;
  if ($[13] !== form) {
    t10 = form.getInputProps("Password");
    $[13] = form;
    $[14] = t10;
  } else {
    t10 = $[14];
  }
  let t11;
  if ($[15] !== handleChangePassword) {
    t11 = (event) => handleChangePassword(event.currentTarget.value);
    $[15] = handleChangePassword;
    $[16] = t11;
  } else {
    t11 = $[16];
  }
  let t12;
  if ($[17] !== t10 || $[18] !== t11 || $[19] !== t9) {
    t12 = /* @__PURE__ */ jsxRuntimeExports.jsx(PasswordInput, { size: "lg", radius: "md", variant: "filled", name: "Password", placeholder: t9, ...t10, onChange: t11 });
    $[17] = t10;
    $[18] = t11;
    $[19] = t9;
    $[20] = t12;
  } else {
    t12 = $[20];
  }
  const t13 = classes.checkbox;
  let t14;
  if ($[21] !== t) {
    t14 = t("register.subscribeAccept");
    $[21] = t;
    $[22] = t14;
  } else {
    t14 = $[22];
  }
  let t15;
  if ($[23] !== form) {
    t15 = form.getInputProps("AgreementsConfirmedInfo", {
      type: "checkbox"
    });
    $[23] = form;
    $[24] = t15;
  } else {
    t15 = $[24];
  }
  let t16;
  if ($[25] !== classes.checkbox || $[26] !== t14 || $[27] !== t15) {
    t16 = /* @__PURE__ */ jsxRuntimeExports.jsx(Checkbox, { className: t13, label: t14, size: "sm", ...t15 });
    $[25] = classes.checkbox;
    $[26] = t14;
    $[27] = t15;
    $[28] = t16;
  } else {
    t16 = $[28];
  }
  const t17 = classes.checkbox;
  let t18;
  if ($[29] !== form) {
    t18 = form.getInputProps("AgreementsConfirmedRule", {
      type: "checkbox"
    });
    $[29] = form;
    $[30] = t18;
  } else {
    t18 = $[30];
  }
  let t19;
  if ($[31] !== t) {
    t19 = t("register.accept");
    $[31] = t;
    $[32] = t19;
  } else {
    t19 = $[32];
  }
  const t20 = classes.checkboxLink;
  let t21;
  if ($[33] !== t) {
    t21 = t("register.serviceRules");
    $[33] = t;
    $[34] = t21;
  } else {
    t21 = $[34];
  }
  let t22;
  if ($[35] !== classes.checkboxLink || $[36] !== t21) {
    t22 = /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { variant: "subtle", className: t20, component: Link, target: "_blank", to: "https://r7-office.ru/doc/terms_of_service", children: t21 });
    $[35] = classes.checkboxLink;
    $[36] = t21;
    $[37] = t22;
  } else {
    t22 = $[37];
  }
  let t23;
  if ($[38] !== t) {
    t23 = t("register.and");
    $[38] = t;
    $[39] = t23;
  } else {
    t23 = $[39];
  }
  const t24 = classes.checkboxLink;
  let t25;
  if ($[40] !== t) {
    t25 = t("register.privacyPolicy");
    $[40] = t;
    $[41] = t25;
  } else {
    t25 = $[41];
  }
  let t26;
  if ($[42] !== classes.checkboxLink || $[43] !== t25) {
    t26 = /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { variant: "subtle", className: t24, component: Link, target: "_blank", to: "https://r7-office.ru/doc/personal_data_processing_policy", children: t25 });
    $[42] = classes.checkboxLink;
    $[43] = t25;
    $[44] = t26;
  } else {
    t26 = $[44];
  }
  let t27;
  if ($[45] !== t19 || $[46] !== t22 || $[47] !== t23 || $[48] !== t26) {
    t27 = /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { children: [
      t19,
      " ",
      t22,
      " ",
      t23,
      " ",
      t26
    ] });
    $[45] = t19;
    $[46] = t22;
    $[47] = t23;
    $[48] = t26;
    $[49] = t27;
  } else {
    t27 = $[49];
  }
  let t28;
  if ($[50] !== classes.checkbox || $[51] !== t18 || $[52] !== t27) {
    t28 = /* @__PURE__ */ jsxRuntimeExports.jsx(Checkbox, { className: t17, ...t18, label: t27, size: "sm" });
    $[50] = classes.checkbox;
    $[51] = t18;
    $[52] = t27;
    $[53] = t28;
  } else {
    t28 = $[53];
  }
  let t29;
  if ($[54] !== t16 || $[55] !== t28) {
    t29 = /* @__PURE__ */ jsxRuntimeExports.jsxs(Group, { justify: "space-between", mb: 12, mt: 25, pl: 20, gap: "xs", children: [
      t16,
      t28
    ] });
    $[54] = t16;
    $[55] = t28;
    $[56] = t29;
  } else {
    t29 = $[56];
  }
  let t30;
  if ($[57] !== classes.wrapper || $[58] !== t12 || $[59] !== t29 || $[60] !== t6 || $[61] !== t8) {
    t30 = /* @__PURE__ */ jsxRuntimeExports.jsxs(Box, { className: t1, children: [
      t6,
      t8,
      t12,
      t29
    ] });
    $[57] = classes.wrapper;
    $[58] = t12;
    $[59] = t29;
    $[60] = t6;
    $[61] = t8;
    $[62] = t30;
  } else {
    t30 = $[62];
  }
  return t30;
};
const iconArrow = "data:image/svg+xml,%3csvg%20width='9'%20height='16'%20viewBox='0%200%209%2016'%20fill='none'%20xmlns='http://www.w3.org/2000/svg'%3e%3cpath%20d='M7.75%201.5L1.25%208L7.75%2014.5'%20stroke='%23339AF0'%20stroke-width='1.5'%20stroke-linecap='round'%20stroke-linejoin='round'/%3e%3c/svg%3e";
const RegistrationControls = (t0) => {
  const $ = compilerRuntimeExports.c(33);
  const {
    active,
    nextStep,
    prevStep,
    handleClickButton,
    serviceEmail,
    classes,
    t,
    isSubmitting,
    isSaas,
    hasErrorsForCurrentStep
  } = t0;
  const isMobile = useMediaQuery("(max-width: 576px)");
  let t1;
  if ($[0] !== active || $[1] !== hasErrorsForCurrentStep || $[2] !== nextStep || $[3] !== t) {
    t1 = active === 0 && /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { size: "lg", w: "100%", onClick: nextStep, disabled: hasErrorsForCurrentStep, children: t("register.continue") });
    $[0] = active;
    $[1] = hasErrorsForCurrentStep;
    $[2] = nextStep;
    $[3] = t;
    $[4] = t1;
  } else {
    t1 = $[4];
  }
  let t2;
  if ($[5] !== active || $[6] !== classes.footerFormPrevButton || $[7] !== classes.iconArrow || $[8] !== classes.mailButton || $[9] !== handleClickButton || $[10] !== hasErrorsForCurrentStep || $[11] !== isMobile || $[12] !== isSaas || $[13] !== nextStep || $[14] !== prevStep || $[15] !== serviceEmail || $[16] !== t) {
    t2 = active === 1 && /* @__PURE__ */ jsxRuntimeExports.jsxs(Box, { sx: {
      width: "100%"
    }, children: [
      /* @__PURE__ */ jsxRuntimeExports.jsxs(SimpleGrid, { cols: isMobile ? 1 : 2, w: "100%", children: [
        /* @__PURE__ */ jsxRuntimeExports.jsxs(Button, { size: "lg", w: "100%", className: classes.footerFormPrevButton, variant: "default", onClick: prevStep, children: [
          /* @__PURE__ */ jsxRuntimeExports.jsx("img", { src: iconArrow, alt: "icon", className: classes.iconArrow }),
          t("register.back")
        ] }),
        /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { size: "lg", w: "100%", onClick: nextStep, disabled: hasErrorsForCurrentStep, children: t("register.continue") })
      ] }),
      isSaas ? /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { onClick: handleClickButton, className: classes.mailButton, variant: "subtle", size: "lg", w: "100%", children: serviceEmail ? t("register.useExistingEmail") : t("register.createNewEmail") }) : null
    ] });
    $[5] = active;
    $[6] = classes.footerFormPrevButton;
    $[7] = classes.iconArrow;
    $[8] = classes.mailButton;
    $[9] = handleClickButton;
    $[10] = hasErrorsForCurrentStep;
    $[11] = isMobile;
    $[12] = isSaas;
    $[13] = nextStep;
    $[14] = prevStep;
    $[15] = serviceEmail;
    $[16] = t;
    $[17] = t2;
  } else {
    t2 = $[17];
  }
  let t3;
  if ($[18] !== active || $[19] !== classes.footerFormPrevButton || $[20] !== classes.iconArrow || $[21] !== classes.registerButton || $[22] !== hasErrorsForCurrentStep || $[23] !== isMobile || $[24] !== isSubmitting || $[25] !== prevStep || $[26] !== t) {
    t3 = active === 2 && /* @__PURE__ */ jsxRuntimeExports.jsxs(SimpleGrid, { cols: isMobile ? 1 : 2, w: "100%", children: [
      /* @__PURE__ */ jsxRuntimeExports.jsxs(Button, { size: "lg", w: "100%", className: classes.footerFormPrevButton, variant: "default", onClick: prevStep, children: [
        /* @__PURE__ */ jsxRuntimeExports.jsx("img", { src: iconArrow, alt: "icon", className: classes.iconArrow }),
        t("register.back")
      ] }),
      /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { size: "lg", w: "100%", type: "submit", disabled: isSubmitting || hasErrorsForCurrentStep, className: classes.registerButton, children: t("register.register") })
    ] });
    $[18] = active;
    $[19] = classes.footerFormPrevButton;
    $[20] = classes.iconArrow;
    $[21] = classes.registerButton;
    $[22] = hasErrorsForCurrentStep;
    $[23] = isMobile;
    $[24] = isSubmitting;
    $[25] = prevStep;
    $[26] = t;
    $[27] = t3;
  } else {
    t3 = $[27];
  }
  let t4;
  if ($[28] !== classes.footerForm || $[29] !== t1 || $[30] !== t2 || $[31] !== t3) {
    t4 = /* @__PURE__ */ jsxRuntimeExports.jsxs(Group, { justify: "space-between", className: classes.footerForm, children: [
      t1,
      t2,
      t3
    ] });
    $[28] = classes.footerForm;
    $[29] = t1;
    $[30] = t2;
    $[31] = t3;
    $[32] = t4;
  } else {
    t4 = $[32];
  }
  return t4;
};
const limitsLengthRegistrationFields = {
  Company: 128
};
const RegistrationForm = ({
  passwordStrengthOptions,
  invitationData,
  invitationCode
}) => {
  var _a, _b;
  const {
    t
  } = useTranslation();
  const navigate = useNavigate();
  const {
    Settings
  } = useAppSelector((state) => state.userInfo);
  const [createClient] = useCreateClientMutation();
  const [checkEmailExists] = useLazyCheckEmailExistsQuery();
  const {
    classes
  } = useStyles();
  const isSaas = isSaaS(Settings);
  const [active, setActive] = reactExports.useState(0);
  const [serviceEmail, setServiceEmail] = reactExports.useState(isSaas);
  const [isSubmitting, setIsSubmitting] = reactExports.useState(false);
  const EMAIL_DOMAIN = "@" + (((_b = (_a = Settings == null ? void 0 : Settings.ModuleSettings) == null ? void 0 : _a.ModuleUrls.find((x) => x.Name == "Admin")) == null ? void 0 : _b.Url.replace("https://admin.", "").replace("http://admin.", "")) || "r7-space.ru");
  const passwordRulesZ = usePasswordSchema(passwordStrengthOptions || defaultMailServerPasswordOptions, t);
  const schema = objectType({
    FirstName: stringType().min(1, {
      message: t("register.nameShort")
    }),
    Surname: stringType().min(1, {
      message: t("register.surnameShort")
    }),
    Company: stringType().min(1, {
      message: t("register.companyShort")
    }).max(limitsLengthRegistrationFields.Company, {
      message: t("validation.maxLengthSymbolsWithCount.symbols", {
        count: limitsLengthRegistrationFields.Company
      })
    }),
    Email: stringType().max(255, {
      message: t("validation.maxLengthSymbolsWithCount.symbols", {
        count: 255
      })
    }).refine((data) => {
      if (serviceEmail) {
        return emailPrefixRegExp.test(data) && emailLastCharRegExp.test(data) && emailFirstCharRegExp.test(data);
      } else {
        return stringType().email({
          message: t("register.incorrectEmail")
        }).safeParse(data).success;
      }
    }, (data_0) => {
      if (serviceEmail) {
        if (!emailFirstCharRegExp.test(data_0)) {
          return {
            message: t("register.emailFirstChar")
          };
        }
        if (!emailPrefixRegExp.test(data_0)) {
          return {
            message: t("register.emailRules")
          };
        }
        if (!emailLastCharRegExp.test(data_0)) {
          return {
            message: t("register.emailLastChar")
          };
        }
        return {
          message: t("register.incorrectEmail")
        };
      } else {
        return {
          message: t("register.incorrectEmail")
        };
      }
    }),
    Password: passwordRulesZ,
    AgreementsConfirmedRule: booleanType().refine((value) => value, {
      message: t("register.agreementsConfirmedRule")
    })
  }).refine((data_1) => data_1.FirstName.length > 0, {
    message: t("register.requiredField"),
    path: ["FirstName"]
  }).refine((data_2) => data_2.Surname.length > 0, {
    message: t("register.requiredField"),
    path: ["Surname"]
  }).refine((data_3) => data_3.Email.length > 0, {
    message: t("register.requiredField"),
    path: ["Email"]
  }).refine((data_4) => data_4.Password.length > 0, {
    message: t("register.requiredField"),
    path: ["Password"]
  });
  const form = useForm({
    validate: zodResolver(schema),
    initialValues: {
      FirstName: "",
      Surname: "",
      Email: "",
      Password: "",
      Company: "",
      AgreementsConfirmedInfo: false,
      AgreementsConfirmedRule: false
    },
    validateInputOnChange: false
  });
  const appendDomain = (email, isServiceEmail) => {
    return isServiceEmail ? `${email}${EMAIL_DOMAIN}` : email;
  };
  const nextStep = async () => {
    const fieldsToValidate = getFieldsToValidate(active);
    let allFieldsValid = true;
    fieldsToValidate.forEach((field) => {
      const error = form.validateField(field);
      if (error.hasError) {
        allFieldsValid = false;
      }
    });
    if (allFieldsValid) {
      if (active === 1) {
        const emailToCheck = appendDomain(form.values.Email, serviceEmail);
        try {
          const result = await checkEmailExists({
            email: emailToCheck
          }).unwrap();
          if (result == null ? void 0 : result.ExistsUser) {
            showNotification({
              title: t("requestsErrors.error"),
              message: t("register.emailExists"),
              autoClose: true,
              color: "red"
            });
            return;
          }
        } catch (e) {
          showNotification({
            title: t("requestsErrors.error"),
            message: t("register.emailCheckError"),
            autoClose: true,
            color: "red"
          });
          return;
        }
      }
      setActive((current) => current < 2 ? current + 1 : current);
    }
  };
  const prevStep = () => {
    form.clearErrors();
    setActive((current_0) => current_0 > 0 ? current_0 - 1 : current_0);
  };
  function getFieldsToValidate(step) {
    const stepFields = {
      0: ["FirstName", "Surname", "Company"],
      1: ["Email"],
      2: ["Password"]
    };
    return stepFields[step] || [];
  }
  const handleClickButton = () => {
    setServiceEmail((current_1) => !current_1);
    form.setFieldValue("Email", "");
  };
  reactExports.useEffect(() => {
    if (invitationData) {
      form.setFieldValue("Company", invitationData.Company);
    }
  }, [invitationData]);
  const handleSubmit = async (values) => {
    try {
      const clientDat = {
        Alias: null,
        Domain: "",
        Company: values.Company,
        Owner: {
          FirstName: values.FirstName,
          Surname: values.Surname,
          Email: appendDomain(values.Email, serviceEmail),
          Password: values.Password,
          AgreementsConfirmedInfo: values.AgreementsConfirmedInfo,
          AgreementsConfirmedRule: values.AgreementsConfirmedRule
        }
      };
      if (invitationCode && invitationCode.length) {
        clientDat.Code = invitationCode;
      }
      setIsSubmitting(true);
      const res = await createClient(clientDat);
      if ("error" in res) {
        universalNotification({
          error: res.error,
          isError: true,
          isSuccess: false
        });
        setIsSubmitting(false);
      } else {
        showNotification({
          title: t("register.successRegister"),
          message: "",
          autoClose: true,
          color: "green",
          style: {
            zIndex: 1003
          }
        });
        navigate("/login");
        setIsSubmitting(false);
      }
    } catch (err) {
      setIsSubmitting(false);
    }
  };
  const handleChangePassword = (password) => {
    form.setFieldValue("Password", password.replace(/\s+/g, ""));
  };
  const hasErrorsForCurrentStep = () => {
    const fieldsToValidate_0 = getFieldsToValidate(active);
    return fieldsToValidate_0.some((field_0) => form.errors[field_0]);
  };
  return /* @__PURE__ */ jsxRuntimeExports.jsxs(Box, { className: classes.controls, component: "form", onSubmit: form.onSubmit(handleSubmit), children: [
    /* @__PURE__ */ jsxRuntimeExports.jsxs(Stepper, { active, onStepClick: setActive, children: [
      /* @__PURE__ */ jsxRuntimeExports.jsx(Stepper.Step, { withIcon: false, children: /* @__PURE__ */ jsxRuntimeExports.jsx(InfoStep, { form, classes, t, isDisableCompany: !!(invitationData == null ? void 0 : invitationData.Company.length) }) }),
      /* @__PURE__ */ jsxRuntimeExports.jsx(Stepper.Step, { withIcon: false, children: /* @__PURE__ */ jsxRuntimeExports.jsx(EmailStep, { form, serviceEmail, EMAIL_DOMAIN, classes, t }) }),
      /* @__PURE__ */ jsxRuntimeExports.jsx(Stepper.Step, { withIcon: false, children: /* @__PURE__ */ jsxRuntimeExports.jsx(PasswordStep, { form, passwordStrengthOptions, handleChangePassword, classes, t }) })
    ] }),
    /* @__PURE__ */ jsxRuntimeExports.jsx(RegistrationControls, { isSaas, active, nextStep, prevStep, handleClickButton, serviceEmail, classes, t, isSubmitting, hasErrorsForCurrentStep: hasErrorsForCurrentStep() })
  ] });
};
export {
  RegistrationForm as R
};
//# sourceMappingURL=RegistrationForm-CuW4XnXz.js.map
