import { clearStoredPath } from "../../utilities/redirect/LocalRedirectUrlStorage.mjs";
import React, { useEffect, useState } from "react";
//#region src/routes/components/PasswordResetRedirect.jsx
const PasswordResetRedirect = (props) => {
	const [errorDescription, setErrorDescription] = useState(null);
	useEffect(() => {
		const hash = window.location.hash || "";
		if (props?.error?.errorMessage) formatError(props?.error?.errorMessage);
		else if (hash) {
			const errorDescription_0 = new URLSearchParams(hash.substring(1)).get("error_description");
			if (errorDescription_0) formatError(errorDescription_0);
		}
	}, [props?.error?.errorMessage]);
	const formatError = (errorDescription_1) => {
		const decodedDescription = decodeURIComponent(errorDescription_1).replace(/%0d%0a/g, "\n");
		if (decodedDescription.includes("AADB2C90208")) setErrorDescription("The password reset link has expired.");
		else if (decodedDescription.includes("AADB2C")) setErrorDescription("Unable to find an account associated to that email.");
		else setErrorDescription("An unexpected error occurred.");
	};
	const handleGoHome = () => {
		clearStoredPath();
		window.location.href = "/";
	};
	return /* @__PURE__ */ React.createElement("div", null, /* @__PURE__ */ React.createElement("div", { style: {
		textAlign: "center",
		marginTop: "50px"
	} }, /* @__PURE__ */ React.createElement("img", {
		src: "https://customb2cpolicydevtest.blob.core.windows.net/root/unitylogo.svg",
		alt: "Unity Logo",
		width: "300",
		style: {
			height: "auto",
			marginBottom: 50
		}
	}), errorDescription ? /* @__PURE__ */ React.createElement("h2", null, errorDescription) : /* @__PURE__ */ React.createElement("h2", null, "Your password has been successfully reset"), errorDescription !== "The password reset link has expired." && /* @__PURE__ */ React.createElement("p", null, "Please click below to return to the sign in page"), errorDescription !== "The password reset link has expired." && /* @__PURE__ */ React.createElement("button", {
		onClick: handleGoHome,
		style: {
			marginTop: "10px",
			backgroundColor: "#0C2F50",
			color: "white",
			border: "none",
			padding: "10px 20px",
			cursor: "pointer",
			borderRadius: "5px",
			fontSize: "16px"
		}
	}, "Sign In")));
};
//#endregion
export { PasswordResetRedirect, PasswordResetRedirect as default };

//# sourceMappingURL=PasswordResetRedirect.mjs.map