import { r as reactExports, E as compilerRuntimeExports, j as jsxRuntimeExports } from "./vendor-react-DYNCg6N5.js";
import { u as useStyles } from "./styles-CGXtrnyw.js";
import { cO as useLazySyncTeamSettingsQuery, c as useAppSelector, m as universalNotification } from "./index-DfebxkL9.js";
import { g as getValidateErrors } from "./validation-Ds00Zghx.js";
import { u as useSaveCommonSettings, I as ICommonSettingsEnum } from "./useSaveCommonSettings-DdirtcwG.js";
import { C as CommonSectionTemplate } from "./index-BRmgVx8q.js";
import { l as lG, m as Dze } from "./vendor-icons-xWhXK_Ui.js";
import { s as showNotification, z as useForm, W as useMediaQuery, a0 as SimpleGrid, E as TextInput, T as Text, B as Button, R as Radio, F as Flex, b as Box } from "./vendor-mantine-h0WlM2Mj.js";
import { c as copyToClipboard } from "./utils-D5kCyTRM.js";
import { u as useTranslation } from "./vendor-i18n-wisIXUFi.js";
import { o as objectType, s as stringType, l as literalType, u as unionType } from "./types-espwwxTQ.js";
import "./types-B9VC9FeZ.js";
const useTeamSettingsSync = () => {
  const [teamSync, {
    isLoading: isTeamSync
  }] = useLazySyncTeamSettingsQuery();
  const SyncTeamSettings = reactExports.useCallback(async () => {
    var _a;
    try {
      const res = await teamSync();
      if ("error" in res) {
        showNotification({
          title: `${(_a = res == null ? void 0 : res.error) == null ? void 0 : _a.data}`,
          message: "",
          autoClose: true,
          color: "red"
        });
      } else {
        showNotification({
          title: `Сихронизация запущена!`,
          message: "",
          autoClose: true,
          color: "green"
        });
      }
    } catch (err) {
      console.warn("Ошибка синхронезации", err);
    }
  }, [teamSync]);
  return {
    SyncTeamSettings,
    isTeamSync
  };
};
const IntegrationsPage = () => {
  var _a, _b, _c, _d, _e;
  const $ = compilerRuntimeExports.c(96);
  const {
    classes
  } = useStyles();
  const {
    t
  } = useTranslation();
  const {
    TeamSettings
  } = useAppSelector(_temp);
  const updateSettings = useSaveCommonSettings();
  const {
    isTeamSync,
    SyncTeamSettings
  } = useTeamSettingsSync();
  let t0;
  if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
    const enabledScheme = objectType({
      IsEnabled: literalType(true),
      Url: stringType().min(1, {
        message: "Введите ссылку"
      })
    });
    const disabledScheme = objectType({
      IsEnabled: literalType(false),
      Url: stringType().nullable()
    });
    t0 = unionType([enabledScheme, disabledScheme]);
    $[0] = t0;
  } else {
    t0 = $[0];
  }
  const validateScheme = t0;
  let t1;
  if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
    t1 = {
      IsEnabled: false,
      Url: "",
      ClientId: "",
      ClientSecret: "",
      RabbitData: null
    };
    $[1] = t1;
  } else {
    t1 = $[1];
  }
  let t2;
  if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
    t2 = {
      initialValues: t1,
      validateInputOnChange: true,
      validate: (values) => getValidateErrors(validateScheme, values)
    };
    $[2] = t2;
  } else {
    t2 = $[2];
  }
  const form = useForm(t2);
  const errors = form.errors;
  let t3;
  if ($[3] !== form) {
    t3 = form.isDirty();
    $[3] = form;
    $[4] = t3;
  } else {
    t3 = $[4];
  }
  const isDirtyForm = t3;
  let t4;
  if ($[5] !== errors || $[6] !== isDirtyForm) {
    t4 = Object.keys(errors || {}).length !== 0 || !isDirtyForm;
    $[5] = errors;
    $[6] = isDirtyForm;
    $[7] = t4;
  } else {
    t4 = $[7];
  }
  const isDisabled = t4;
  const isMobile = useMediaQuery("(max-width: 576px)");
  const [copiedField, setCopiedField] = reactExports.useState(null);
  let t5;
  if ($[8] !== TeamSettings || $[9] !== form) {
    t5 = () => {
      if (TeamSettings) {
        const formData = {
          Url: (TeamSettings == null ? void 0 : TeamSettings.Url) || "",
          IsEnabled: (TeamSettings == null ? void 0 : TeamSettings.IsEnabled) || false,
          ClientId: (TeamSettings == null ? void 0 : TeamSettings.ClientId) || "",
          ClientSecret: (TeamSettings == null ? void 0 : TeamSettings.ClientSecret) || "",
          RabbitData: (TeamSettings == null ? void 0 : TeamSettings.RabbitData) || null
        };
        form.setValues(formData);
        form.resetDirty(formData);
      }
    };
    $[8] = TeamSettings;
    $[9] = form;
    $[10] = t5;
  } else {
    t5 = $[10];
  }
  let t6;
  if ($[11] !== TeamSettings) {
    t6 = [TeamSettings];
    $[11] = TeamSettings;
    $[12] = t6;
  } else {
    t6 = $[12];
  }
  reactExports.useEffect(t5, t6);
  let t7;
  if ($[13] !== (TeamSettings == null ? void 0 : TeamSettings.ClientId) || $[14] !== (TeamSettings == null ? void 0 : TeamSettings.ClientSecret) || $[15] !== (TeamSettings == null ? void 0 : TeamSettings.RabbitData) || $[16] !== (TeamSettings == null ? void 0 : TeamSettings.Url) || $[17] !== updateSettings) {
    t7 = async (values_0) => {
      await updateSettings(ICommonSettingsEnum.Commands, {
        TeamSettings: {
          IsEnabled: values_0.IsEnabled,
          Url: values_0.IsEnabled ? values_0.Url : (TeamSettings == null ? void 0 : TeamSettings.Url) || "",
          ClientId: values_0.IsEnabled ? values_0.ClientId : (TeamSettings == null ? void 0 : TeamSettings.ClientId) || "",
          ClientSecret: values_0.IsEnabled ? values_0.ClientSecret : (TeamSettings == null ? void 0 : TeamSettings.ClientSecret) || "",
          RabbitData: values_0.IsEnabled ? values_0.RabbitData : (TeamSettings == null ? void 0 : TeamSettings.RabbitData) || null
        }
      });
    };
    $[13] = TeamSettings == null ? void 0 : TeamSettings.ClientId;
    $[14] = TeamSettings == null ? void 0 : TeamSettings.ClientSecret;
    $[15] = TeamSettings == null ? void 0 : TeamSettings.RabbitData;
    $[16] = TeamSettings == null ? void 0 : TeamSettings.Url;
    $[17] = updateSettings;
    $[18] = t7;
  } else {
    t7 = $[18];
  }
  const handleSubmit = t7;
  let t8;
  if ($[19] !== t) {
    t8 = async (textToCopy, field) => {
      if (textToCopy) {
        try {
          await copyToClipboard(textToCopy);
          setCopiedField(field);
          universalNotification({
            isError: false,
            error: null,
            isSuccess: true,
            successTitle: t("copied")
          });
        } catch (t92) {
          setCopiedField(null);
        }
      }
    };
    $[19] = t;
    $[20] = t8;
  } else {
    t8 = $[20];
  }
  const copyText = t8;
  let t9;
  if ($[21] !== copiedField) {
    t9 = (field_0) => copiedField === field_0 ? "teal" : "blue";
    $[21] = copiedField;
    $[22] = t9;
  } else {
    t9 = $[22];
  }
  const getColor = t9;
  let t10;
  if ($[23] !== form) {
    t10 = () => {
      var _a2;
      setCopiedField(null);
      if (!((_a2 = form.values.Url) == null ? void 0 : _a2.length)) {
        form.setValues({
          IsEnabled: false,
          Url: "",
          ClientId: "",
          ClientSecret: ""
        });
      } else {
        form.setValues({
          IsEnabled: false
        });
      }
    };
    $[23] = form;
    $[24] = t10;
  } else {
    t10 = $[24];
  }
  const handleChange = t10;
  let t11;
  if ($[25] !== SyncTeamSettings || $[26] !== TeamSettings) {
    t11 = async () => {
      if (TeamSettings) {
        await SyncTeamSettings();
      }
    };
    $[25] = SyncTeamSettings;
    $[26] = TeamSettings;
    $[27] = t11;
  } else {
    t11 = $[27];
  }
  const handleRefresh = t11;
  let t12;
  if ($[28] !== t) {
    t12 = t("team");
    $[28] = t;
    $[29] = t12;
  } else {
    t12 = $[29];
  }
  let t13;
  if ($[30] === Symbol.for("react.memo_cache_sentinel")) {
    t13 = {
      width: "100%"
    };
    $[30] = t13;
  } else {
    t13 = $[30];
  }
  let t14;
  if ($[31] !== form || $[32] !== handleSubmit) {
    t14 = form.onSubmit(handleSubmit);
    $[31] = form;
    $[32] = handleSubmit;
    $[33] = t14;
  } else {
    t14 = $[33];
  }
  const t15 = classes.radio;
  const t16 = !((_a = form == null ? void 0 : form.values) == null ? void 0 : _a.IsEnabled);
  let t17;
  if ($[34] !== handleChange) {
    t17 = () => handleChange();
    $[34] = handleChange;
    $[35] = t17;
  } else {
    t17 = $[35];
  }
  let t18;
  if ($[36] !== t) {
    t18 = t("disable");
    $[36] = t;
    $[37] = t18;
  } else {
    t18 = $[37];
  }
  let t19;
  if ($[38] !== classes.radio || $[39] !== t16 || $[40] !== t17 || $[41] !== t18) {
    t19 = /* @__PURE__ */ jsxRuntimeExports.jsx(Radio, { className: t15, size: "xs", checked: t16, onChange: t17, label: t18 });
    $[38] = classes.radio;
    $[39] = t16;
    $[40] = t17;
    $[41] = t18;
    $[42] = t19;
  } else {
    t19 = $[42];
  }
  const t20 = classes.radio;
  const t21 = (_b = form == null ? void 0 : form.values) == null ? void 0 : _b.IsEnabled;
  let t22;
  if ($[43] !== form) {
    t22 = () => form.setValues({
      IsEnabled: true
    });
    $[43] = form;
    $[44] = t22;
  } else {
    t22 = $[44];
  }
  let t23;
  if ($[45] !== t) {
    t23 = t("enable");
    $[45] = t;
    $[46] = t23;
  } else {
    t23 = $[46];
  }
  let t24;
  if ($[47] !== classes.radio || $[48] !== t21 || $[49] !== t22 || $[50] !== t23) {
    t24 = /* @__PURE__ */ jsxRuntimeExports.jsx(Radio, { className: t20, size: "xs", mb: "sm", checked: t21, onChange: t22, label: t23 });
    $[47] = classes.radio;
    $[48] = t21;
    $[49] = t22;
    $[50] = t23;
    $[51] = t24;
  } else {
    t24 = $[51];
  }
  let t25;
  if ($[52] !== classes.clientContainer || $[53] !== classes.copyInput || $[54] !== classes.textFieldInput || $[55] !== copyText || $[56] !== form || $[57] !== getColor || $[58] !== isMobile || $[59] !== t) {
    t25 = ((_c = form == null ? void 0 : form.values) == null ? void 0 : _c.IsEnabled) ? /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
      /* @__PURE__ */ jsxRuntimeExports.jsx(SimpleGrid, { cols: isMobile ? 1 : 2, w: "100%", className: classes.clientContainer, children: /* @__PURE__ */ jsxRuntimeExports.jsx(TextInput, { className: classes.textFieldInput, label: t("link"), withAsterisk: true, ...form.getInputProps("Url") }) }),
      /* @__PURE__ */ jsxRuntimeExports.jsxs(SimpleGrid, { cols: isMobile ? 1 : 2, w: "100%", className: classes.clientContainer, children: [
        /* @__PURE__ */ jsxRuntimeExports.jsx(TextInput, { label: "ClientId", className: classes.textFieldInput, classNames: {
          input: classes.copyInput
        }, rightSection: /* @__PURE__ */ jsxRuntimeExports.jsx(lG, { cursor: "pointer", color: getColor("ClientId"), onClick: () => copyText(form.values.ClientId, "ClientId") }), readOnly: true, "data-cy": "clientId", ...form.getInputProps("ClientId") }),
        /* @__PURE__ */ jsxRuntimeExports.jsx(TextInput, { label: "ClientSecret", className: classes.textFieldInput, classNames: {
          input: classes.copyInput
        }, rightSection: /* @__PURE__ */ jsxRuntimeExports.jsx(lG, { cursor: "pointer", color: getColor("ClientSecret"), onClick: () => copyText(form.values.ClientSecret, "ClientSecret") }), readOnly: true, "data-cy": "clientSecret", ...form.getInputProps("ClientSecret") })
      ] })
    ] }) : null;
    $[52] = classes.clientContainer;
    $[53] = classes.copyInput;
    $[54] = classes.textFieldInput;
    $[55] = copyText;
    $[56] = form;
    $[57] = getColor;
    $[58] = isMobile;
    $[59] = t;
    $[60] = t25;
  } else {
    t25 = $[60];
  }
  let t26;
  if ($[61] !== classes.clientContainer || $[62] !== classes.copyInput || $[63] !== classes.textFieldInput || $[64] !== copyText || $[65] !== form || $[66] !== getColor || $[67] !== isMobile || $[68] !== t) {
    t26 = ((_d = form == null ? void 0 : form.values) == null ? void 0 : _d.IsEnabled) && ((_e = form.values) == null ? void 0 : _e.RabbitData) !== null ? /* @__PURE__ */ jsxRuntimeExports.jsxs(SimpleGrid, { cols: isMobile ? 1 : 2, w: "100%", className: classes.clientContainer, children: [
      /* @__PURE__ */ jsxRuntimeExports.jsx(TextInput, { label: t("teams.rabbitUser"), className: classes.textFieldInput, classNames: {
        input: classes.copyInput
      }, rightSection: /* @__PURE__ */ jsxRuntimeExports.jsx(lG, { cursor: "pointer", color: getColor("RabbitData.Name"), onClick: () => {
        var _a2, _b2;
        return copyText(((_b2 = (_a2 = form.values) == null ? void 0 : _a2.RabbitData) == null ? void 0 : _b2.Name) ?? "", "RabbitData.Name");
      } }), readOnly: true, "data-cy": "rabbitUser", ...form.getInputProps("RabbitData.Name") }),
      /* @__PURE__ */ jsxRuntimeExports.jsx(TextInput, { label: t("teams.rabbitPassword"), className: classes.textFieldInput, classNames: {
        input: classes.copyInput
      }, rightSection: /* @__PURE__ */ jsxRuntimeExports.jsx(lG, { cursor: "pointer", color: getColor("RabbitData.Password"), onClick: () => {
        var _a2, _b2;
        return copyText(((_b2 = (_a2 = form.values) == null ? void 0 : _a2.RabbitData) == null ? void 0 : _b2.Password) ?? "", "RabbitData.Password");
      } }), readOnly: true, "data-cy": "rabbitPassword", ...form.getInputProps("RabbitData.Password") })
    ] }) : /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { size: "sm", c: "#667085", mt: "sm", children: t("teams.rabbitInfo") });
    $[61] = classes.clientContainer;
    $[62] = classes.copyInput;
    $[63] = classes.textFieldInput;
    $[64] = copyText;
    $[65] = form;
    $[66] = getColor;
    $[67] = isMobile;
    $[68] = t;
    $[69] = t26;
  } else {
    t26 = $[69];
  }
  const t27 = classes.sectionControls;
  const t28 = classes.submitButton;
  let t29;
  if ($[70] !== t) {
    t29 = t("save");
    $[70] = t;
    $[71] = t29;
  } else {
    t29 = $[71];
  }
  let t30;
  if ($[72] !== classes.submitButton || $[73] !== isDisabled || $[74] !== t29) {
    t30 = /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { disabled: isDisabled, className: t28, size: "sm", radius: 8, type: "submit", mt: "md", children: t29 });
    $[72] = classes.submitButton;
    $[73] = isDisabled;
    $[74] = t29;
    $[75] = t30;
  } else {
    t30 = $[75];
  }
  let t31;
  if ($[76] !== (TeamSettings == null ? void 0 : TeamSettings.IsEnabled) || $[77] !== classes.rotate || $[78] !== handleRefresh || $[79] !== isTeamSync || $[80] !== t) {
    t31 = (TeamSettings == null ? void 0 : TeamSettings.IsEnabled) ? /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { size: "sm", radius: 8, color: "green", mt: "md", rightSection: /* @__PURE__ */ jsxRuntimeExports.jsx(Dze, { size: 24, className: isTeamSync ? classes.rotate : "" }), onClick: () => handleRefresh(), disabled: isTeamSync, children: t("sync") }) : null;
    $[76] = TeamSettings == null ? void 0 : TeamSettings.IsEnabled;
    $[77] = classes.rotate;
    $[78] = handleRefresh;
    $[79] = isTeamSync;
    $[80] = t;
    $[81] = t31;
  } else {
    t31 = $[81];
  }
  let t32;
  if ($[82] !== classes.sectionControls || $[83] !== t30 || $[84] !== t31) {
    t32 = /* @__PURE__ */ jsxRuntimeExports.jsxs(Flex, { className: t27, w: "100%", children: [
      t30,
      t31
    ] });
    $[82] = classes.sectionControls;
    $[83] = t30;
    $[84] = t31;
    $[85] = t32;
  } else {
    t32 = $[85];
  }
  let t33;
  if ($[86] !== t14 || $[87] !== t19 || $[88] !== t24 || $[89] !== t25 || $[90] !== t26 || $[91] !== t32) {
    t33 = /* @__PURE__ */ jsxRuntimeExports.jsx(Box, { sx: t13, children: /* @__PURE__ */ jsxRuntimeExports.jsxs("form", { onSubmit: t14, children: [
      t19,
      t24,
      t25,
      t26,
      t32
    ] }) });
    $[86] = t14;
    $[87] = t19;
    $[88] = t24;
    $[89] = t25;
    $[90] = t26;
    $[91] = t32;
    $[92] = t33;
  } else {
    t33 = $[92];
  }
  let t34;
  if ($[93] !== t12 || $[94] !== t33) {
    t34 = /* @__PURE__ */ jsxRuntimeExports.jsx(CommonSectionTemplate, { title: t12, children: t33 });
    $[93] = t12;
    $[94] = t33;
    $[95] = t34;
  } else {
    t34 = $[95];
  }
  return t34;
};
function _temp(state) {
  return state.commonSettings;
}
export {
  IntegrationsPage as default
};
//# sourceMappingURL=index-BcFqSuPN.js.map
