1+ "use client" ;
2+ import React , { useEffect , useState } from "react" ;
3+ import { FaChevronUp , FaChevronDown } from "react-icons/fa" ;
4+
5+ const BottomAd = ( ) => {
6+ const [ isClient , setIsClient ] = useState ( false ) ;
7+ const [ minimized , setMinimized ] = useState ( false ) ;
8+
9+ useEffect ( ( ) => {
10+ setIsClient ( true ) ;
11+
12+ if ( typeof window !== "undefined" ) {
13+ // Load AdSense script once
14+ const scriptId = "adsbygoogle-js" ;
15+ if ( ! document . getElementById ( scriptId ) ) {
16+ const script = document . createElement ( "script" ) ;
17+ script . id = scriptId ;
18+ script . async = true ;
19+ script . src =
20+ "https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-4311738896428559" ;
21+ script . crossOrigin = "anonymous" ;
22+ document . head . appendChild ( script ) ;
23+ }
24+ }
25+ } , [ ] ) ;
26+
27+ useEffect ( ( ) => {
28+ if ( isClient ) {
29+ try {
30+ ( window . adsbygoogle = window . adsbygoogle || [ ] ) . push ( { } ) ;
31+ } catch ( e ) {
32+ console . warn ( "AdSense error:" , e ) ;
33+ }
34+ }
35+ } , [ isClient ] ) ;
36+
37+ if ( ! isClient ) return null ;
38+
39+ // Detect environment for test ads
40+ const isDev =
41+ window . location . hostname === "localhost" ||
42+ window . location . hostname === "127.0.0.1" ;
43+
44+ return (
45+ < div
46+ style = { {
47+ position : "fixed" ,
48+ bottom : 0 ,
49+ left : 0 ,
50+ width : "100%" ,
51+ background : "#fff" ,
52+ boxShadow : "0 -2px 8px rgba(0,0,0,0.1)" ,
53+ zIndex : 9999 ,
54+ transition : "height 0.3s ease" ,
55+ height : minimized ? "36px" : "120px" ,
56+ overflow : "hidden" ,
57+ textAlign : "center" ,
58+ padding : minimized ? "0" : "4px 0" ,
59+ } }
60+ >
61+ < button
62+ onClick = { ( ) => setMinimized ( ! minimized ) }
63+ style = { {
64+ position : "absolute" ,
65+ right : "8px" ,
66+ top : "4px" ,
67+ background : "transparent" ,
68+ border : "none" ,
69+ fontSize : "16px" ,
70+ cursor : "pointer" ,
71+ color : "#444" ,
72+ display : "flex" ,
73+ alignItems : "center" ,
74+ justifyContent : "center" ,
75+ } }
76+ aria-label = { minimized ? "Expand Ad" : "Minimize Ad" }
77+ >
78+ { minimized ? < FaChevronUp /> : < FaChevronDown /> }
79+ </ button >
80+
81+ { minimized ? (
82+ < div style = { { fontSize : "13px" , padding : "6px" , color : "#555" } } >
83+ Ad minimized — click ▲ to reopen
84+ </ div >
85+ ) : (
86+ < ins
87+ className = "adsbygoogle"
88+ style = { { display : "block" , height : "100px" } }
89+ data-ad-client = {
90+ isDev ? "ca-pub-3940256099942544" : "ca-pub-4311738896428559"
91+ }
92+ data-ad-slot = { isDev ? "6300978111" : "2048540881" }
93+ data-ad-format = "auto"
94+ data-full-width-responsive = "true"
95+ > </ ins >
96+ ) }
97+ </ div >
98+ ) ;
99+ } ;
100+
101+ export default BottomAd ;
0 commit comments