import { T as reactExports, K as jsxRuntimeExports } from "./server-ChzsfjB9.js";
import { h as useNavigate, s as supabase, L as Link } from "./router-uu4vGjiO.js";
import { C as ChartColumn, I as Input, B as Button, L as LoaderCircle } from "./input-muzHTpl5.js";
import { L as Label } from "./label-2bHC70jG.js";
import { C as CircleCheck } from "./circle-check-uh9kY1Dd.js";
import { L as Lock } from "./lock-0me_4kb9.js";
import "node:async_hooks";
import "node:stream/web";
import "node:stream";
function ResetPage() {
  const navigate = useNavigate();
  const [pwd, setPwd] = reactExports.useState("");
  const [confirm, setConfirm] = reactExports.useState("");
  const [error, setError] = reactExports.useState(null);
  const [done, setDone] = reactExports.useState(false);
  const [submitting, setSubmitting] = reactExports.useState(false);
  const [ready, setReady] = reactExports.useState(false);
  reactExports.useEffect(() => {
    supabase.auth.getSession().then(({
      data
    }) => {
      setReady(!!data.session);
    });
  }, []);
  const onSubmit = async (e) => {
    e.preventDefault();
    setError(null);
    if (pwd.length < 6) return setError("Senha mínima de 6 caracteres.");
    if (pwd !== confirm) return setError("As senhas não coincidem.");
    setSubmitting(true);
    const {
      error: error2
    } = await supabase.auth.updateUser({
      password: pwd
    });
    setSubmitting(false);
    if (error2) setError(error2.message);
    else {
      setDone(true);
      setTimeout(() => navigate({
        to: "/login"
      }), 2e3);
    }
  };
  return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "min-h-screen flex items-center justify-center bg-gradient-to-br from-muted/40 via-background to-accent/30 px-4 py-10", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "w-full max-w-md", children: [
    /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "mb-6 flex flex-col items-center", children: [
      /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex h-12 w-12 items-center justify-center rounded-xl bg-gradient-to-br from-primary to-primary-glow shadow-lg shadow-primary/20", children: /* @__PURE__ */ jsxRuntimeExports.jsx(ChartColumn, { className: "h-6 w-6 text-primary-foreground" }) }),
      /* @__PURE__ */ jsxRuntimeExports.jsx("h1", { className: "mt-3 text-xl font-bold tracking-tight", children: "365-BI" })
    ] }),
    /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "rounded-2xl border bg-card p-6 shadow-xl sm:p-8", children: done ? /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-4 text-center", children: [
      /* @__PURE__ */ jsxRuntimeExports.jsx(CircleCheck, { className: "mx-auto h-10 w-10 text-emerald-500" }),
      /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm", children: "Senha atualizada. Redirecionando para o login…" })
    ] }) : !ready ? /* @__PURE__ */ jsxRuntimeExports.jsxs("p", { className: "text-sm text-muted-foreground text-center", children: [
      "Link inválido ou expirado.",
      " ",
      /* @__PURE__ */ jsxRuntimeExports.jsx(Link, { to: "/recuperar-senha", className: "text-primary underline", children: "Solicitar novo" })
    ] }) : /* @__PURE__ */ jsxRuntimeExports.jsxs("form", { onSubmit, className: "space-y-4", children: [
      /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
        /* @__PURE__ */ jsxRuntimeExports.jsx("h2", { className: "text-lg font-semibold", children: "Definir nova senha" }),
        /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm text-muted-foreground", children: "Crie uma senha de pelo menos 6 caracteres." })
      ] }),
      /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-1.5", children: [
        /* @__PURE__ */ jsxRuntimeExports.jsx(Label, { children: "Nova senha" }),
        /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "relative", children: [
          /* @__PURE__ */ jsxRuntimeExports.jsx(Lock, { className: "absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground" }),
          /* @__PURE__ */ jsxRuntimeExports.jsx(Input, { type: "password", value: pwd, onChange: (e) => setPwd(e.target.value), className: "pl-9 h-11" })
        ] })
      ] }),
      /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-1.5", children: [
        /* @__PURE__ */ jsxRuntimeExports.jsx(Label, { children: "Confirmar senha" }),
        /* @__PURE__ */ jsxRuntimeExports.jsx(Input, { type: "password", value: confirm, onChange: (e) => setConfirm(e.target.value), className: "h-11" })
      ] }),
      error && /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "rounded-md border border-destructive/30 bg-destructive/10 px-3 py-2 text-sm text-destructive", children: error }),
      /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { type: "submit", disabled: submitting, className: "w-full h-11", children: submitting ? /* @__PURE__ */ jsxRuntimeExports.jsx(LoaderCircle, { className: "h-4 w-4 animate-spin" }) : "Salvar nova senha" })
    ] }) })
  ] }) });
}
export {
  ResetPage as component
};
