import { E as compilerRuntimeExports, r as reactExports, j as jsxRuntimeExports } from "./vendor-react-DYNCg6N5.js";
import { c as useAppSelector } from "./index-DfebxkL9.js";
import { g as getValidateErrors } from "./validation-Ds00Zghx.js";
import { u as useStyles } from "./styles-rKP3r-bS.js";
import { z as useForm, T as Text, ah as Grid, E as TextInput, ad as NumberInput, d as Checkbox, J as PasswordInput, B as Button, F as Flex, b as Box } from "./vendor-mantine-h0WlM2Mj.js";
import { o as objectType, b as booleanType, s as stringType, n as numberType, l as literalType, u as unionType } from "./types-espwwxTQ.js";
import "./vendor-i18n-wisIXUFi.js";
import "./vendor-icons-xWhXK_Ui.js";
import "./styles-3NoIlzov.js";
const basicSchema = objectType({
  host: stringType().min(1, {
    message: "Введите хост"
  }),
  port: numberType({
    required_error: "Введите порт",
    invalid_type_error: "Порт должен быть числом"
  }).positive({
    message: "Должен быть положительным"
  }).lt(65536, {
    message: "Должен быть меньше 65536"
  }),
  senderName: stringType().optional(),
  senderAddress: stringType().email({
    message: "Введите адрес отправителя"
  }),
  useSSL: booleanType().optional()
});
const noAuthSchema = basicSchema.extend({
  authentication: literalType(false),
  login: literalType(""),
  password: literalType("")
});
const authSchema = basicSchema.extend({
  authentication: booleanType(),
  login: stringType().min(1, {
    message: "Введите логин"
  }),
  password: stringType().min(1, {
    message: "Введите пароль"
  })
});
const validateScheme = unionType([noAuthSchema, authSchema]);
const SMTPPage = () => {
  const $ = compilerRuntimeExports.c(89);
  const {
    classes
  } = useStyles();
  const {
    filial
  } = useAppSelector(_temp);
  let t0;
  if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
    t0 = {
      initialValues: {
        host: "",
        authentication: false,
        login: "",
        password: "",
        senderName: "",
        senderAddress: "",
        useSSL: false
      },
      validateInputOnChange: true,
      validate: _temp2
    };
    $[0] = t0;
  } else {
    t0 = $[0];
  }
  const form = useForm(t0);
  let t1;
  if ($[1] !== (filial == null ? void 0 : filial.Settings) || $[2] !== form) {
    t1 = () => {
      const {
        Smtp
      } = (filial == null ? void 0 : filial.Settings) || {};
      if (!Smtp) {
        return;
      }
      form.setValues({
        host: Smtp.Host,
        port: Smtp.Port,
        login: Smtp.Login,
        password: Smtp.Password,
        senderName: Smtp.ViewUserName,
        senderAddress: Smtp.SenderAddres
      });
    };
    $[1] = filial == null ? void 0 : filial.Settings;
    $[2] = form;
    $[3] = t1;
  } else {
    t1 = $[3];
  }
  let t2;
  if ($[4] !== filial) {
    t2 = [filial];
    $[4] = filial;
    $[5] = t2;
  } else {
    t2 = $[5];
  }
  reactExports.useEffect(t1, t2);
  let t3;
  if ($[6] !== filial) {
    t3 = () => {
      if (!filial) {
        return;
      }
    };
    $[6] = filial;
    $[7] = t3;
  } else {
    t3 = $[7];
  }
  const handleSubmit = t3;
  const t4 = classes.container;
  const t5 = classes.section;
  let t6;
  if ($[8] !== form || $[9] !== handleSubmit) {
    t6 = form.onSubmit(handleSubmit);
    $[8] = form;
    $[9] = handleSubmit;
    $[10] = t6;
  } else {
    t6 = $[10];
  }
  let t7;
  if ($[11] !== classes.title) {
    t7 = /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { className: classes.title, my: "sm", children: "Настройка SMTP" });
    $[11] = classes.title;
    $[12] = t7;
  } else {
    t7 = $[12];
  }
  const t8 = classes.textFieldInput;
  let t9;
  if ($[13] !== form) {
    t9 = form.getInputProps("host");
    $[13] = form;
    $[14] = t9;
  } else {
    t9 = $[14];
  }
  let t10;
  if ($[15] !== classes.textFieldInput || $[16] !== t9) {
    t10 = /* @__PURE__ */ jsxRuntimeExports.jsx(Grid.Col, { span: 5, children: /* @__PURE__ */ jsxRuntimeExports.jsx(TextInput, { className: t8, label: "Хост", withAsterisk: true, ...t9 }) });
    $[15] = classes.textFieldInput;
    $[16] = t9;
    $[17] = t10;
  } else {
    t10 = $[17];
  }
  const t11 = classes.textFieldInput;
  let t12;
  if ($[18] !== form) {
    t12 = form.getInputProps("port");
    $[18] = form;
    $[19] = t12;
  } else {
    t12 = $[19];
  }
  let t13;
  if ($[20] !== classes.textFieldInput || $[21] !== t12) {
    t13 = /* @__PURE__ */ jsxRuntimeExports.jsx(Grid.Col, { span: 2, children: /* @__PURE__ */ jsxRuntimeExports.jsx(NumberInput, { autoComplete: "off", className: t11, label: "Порт", hideControls: true, withAsterisk: true, ...t12 }) });
    $[20] = classes.textFieldInput;
    $[21] = t12;
    $[22] = t13;
  } else {
    t13 = $[22];
  }
  const t14 = classes.checkbox;
  let t15;
  if ($[23] !== form) {
    t15 = form.getInputProps("authentication");
    $[23] = form;
    $[24] = t15;
  } else {
    t15 = $[24];
  }
  let t16;
  if ($[25] !== classes.checkbox || $[26] !== t15) {
    t16 = /* @__PURE__ */ jsxRuntimeExports.jsx(Grid.Col, { span: 10, children: /* @__PURE__ */ jsxRuntimeExports.jsx(Checkbox, { className: t14, label: "Аутентификация", size: "xs", ...t15 }) });
    $[25] = classes.checkbox;
    $[26] = t15;
    $[27] = t16;
  } else {
    t16 = $[27];
  }
  const t17 = classes.textFieldInput;
  let t18;
  if ($[28] !== form) {
    t18 = form.getTransformedValues();
    $[28] = form;
    $[29] = t18;
  } else {
    t18 = $[29];
  }
  const t19 = !t18.authentication;
  let t20;
  if ($[30] !== form) {
    t20 = form.getInputProps("login");
    $[30] = form;
    $[31] = t20;
  } else {
    t20 = $[31];
  }
  let t21;
  if ($[32] !== classes.textFieldInput || $[33] !== t19 || $[34] !== t20) {
    t21 = /* @__PURE__ */ jsxRuntimeExports.jsx(Grid.Col, { span: 5, children: /* @__PURE__ */ jsxRuntimeExports.jsx(TextInput, { className: t17, label: "Логин", withAsterisk: true, disabled: t19, ...t20 }) });
    $[32] = classes.textFieldInput;
    $[33] = t19;
    $[34] = t20;
    $[35] = t21;
  } else {
    t21 = $[35];
  }
  const t22 = classes.textFieldInput;
  let t23;
  if ($[36] !== form) {
    t23 = form.getTransformedValues();
    $[36] = form;
    $[37] = t23;
  } else {
    t23 = $[37];
  }
  const t24 = !t23.authentication;
  let t25;
  if ($[38] !== form) {
    t25 = form.getInputProps("password");
    $[38] = form;
    $[39] = t25;
  } else {
    t25 = $[39];
  }
  let t26;
  if ($[40] !== classes.textFieldInput || $[41] !== t24 || $[42] !== t25) {
    t26 = /* @__PURE__ */ jsxRuntimeExports.jsx(Grid.Col, { span: 5, children: /* @__PURE__ */ jsxRuntimeExports.jsx(PasswordInput, { className: t22, label: "Пароль", withAsterisk: true, disabled: t24, ...t25 }) });
    $[40] = classes.textFieldInput;
    $[41] = t24;
    $[42] = t25;
    $[43] = t26;
  } else {
    t26 = $[43];
  }
  const t27 = classes.textFieldInput;
  let t28;
  if ($[44] !== form) {
    t28 = form.getInputProps("senderName");
    $[44] = form;
    $[45] = t28;
  } else {
    t28 = $[45];
  }
  let t29;
  if ($[46] !== classes.textFieldInput || $[47] !== t28) {
    t29 = /* @__PURE__ */ jsxRuntimeExports.jsx(Grid.Col, { span: 5, children: /* @__PURE__ */ jsxRuntimeExports.jsx(TextInput, { className: t27, label: "Отображаемое имя отправителя", ...t28 }) });
    $[46] = classes.textFieldInput;
    $[47] = t28;
    $[48] = t29;
  } else {
    t29 = $[48];
  }
  const t30 = classes.textFieldInput;
  let t31;
  if ($[49] !== form) {
    t31 = form.getInputProps("senderAddress");
    $[49] = form;
    $[50] = t31;
  } else {
    t31 = $[50];
  }
  let t32;
  if ($[51] !== classes.textFieldInput || $[52] !== t31) {
    t32 = /* @__PURE__ */ jsxRuntimeExports.jsx(Grid.Col, { span: 5, children: /* @__PURE__ */ jsxRuntimeExports.jsx(TextInput, { className: t30, label: "Адрес email отправителя", withAsterisk: true, ...t31 }) });
    $[51] = classes.textFieldInput;
    $[52] = t31;
    $[53] = t32;
  } else {
    t32 = $[53];
  }
  const t33 = classes.checkbox;
  let t34;
  if ($[54] !== form) {
    t34 = form.getInputProps("useSSL");
    $[54] = form;
    $[55] = t34;
  } else {
    t34 = $[55];
  }
  let t35;
  if ($[56] !== classes.checkbox || $[57] !== t34) {
    t35 = /* @__PURE__ */ jsxRuntimeExports.jsx(Grid.Col, { span: 10, children: /* @__PURE__ */ jsxRuntimeExports.jsx(Checkbox, { className: t33, label: "Использовать SSL", size: "xs", ...t34 }) });
    $[56] = classes.checkbox;
    $[57] = t34;
    $[58] = t35;
  } else {
    t35 = $[58];
  }
  let t36;
  if ($[59] !== t10 || $[60] !== t13 || $[61] !== t16 || $[62] !== t21 || $[63] !== t26 || $[64] !== t29 || $[65] !== t32 || $[66] !== t35) {
    t36 = /* @__PURE__ */ jsxRuntimeExports.jsxs(Grid, { columns: 10, children: [
      t10,
      t13,
      t16,
      t21,
      t26,
      t29,
      t32,
      t35
    ] });
    $[59] = t10;
    $[60] = t13;
    $[61] = t16;
    $[62] = t21;
    $[63] = t26;
    $[64] = t29;
    $[65] = t32;
    $[66] = t35;
    $[67] = t36;
  } else {
    t36 = $[67];
  }
  let t37;
  let t38;
  if ($[68] !== classes.description) {
    t37 = /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { className: classes.description, mt: "sm", children: "Настройки SMTP нужны для того чтобы задать учетную запись электронной почты, которая будет служить для отправки оповещений с портала с помощью вашего собственного SMTP-сервера вместо используемого Р7-Демо по умолчанию. Пожалуйста, заполните все поля и нажмите на кнопку Сохранить. Вы можете использовать кнопку Тестовое письмо, чтобы проверить, все ли параметры введены правильно и всё ли работает как полагается." });
    t38 = /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { className: classes.description, mt: "sm", children: "Если Вы используете учетную запись Gmail в качестве SMTP-сервера, Вы не сможете отправлять почту, пока не выполните следующие действия: войдите в аккаунт Gmail через стандартный веб-интерфейс и подтвердите запросы на проверку о попытке доступа Р7-Демо к вашему аккаунту, если они есть. Также необходимо сгенерировать пароль приложения в настройках безопасности на странице My Google Account (этот пароль можно использовать, только если включена двухэтапная верификация).Для отправки сообщений рекомендуется использовать порты 587 или 25, поскольку другие значения могут препятствовать правильной работе SMTP." });
    $[68] = classes.description;
    $[69] = t37;
    $[70] = t38;
  } else {
    t37 = $[69];
    t38 = $[70];
  }
  let t39;
  if ($[71] !== form) {
    t39 = form.isValid();
    $[71] = form;
    $[72] = t39;
  } else {
    t39 = $[72];
  }
  const t40 = !t39;
  let t41;
  if ($[73] === Symbol.for("react.memo_cache_sentinel")) {
    t41 = {
      width: "20%"
    };
    $[73] = t41;
  } else {
    t41 = $[73];
  }
  let t42;
  if ($[74] !== t40) {
    t42 = /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { type: "submit", size: "sm", radius: 8, disabled: t40, mt: "md", style: t41, children: "Сохранить" });
    $[74] = t40;
    $[75] = t42;
  } else {
    t42 = $[75];
  }
  let t43;
  if ($[76] !== t36 || $[77] !== t37 || $[78] !== t38 || $[79] !== t42 || $[80] !== t6 || $[81] !== t7) {
    t43 = /* @__PURE__ */ jsxRuntimeExports.jsxs("form", { onSubmit: t6, children: [
      t7,
      t36,
      t37,
      t38,
      t42
    ] });
    $[76] = t36;
    $[77] = t37;
    $[78] = t38;
    $[79] = t42;
    $[80] = t6;
    $[81] = t7;
    $[82] = t43;
  } else {
    t43 = $[82];
  }
  let t44;
  if ($[83] !== classes.section || $[84] !== t43) {
    t44 = /* @__PURE__ */ jsxRuntimeExports.jsx(Flex, { className: t5, align: "flex-start", direction: "column", px: "sm", pb: "md", children: t43 });
    $[83] = classes.section;
    $[84] = t43;
    $[85] = t44;
  } else {
    t44 = $[85];
  }
  let t45;
  if ($[86] !== classes.container || $[87] !== t44) {
    t45 = /* @__PURE__ */ jsxRuntimeExports.jsx(Box, { className: t4, children: t44 });
    $[86] = classes.container;
    $[87] = t44;
    $[88] = t45;
  } else {
    t45 = $[88];
  }
  return t45;
};
function _temp(state) {
  return state.filials;
}
function _temp2(values) {
  return getValidateErrors(validateScheme, values);
}
export {
  SMTPPage as default
};
//# sourceMappingURL=index-CUoIuKcD.js.map
