"use client";
import { Fragment, jsx } from "react/jsx-runtime";
import { useAuth } from "../../../hooks/useAuth";
import { useRouter } from "next/navigation";
import { useEffect } from "react";
import { Loader2 } from "lucide-react";
import { useEnsureUserMetadata } from "../../../hooks/useEnsureUserMetadata";
import { useAuthMethodDetector } from "../../../hooks/useAuthMethodDetector";
function AuthGuard({ children }) {
  const { user, isLoading } = useAuth();
  const router = useRouter();
  useAuthMethodDetector();
  useEnsureUserMetadata();
  useEffect(() => {
    if (!isLoading && !user) {
      router.push("/login");
    }
  }, [user, isLoading, router]);
  if (isLoading) {
    return /* @__PURE__ */ jsx("div", { className: "min-h-screen flex items-center justify-center", children: /* @__PURE__ */ jsx(Loader2, { className: "h-8 w-8 animate-spin text-muted-foreground" }) });
  }
  if (!user) {
    return null;
  }
  return /* @__PURE__ */ jsx(Fragment, { children });
}
export {
  AuthGuard
};
