import { r as reactExports, U as jsxRuntimeExports } from "./worker-entry-ScJyyKL-.js";
import { u as useNavigate, L as Link, t as toast } from "./router-DeIlR9yC.js";
import { s as supabase } from "./client-Dez4i5AL.js";
import { B as Button } from "./button-BfwfuXeE.js";
import { L as Label, I as Input } from "./label-B9UfDuIZ.js";
import "node:events";
import "node:async_hooks";
import "node:stream/web";
import "node:stream";
function AuthPage() {
  const navigate = useNavigate();
  const [mode, setMode] = reactExports.useState("signin");
  const [loading, setLoading] = reactExports.useState(false);
  reactExports.useEffect(() => {
    supabase.auth.getSession().then(({
      data
    }) => {
      if (data.session) navigate({
        to: "/admin"
      });
    });
  }, [navigate]);
  async function handle(e) {
    e.preventDefault();
    setLoading(true);
    const fd = new FormData(e.currentTarget);
    const email = String(fd.get("email") ?? "").trim();
    const password = String(fd.get("password") ?? "");
    const displayName = String(fd.get("display_name") ?? "").trim();
    if (mode === "signup") {
      const {
        error: error2
      } = await supabase.auth.signUp({
        email,
        password,
        options: {
          emailRedirectTo: `${window.location.origin}/admin`,
          data: {
            display_name: displayName || email
          }
        }
      });
      setLoading(false);
      if (error2) {
        toast.error(error2.message);
        return;
      }
      toast.success("Account created. Check your inbox to verify, then sign in.");
      setMode("signin");
      return;
    }
    const {
      error
    } = await supabase.auth.signInWithPassword({
      email,
      password
    });
    setLoading(false);
    if (error) {
      toast.error(error.message);
      return;
    }
    navigate({
      to: "/admin"
    });
  }
  return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "min-h-screen flex items-center justify-center px-5 py-10 bg-background bg-spotlight", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "w-full max-w-md", children: [
    /* @__PURE__ */ jsxRuntimeExports.jsxs(Link, { to: "/", className: "flex items-center justify-center gap-2 mb-10", children: [
      /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "font-display text-3xl", children: "Luxxen" }),
      /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "font-display text-3xl text-gradient-gold", children: "Pictures" })
    ] }),
    /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "bg-onyx border border-border p-8 md:p-10", children: [
      /* @__PURE__ */ jsxRuntimeExports.jsx("h1", { className: "font-display text-3xl text-center", children: mode === "signin" ? "Admin Sign In" : "Create Admin Account" }),
      /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-center text-sm text-muted-foreground mt-2", children: mode === "signin" ? "Access the Luxxen Pictures dashboard" : "First admin? Create your account." }),
      /* @__PURE__ */ jsxRuntimeExports.jsxs("form", { onSubmit: handle, className: "mt-8 space-y-5", children: [
        mode === "signup" && /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-2", children: [
          /* @__PURE__ */ jsxRuntimeExports.jsx(Label, { className: "text-xs uppercase tracking-widest text-muted-foreground", children: "Display Name" }),
          /* @__PURE__ */ jsxRuntimeExports.jsx(Input, { name: "display_name", required: true, maxLength: 120, className: "bg-background h-12" })
        ] }),
        /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-2", children: [
          /* @__PURE__ */ jsxRuntimeExports.jsx(Label, { className: "text-xs uppercase tracking-widest text-muted-foreground", children: "Email" }),
          /* @__PURE__ */ jsxRuntimeExports.jsx(Input, { name: "email", type: "email", required: true, className: "bg-background h-12" })
        ] }),
        /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-2", children: [
          /* @__PURE__ */ jsxRuntimeExports.jsx(Label, { className: "text-xs uppercase tracking-widest text-muted-foreground", children: "Password" }),
          /* @__PURE__ */ jsxRuntimeExports.jsx(Input, { name: "password", type: "password", required: true, minLength: 6, className: "bg-background h-12" })
        ] }),
        /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { type: "submit", variant: "hero", size: "lg", disabled: loading, className: "w-full", children: loading ? "..." : mode === "signin" ? "Sign In" : "Create Account" })
      ] }),
      /* @__PURE__ */ jsxRuntimeExports.jsx("button", { onClick: () => setMode(mode === "signin" ? "signup" : "signin"), className: "w-full mt-6 text-sm text-muted-foreground hover:text-gold transition-colors", children: mode === "signin" ? "No account yet? Create one" : "Already have an account? Sign in" })
    ] }),
    /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xs text-center text-muted-foreground mt-6", children: "The first user to sign up should be granted the admin role from the backend dashboard." })
  ] }) });
}
export {
  AuthPage as component
};
