"use client";

import { GoogleOAuthProvider } from "@react-oauth/google";

function isValidGoogleClientId(value: string | undefined): boolean {
  if (!value) return false;
  if (value === "your_google_oauth_client_id_here") return false;
  return value.includes(".apps.googleusercontent.com");
}

export function AppGoogleOAuthProvider({
  children,
}: {
  children: React.ReactNode;
}) {
  const rawClientId = process.env.NEXT_PUBLIC_GOOGLE_CLIENT_ID;
  const clientId = isValidGoogleClientId(rawClientId) ? rawClientId : undefined;

  // Keep app usable even when Google client ID is missing.
  if (!clientId) {
    return <>{children}</>;
  }

  return <GoogleOAuthProvider clientId={clientId}>{children}</GoogleOAuthProvider>;
}
