import { AuthLayout, Banner, Button, Input, LinkButton, Text } from "@cloudhal/ui";
import { EnvelopeSimple, Info, SquaresFour } from "@phosphor-icons/react";
import { useMutation } from "@tanstack/react-query";
import { type FormEvent, useState } from "react";
import { ErrorBanner } from "../components/ErrorBanner.tsx";
import { LanguageSwitch } from "../components/LanguageSwitch.tsx";
import { useT } from "../i18n/index.tsx";
import { api, errorCode } from "../lib/api.ts";
import { validEmail } from "../lib/roles.ts";
/**
* `/forgot-password` (DESIGN.md §2r, RFC-0011): one email field. The server answers the same for
* every address, so the screen does too ("If … belongs to an account here"); a server that cannot
* send email says to ask an Administrator, who can issue a link from Team.
*/
export function ForgotPasswordPage() {
const t = useT();
const [email, setEmail] = useState("");
const [attempted, setAttempted] = useState(false);
const send = useMutation({
mutationFn: () => api.passwordReset.request(email.trim().toLowerCase()),
});
const unavailable = errorCode(send.error) === "email_unavailable";
const emailError =
attempted && !validEmail(email)
? email.trim()
? t("invites.errors.emailInvalid")
: t("invites.errors.emailRequired")
: undefined;
const submit = (e: FormEvent) => {
e.preventDefault();
setAttempted(true);
if (send.isPending || !validEmail(email)) return;
send.mutate();
};
return (