import { u as useAtomValue, a as appConfig, q as useNavigate, t as React, j as jsxRuntimeExports, C as Container, c as CssBaseline, d as Box, e as Grow, F as FormControl, f as InputLabel, O as OutlinedInput, g as InputAdornment, I as IconButton, G as Grid, h as FormHelperText, B as Button, L as Link, b as axios, v as renderMessageBox } from "./index-D15x63tD.js";
import { W as WhereNavigate, V as VisibilityOff, a as Visibility } from "./SignIn-BbTs8zBq.js";
function RestorePassword(props) {
  var _a;
  const config = useAtomValue(appConfig);
  const navigate = useNavigate();
  document.title = "Восстановление пароля";
  const [error, setError] = React.useState("");
  const url = (_a = config.lk.url) == null ? void 0 : _a.changePassword;
  const [showpassword, setShowPassword] = React.useState({
    newPassword: false,
    newPasswordRepeat: false
  });
  const [token, setToken] = React.useState("");
  const [isRequestLoading, setIsRequestLoading] = React.useState(false);
  const handleClickShowPassword = (id) => {
    setShowPassword({ ...showpassword, [id]: !showpassword[id] });
  };
  React.useEffect(() => {
    const urlParams = new URLSearchParams(window.location.search);
    if (urlParams.has("token")) {
      setToken(urlParams.get("token"));
    } else {
      navigate(WhereNavigate());
    }
  }, []);
  const handleMouseDownPassword = (event) => {
    event.preventDefault();
  };
  const handleSubmit = (event) => {
    event.preventDefault();
    const data = new FormData(event.currentTarget);
    const LoginData = {
      Password: data.get("newPassword"),
      token,
      needOld: "no"
    };
    if (data.get("newPassword") === data.get("newPasswordRepeat")) {
      setIsRequestLoading(true);
      axios.post(url, JSON.stringify(LoginData)).then((response) => {
        setIsRequestLoading(false);
        if (response.data.status) {
          renderMessageBox({ dlgType: 2, buttons: 1, message: response.data.status });
        }
      });
    } else {
      setError("Указанные пароли не совпадают. Повторите попытку.");
    }
  };
  return /* @__PURE__ */ jsxRuntimeExports.jsxs(Container, { component: "main", maxWidth: "xs", children: [
    /* @__PURE__ */ jsxRuntimeExports.jsx(CssBaseline, {}),
    /* @__PURE__ */ jsxRuntimeExports.jsx(
      Box,
      {
        sx: {
          marginTop: 8,
          display: "flex",
          flexDirection: "column",
          alignItems: "center"
        },
        children: /* @__PURE__ */ jsxRuntimeExports.jsxs(Box, { component: "form", onSubmit: handleSubmit, noValidate: true, sx: { mt: 1 }, children: [
          /* @__PURE__ */ jsxRuntimeExports.jsx("img", { src: "logo.png", style: { marginLeft: "29%", width: "45%" } }),
          /* @__PURE__ */ jsxRuntimeExports.jsx(Grow, { in: true, timeout: 200, style: { transformOrigin: "0 0 0" }, children: /* @__PURE__ */ jsxRuntimeExports.jsxs(
            FormControl,
            {
              fullWidth: true,
              variant: "outlined",
              sx: {
                "& .MuiOutlinedInput-root": {
                  "&.Mui-focused fieldset": { borderColor: "#3c5b77" }
                },
                pb: 1
              },
              children: [
                /* @__PURE__ */ jsxRuntimeExports.jsx(InputLabel, { required: true, htmlFor: "password", sx: { "&.Mui-focused": { color: "#3c5b77" } }, children: "Новый пароль" }),
                /* @__PURE__ */ jsxRuntimeExports.jsx(
                  OutlinedInput,
                  {
                    autoComplete: "newPassword",
                    type: showpassword.newPassword ? "text" : "password",
                    fullWidth: true,
                    id: "newPassword",
                    label: "newPassword",
                    name: "newPassword",
                    endAdornment: /* @__PURE__ */ jsxRuntimeExports.jsx(InputAdornment, { position: "end", children: /* @__PURE__ */ jsxRuntimeExports.jsx(
                      IconButton,
                      {
                        id: "newPassword",
                        "aria-label": "toggle password visibility",
                        onClick: () => {
                          handleClickShowPassword("newPassword");
                        },
                        onMouseDown: handleMouseDownPassword,
                        edge: "end",
                        children: showpassword.newPassword ? /* @__PURE__ */ jsxRuntimeExports.jsx(VisibilityOff, { id: "newPassword" }) : /* @__PURE__ */ jsxRuntimeExports.jsx(Visibility, { id: "newPassword" })
                      }
                    ) })
                  }
                )
              ]
            }
          ) }),
          /* @__PURE__ */ jsxRuntimeExports.jsx(Grow, { in: true, timeout: 250, style: { transformOrigin: "0 0 0" }, children: /* @__PURE__ */ jsxRuntimeExports.jsxs(
            FormControl,
            {
              fullWidth: true,
              variant: "outlined",
              sx: {
                "& .MuiOutlinedInput-root": {
                  "&.Mui-focused fieldset": { borderColor: "#3c5b77" }
                }
              },
              children: [
                /* @__PURE__ */ jsxRuntimeExports.jsx(InputLabel, { required: true, htmlFor: "password", sx: { "&.Mui-focused": { color: "#3c5b77" } }, children: "Повторите пароль" }),
                /* @__PURE__ */ jsxRuntimeExports.jsx(
                  OutlinedInput,
                  {
                    autoComplete: "newPasswordRepeat",
                    type: showpassword.newPasswordRepeat ? "text" : "password",
                    fullWidth: true,
                    id: "newPasswordRepeat",
                    label: "newPasswordRepeat",
                    name: "newPasswordRepeat",
                    endAdornment: /* @__PURE__ */ jsxRuntimeExports.jsx(InputAdornment, { position: "end", children: /* @__PURE__ */ jsxRuntimeExports.jsx(
                      IconButton,
                      {
                        id: "newPasswordRepeat",
                        "aria-label": "toggle password visibility",
                        onClick: () => {
                          handleClickShowPassword("newPasswordRepeat");
                        },
                        onMouseDown: handleMouseDownPassword,
                        edge: "end",
                        children: showpassword.newPasswordRepeat ? /* @__PURE__ */ jsxRuntimeExports.jsx(VisibilityOff, { id: "newPasswordRepeat" }) : /* @__PURE__ */ jsxRuntimeExports.jsx(Visibility, { id: "newPasswordRepeat" })
                      }
                    ) })
                  }
                )
              ]
            }
          ) }),
          /* @__PURE__ */ jsxRuntimeExports.jsx(Grid, { item: true, xs: 12, children: /* @__PURE__ */ jsxRuntimeExports.jsx(FormHelperText, { error: true, children: error !== "" ? `${error}` : "" }) }),
          /* @__PURE__ */ jsxRuntimeExports.jsx(Grow, { in: true, timeout: 280, style: { transformOrigin: "0 0 0" }, children: /* @__PURE__ */ jsxRuntimeExports.jsxs(Grid, { children: [
            /* @__PURE__ */ jsxRuntimeExports.jsx(
              Button,
              {
                style: { backgroundColor: "#3c5b77", textTransform: "none" },
                type: "submit",
                fullWidth: true,
                variant: "contained",
                sx: { mt: 3, mb: 2 },
                disabled: isRequestLoading,
                children: "Сохранить"
              }
            ),
            /* @__PURE__ */ jsxRuntimeExports.jsx(Grid, { container: true, justifyContent: "center", alignItems: "center", children: /* @__PURE__ */ jsxRuntimeExports.jsx(Grid, { item: true, children: /* @__PURE__ */ jsxRuntimeExports.jsx(Link, { className: "LinkLK", to: WhereNavigate(), children: "Вернутся на страницу входа" }) }) })
          ] }) })
        ] })
      }
    )
  ] });
}
export {
  RestorePassword as default
};
//# sourceMappingURL=RestorePassword-CHcueK5R.js.map
