import Script from 'next/script';
const AdConfigScript = function AdConfigScript() {
  return <Script id="ad-config-script" type="text/javascript" strategy="beforeInteractive">
      {`
      const defineAdSSetup = () => {
            let windowWidth = window.innerWidth || window.document.documentElement.clientWidth || window.document.body.clientWidth;
            let view;
            if (windowWidth > 750) {
                view = "d";
            } else {
                view = "m";
            }
            let Ads = {
                m: {
                    adPlacements: ["banner", "banner_btf", "mrec_btf"],
                    adSlotSizes: {
                        "banner": [{
                            "minWidth": 1,
                            "sizes": [[320, 50]]
                        }],
                        "banner_btf": [{
                            "minWidth": 1,
                            "sizes": [[300, 250], [320, 250]]
                        }, {
                            "minWidth": 650,
                            "sizes": [[300, 250], [640, 250]]
                        }],
                        "mrec_btf": [{
                            "minWidth": 1,
                            "sizes": [[300, 250], [320, 250]]
                        }]
                    }
                },
                d: {
                    adPlacements: ["banner", "banner_btf", "mrec_btf"],
                    adSlotSizes: {
                        "banner": [{
                            "minWidth": 1,
                            "sizes": [[728, 90]]
                        }, {
                            "minWidth": 980,
                            "sizes": [[970, 90], [728, 90]]
                        }],
                        "banner_btf": [{
                            "minWidth": 1,
                            "sizes": [[300, 250], [640, 250], [728, 90]]
                        }, {
                            "minWidth": 980,
                            "sizes": [[970, 250], [300, 250], [640, 250]]
                        }, {
                            "minWidth": 1170,
                            "sizes": [[970, 250], [300, 250], [1160, 250]]
                        }],
                        "mrec_btf": [{
                            "minWidth": 1,
                            "sizes": [[300, 250], [320, 250]]
                        }]
                    }
                },
            };
            // Here we now use our prepared configuration to put together the AdSSetup based on the page width.
            window.adSSetup = {
                adPlacements: Ads[view].adPlacements,
                adSlotSizes: Ads[view].adSlotSizes,
                sightloaderArr: [".*"],
                view: view,
                partners: true,
                colorBg: false,
                bgClick: true,
                hasVideoPlayer: false,
                isArticle: false,
                pageName: window.utag_data?.ad_unit_section || "interactives",
                pid: window.utag_data?.content_id || "",
                zone: window.utag_data?.internal_site_id || "politico",
                contentType: window.utag_data?.page_type.replace(/\\s/g, "-") || "interactives",
                target: "",
                iabTax: "",
                placeholder: {
                    disablePlaceholders: false,
                    default: {
                        "border-color": "rgba(0,0,0,0)",
                        "background-color": "",
                        "admarkPosition": "center center",
                        "color": "#999",
                        "font-size": "12px",
                        "font-family": "Tahoma",
                        "markerText": "AD"
                    }
                }
            };
        // this list will be looked up in utag_data and alls found will be appenden to adSSetup.target
        let utagArray = [
            "content_id",
            "content_tag",
            "content_topic",
            "content_author",
            "page_type",
            "free_paid_content",
            "hp_server_refresh"
        ];
        utagArray.forEach(entry => {
            if (window.utag_data?.[entry]) {
                if (entry === "free_paid_content") {
                    window.adSSetup.target += "isPremium=" + window.utag_data[entry] !== "free" + ";";
                } else if (entry === "page_type") {
                    window.adSSetup.target += entry + "=" + window.utag_data[entry].replace(/\\|/g, ',').replace(/\\s/g, "-") + ";";
                } else {
                    window.adSSetup.target += entry + "=" + window.utag_data[entry].replace(/\\|/g, ',') + ";";
                }
            }
        });
    }
    defineAdSSetup();
      `}
    </Script>;
};
export default AdConfigScript;