"use client";

import Script from "next/script";

type Props = {
  category: string;
};

export default function BlogCategoryAds({ category }: Props) {
  // ===== #3 Native Ad – entertainment listing page, below articles =====
  if (category === "entertainment") {
    return (
      <div className="mt-4">
        {/* Fallback rail container prevents third-party null lookups in nat_full.js */}
        <div id="adm-nat-rightrails" style={{ display: "none" }}></div>
        <div id="adm-nat-below-article" className="add_unit_header_row"></div>
        <Script
          id="ad-native-entertainment-below"
          strategy="afterInteractive"
          dangerouslySetInnerHTML={{
            __html: `
              (function() {
                var s = document.createElement('script');
                s.type = 'text/javascript';
                s.src = "https://native.admedia.com/js/nat_full.js?id=OzopPyMz&bacols=3&barows=1&category=1&subid=[SUBID]";
                document.getElementById("adm-nat-below-article")?.appendChild(s);
              })();
            `,
          }}
        />
      </div>
    );
  }

  // ===== #4 Thankyou Offer – health listing page, below articles =====
  if (category === "health") {
    return (
      <div className="mt-4 text-center">
        <div id="ad-thankyou-health-listing-slot"></div>
        <Script
          id="ad-thankyou-health-970x250"
          strategy="afterInteractive"
          dangerouslySetInnerHTML={{
            __html: `
              (function() {
                var s = document.createElement('script');
                s.src = "//thankyoupages.admedia.com/v2/thankyou.js?aff=rebates&cat=1&subid=[SUBID]&size=970x250";
                document.getElementById("ad-thankyou-health-listing-slot")?.appendChild(s);
              })();
            `,
          }}
        />
      </div>
    );
  }

  return null;
}
