"use client";

import { useAdminAuth } from "../../hooks/useAdminAuth";
import { useClerk } from "@clerk/nextjs";
import { LoadingSkeleton } from "./LoadingSkeleton";
import { AccessDenied } from "./AccessDenied";

export function AdminAuthGate({ children }: { children: React.ReactNode }) {
  const auth = useAdminAuth();
  const { signOut } = useClerk();

  if (auth.status === "loading") {
    return <LoadingSkeleton />;
  }

  if (auth.status === "denied") {
    return <AccessDenied reason={auth.reason} onSignOut={() => signOut()} />;
  }

  return <>{children}</>;
}
