'use client';

import Script from 'next/script';
import { usePathname } from 'next/navigation';

export default function AdSenseScript() {
    const pathname = usePathname();

    // Paths where ads should NOT be shown
    const excludedPaths = [
        '/',                // English Home
        '/de',             // German Home
        '/pricing',        // Pricing Page
        '/login',          // Login
        '/signup',         // Signup
        '/forgot-password', // Forgot Password
        '/qr-code-erstellen', // German landing page
        '/dashboard',      // App Dashboard
        '/settings',       // App Settings
        '/analytics',      // App Analytics
        '/qr',             // QR Creation/Management
        '/create',         // Create Flow
    ];

    // Check if current path starts with any excluded path
    // We add '/' to excluded path to match exact path or subpaths, 
    // EXCEPT for root '/' which needs special handling
    const shouldExclude = excludedPaths.some(path => {
        if (path === '/') {
            return pathname === '/';
        }
        return pathname === path || pathname?.startsWith(`${path}/`);
    });

    if (shouldExclude) {
        return null;
    }

    return (
        <Script
            async
            src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-2782770414424875"
            crossOrigin="anonymous"
            strategy="lazyOnload"
        />
    );
}
