import Script from "next/script";
import AdComponent from "@/components/AdComponent";

export const ADSENSE_CLIENT = "ca-pub-9918939471514709";

type ContentAdsProps = {
  /** Hide the ad unit and only load the script (rare). */
  scriptOnly?: boolean;
  className?: string;
};

/**
 * AdSense for public content pages only — do not use on auth/OTP/empty screens.
 */
export default function ContentAds({
  scriptOnly = false,
  className,
}: ContentAdsProps) {
  return (
    <>
      <Script
        id="adsense-content-script"
        async
        src={`https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=${ADSENSE_CLIENT}`}
        crossOrigin="anonymous"
        strategy="afterInteractive"
      />
      {!scriptOnly && (
        <div
          className={className}
          style={{ margin: "1.5rem auto", maxWidth: 970, minHeight: 90 }}
        >
          <AdComponent adClient={ADSENSE_CLIENT} />
        </div>
      )}
    </>
  );
}
