"use client";
import { jsx, jsxs } from "react/jsx-runtime";
import { useState } from "react";
import Link from "next/link";
import { Card, CardContent, CardHeader, CardTitle, CardDescription } from "@open-mercato/ui/primitives/card";
import { Button } from "@open-mercato/ui/primitives/button";
import { EmailInput } from "@open-mercato/ui/primitives/email-input";
import { Label } from "@open-mercato/ui/primitives/label";
import { useT } from "@open-mercato/shared/lib/i18n/context";
function ResetPage() {
  const t = useT();
  const [sent, setSent] = useState(false);
  const [submitting, setSubmitting] = useState(false);
  const [error, setError] = useState(null);
  const [fieldError, setFieldError] = useState(null);
  async function onSubmit(e) {
    e.preventDefault();
    setError(null);
    setFieldError(null);
    setSubmitting(true);
    try {
      const form = new FormData(e.currentTarget);
      const res = await fetch("/api/auth/reset", { method: "POST", body: form });
      if (!res.ok) {
        const data = await res.json().catch(() => null);
        if (data?.fieldErrors?.email?.length) {
          setFieldError(t("auth.reset.errors.emailInvalid", "Please enter a valid email address."));
          return;
        }
        setError(data?.error || t("auth.reset.error", "Something went wrong"));
        return;
      }
      setSent(true);
    } finally {
      setSubmitting(false);
    }
  }
  return /* @__PURE__ */ jsx("div", { className: "min-h-svh flex items-center justify-center p-4", children: /* @__PURE__ */ jsxs(Card, { className: "w-full max-w-sm", children: [
    /* @__PURE__ */ jsxs(CardHeader, { children: [
      /* @__PURE__ */ jsx(CardTitle, { children: t("auth.resetPassword") }),
      /* @__PURE__ */ jsx(CardDescription, { children: t("auth.reset.description", "Enter your email to receive reset link") })
    ] }),
    /* @__PURE__ */ jsx(CardContent, { children: sent ? /* @__PURE__ */ jsxs("div", { className: "grid gap-3", children: [
      /* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: t("auth.reset.sent", "If an account with that email exists, we sent a reset link. Please check your inbox.") }),
      /* @__PURE__ */ jsx(Link, { href: "/login", className: "text-sm underline", children: t("auth.reset.backToLogin", "Back to login") })
    ] }) : /* @__PURE__ */ jsxs("form", { className: "grid gap-3", onSubmit, noValidate: true, children: [
      error && /* @__PURE__ */ jsx("div", { className: "text-sm text-red-600", children: error }),
      /* @__PURE__ */ jsxs("div", { className: "grid gap-1", children: [
        /* @__PURE__ */ jsx(Label, { htmlFor: "email", children: t("auth.email") }),
        /* @__PURE__ */ jsx(EmailInput, { id: "email", name: "email", required: true, "aria-invalid": !!fieldError, "aria-describedby": fieldError ? "email-error" : void 0 }),
        fieldError && /* @__PURE__ */ jsx("p", { id: "email-error", className: "text-sm text-red-600", children: fieldError })
      ] }),
      /* @__PURE__ */ jsx(Button, { type: "submit", className: "mt-2 w-full", disabled: submitting, children: submitting ? "..." : t("auth.sendResetLink") }),
      /* @__PURE__ */ jsx("div", { className: "text-center", children: /* @__PURE__ */ jsx(Link, { href: "/login", className: "text-xs text-muted-foreground underline", children: t("auth.reset.backToLogin", "Back to login") }) })
    ] }) })
  ] }) });
}
export {
  ResetPage as default
};
//# sourceMappingURL=reset.js.map
