"use client";

import { GoogleReCaptchaProvider } from "react-google-recaptcha-v3";
import { ReactNode } from "react";

interface RecaptchaWrapperProps {
  children: ReactNode;
  lang?: string;
}

export default function RecaptchaWrapper({
  children,
  lang = "en",
}: RecaptchaWrapperProps) {
  const recaptchaSiteKey = process.env.NEXT_PUBLIC_RECAPTCHA_SITE_KEY;

  // If no reCAPTCHA key is configured, render children without the provider
  // Forms should handle this gracefully by skipping reCAPTCHA validation
  if (!recaptchaSiteKey) {
    if (process.env.NODE_ENV === "development") {
      console.warn(
        "reCAPTCHA site key not configured. Bot protection is disabled.",
      );
    }
    return <>{children}</>;
  }

  return (
    <GoogleReCaptchaProvider
      reCaptchaKey={recaptchaSiteKey}
      language={lang}
      scriptProps={{
        async: true,
        defer: true,
        appendTo: "head",
      }}
    >
      {children}
    </GoogleReCaptchaProvider>
  );
}
