#!/usr/bin/env python3
"""
Fix inner page body overflow:hidden issue.
The original Next.js CSS has overflow:hidden on body.
We need to verify the custom CSS loads on inner pages via header.php.
Also check if there's a separate inline style on body.
"""
import re, os

BASE = '/Applications/XAMPP/xamppfiles/htdocs/aaa'

# Check what the inner course page body tag looks like
sample_page = os.path.join(BASE, 'agile-management', 'csm-certification-training.php')
with open(sample_page, 'r', encoding='utf-8', errors='ignore') as f:
    content = f.read()

# Does the page have its own <body> tag with inline overflow?
body_tags = re.findall(r'<body[^>]*>', content[:5000])
print("BODY TAGS in inner page:", body_tags[:3])

# Does the header.php output a body tag?
header_path = os.path.join(BASE, 'header.php')
with open(header_path, 'r', encoding='utf-8') as f:
    header = f.read()
    
body_in_header = re.findall(r'<body[^>]*>', header)
print("BODY TAGS in header.php:", body_in_header[:3])

# Find what CSS files the header loads
css_files = re.findall(r'href="([^"]*\.css[^"]*)"', header)
print("\nCSS FILES loaded in header:")
for c in css_files[:10]:
    print(" ", c)

# Check if custom-brand.css is loaded
print("\ncustom-brand.css in header:", '/assets/css/custom-brand.css' in header)

# Look for overflow:hidden in the CSS files
print("\nChecking loaded CSS for overflow:hidden on body...")
import urllib.request
for css_url in css_files[:3]:
    if 'knowledgehut.com' in css_url:
        try:
            print(f"Checking {css_url[:80]}...")
            req = urllib.request.Request(css_url, headers={'User-Agent': 'Mozilla/5.0'})
            resp = urllib.request.urlopen(req, timeout=5)
            css_content = resp.read().decode('utf-8', errors='ignore')
            if 'overflow:hidden' in css_content or 'overflow: hidden' in css_content:
                # Find body overflow
                body_overflow = re.findall(r'body\{[^}]*overflow[^}]*\}', css_content)
                print("  body overflow rules:", body_overflow[:2])
        except Exception as e:
            print(f"  Could not fetch: {e}")
