import { S as reactExports, J as jsxRuntimeExports } from "./server-CZT6KZsz.js";
import { Q as useAuth, T as useNavigate, N as Navigate } from "./router-Bsssaenw.js";
import { W as Wrench, L as LoaderCircle } from "./wrench-CccwRKu3.js";
import "node:async_hooks";
import "node:stream/web";
import "node:stream";
function LoginPage() {
  const {
    signIn,
    signUp,
    session,
    loading
  } = useAuth();
  const navigate = useNavigate();
  const [mode, setMode] = reactExports.useState("login");
  const [email, setEmail] = reactExports.useState("");
  const [password, setPassword] = reactExports.useState("");
  const [nombre, setNombre] = reactExports.useState("");
  const [err, setErr] = reactExports.useState(null);
  const [busy, setBusy] = reactExports.useState(false);
  if (!loading && session) return /* @__PURE__ */ jsxRuntimeExports.jsx(Navigate, { to: "/" });
  async function onSubmit(e) {
    e.preventDefault();
    setErr(null);
    setBusy(true);
    const res = mode === "login" ? await signIn(email, password) : await signUp(email, password, nombre);
    setBusy(false);
    if (res.error) {
      setErr(res.error);
      return;
    }
    if (mode === "signup") {
      setMode("login");
      setErr("Cuenta creada. Iniciá sesión.");
      return;
    }
    navigate({
      to: "/"
    });
  }
  return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "min-h-screen grid place-items-center bg-background px-4", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "w-full max-w-md", children: [
    /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center gap-3 justify-center mb-8", children: [
      /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "size-12 rounded-lg gradient-primary grid place-items-center shadow-elevated", children: /* @__PURE__ */ jsxRuntimeExports.jsx(Wrench, { className: "size-6 text-primary-foreground", strokeWidth: 2.5 }) }),
      /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
        /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "font-display font-bold text-2xl leading-none", children: "Basurto" }),
        /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-[11px] text-muted-foreground mt-1 uppercase tracking-widest", children: "No Te Calentés" })
      ] })
    ] }),
    /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "bg-card border border-border rounded-xl shadow-card p-6", children: [
      /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex gap-1 p-1 bg-muted rounded-md mb-5", children: ["login", "signup"].map((m) => /* @__PURE__ */ jsxRuntimeExports.jsx("button", { type: "button", onClick: () => {
        setMode(m);
        setErr(null);
      }, className: `flex-1 py-1.5 text-sm rounded font-medium transition ${mode === m ? "bg-card shadow-sm" : "text-muted-foreground"}`, children: m === "login" ? "Iniciar sesión" : "Crear cuenta" }, m)) }),
      /* @__PURE__ */ jsxRuntimeExports.jsxs("form", { onSubmit, className: "space-y-3", children: [
        mode === "signup" && /* @__PURE__ */ jsxRuntimeExports.jsx(Field, { label: "Nombre completo", children: /* @__PURE__ */ jsxRuntimeExports.jsx("input", { required: true, value: nombre, onChange: (e) => setNombre(e.target.value), className: "w-full px-3 py-2 bg-background border border-border rounded-md text-sm outline-none focus:border-ring" }) }),
        /* @__PURE__ */ jsxRuntimeExports.jsx(Field, { label: "Email", children: /* @__PURE__ */ jsxRuntimeExports.jsx("input", { required: true, type: "email", value: email, onChange: (e) => setEmail(e.target.value), className: "w-full px-3 py-2 bg-background border border-border rounded-md text-sm outline-none focus:border-ring" }) }),
        /* @__PURE__ */ jsxRuntimeExports.jsx(Field, { label: "Contraseña", children: /* @__PURE__ */ jsxRuntimeExports.jsx("input", { required: true, minLength: 6, type: "password", value: password, onChange: (e) => setPassword(e.target.value), className: "w-full px-3 py-2 bg-background border border-border rounded-md text-sm outline-none focus:border-ring" }) }),
        err && /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-xs text-destructive bg-destructive/10 px-3 py-2 rounded", children: err }),
        /* @__PURE__ */ jsxRuntimeExports.jsxs("button", { disabled: busy, type: "submit", className: "w-full inline-flex items-center justify-center gap-2 px-4 py-2.5 rounded-md gradient-primary text-primary-foreground font-medium text-sm shadow-elevated disabled:opacity-60", children: [
          busy && /* @__PURE__ */ jsxRuntimeExports.jsx(LoaderCircle, { className: "size-4 animate-spin" }),
          mode === "login" ? "Entrar" : "Crear cuenta"
        ] })
      ] })
    ] }),
    /* @__PURE__ */ jsxRuntimeExports.jsxs("p", { className: "text-center text-xs text-muted-foreground mt-4", children: [
      "Las cuentas nuevas se crean como ",
      /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "font-mono", children: "técnico" }),
      ". Un admin puede promoverlas luego."
    ] })
  ] }) });
}
function Field({
  label,
  children
}) {
  return /* @__PURE__ */ jsxRuntimeExports.jsxs("label", { className: "block", children: [
    /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-xs font-medium text-muted-foreground uppercase tracking-wider", children: label }),
    /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "mt-1", children })
  ] });
}
export {
  LoginPage as component
};
