import os
from pathlib import Path

print("=" * 70)
print("TEST D'AFFICHAGE DES BACKGROUNDS")
print("=" * 70)
print()

# Vérifier les fichiers
media_dir = Path("media/downloaded_images")

print("📁 VÉRIFICATION DES FICHIERS :")
print("-" * 70)

backgrounds = {
    "camion-bg.jpg": "Section 'Qui sommes-nous'",
    "map-bg.png": "Section 'Zone d'intervention'",
}

all_ok = True
for filename, section in backgrounds.items():
    filepath = media_dir / filename
    if filepath.exists():
        size = os.path.getsize(filepath)
        print(f"✅ {filename:20} existe ({size:,} octets) → {section}")
    else:
        print(f"❌ {filename:20} MANQUANT → {section}")
        all_ok = False

print()

# Vérifier le CSS
print("📄 VÉRIFICATION DU CSS :")
print("-" * 70)

css_file = Path("static/css/animations.css")
if css_file.exists():
    with open(css_file, 'r', encoding='utf-8') as f:
        css_content = f.read()
    
    # Vérifier que background-attachment: fixed est retiré
    if "background-attachment: fixed" in css_content:
        print("⚠️  background-attachment: fixed est encore présent")
        all_ok = False
    else:
        print("✅ background-attachment: fixed retiré (pas de parallax)")
    
    # Vérifier les URLs
    for filename in backgrounds.keys():
        url = f"/media/downloaded_images/{filename}"
        if url in css_content:
            print(f"✅ URL correcte pour {filename}")
        else:
            print(f"❌ URL manquante pour {filename}")
            all_ok = False
else:
    print("❌ animations.css non trouvé")
    all_ok = False

print()

# Vérifier settings.py
print("⚙️  VÉRIFICATION DE LA CONFIGURATION :")
print("-" * 70)

settings_file = Path("aacore/settings.py")
if settings_file.exists():
    with open(settings_file, 'r', encoding='utf-8') as f:
        settings_content = f.read()
    
    if "MEDIA_URL = 'media/'" in settings_content:
        print("✅ MEDIA_URL configuré")
    else:
        print("❌ MEDIA_URL manquant")
        all_ok = False
    
    if "MEDIA_ROOT" in settings_content:
        print("✅ MEDIA_ROOT configuré")
    else:
        print("❌ MEDIA_ROOT manquant")
        all_ok = False
else:
    print("❌ settings.py non trouvé")
    all_ok = False

# Vérifier urls.py
urls_file = Path("aacore/urls.py")
if urls_file.exists():
    with open(urls_file, 'r', encoding='utf-8') as f:
        urls_content = f.read()
    
    if "static(settings.MEDIA_URL" in urls_content:
        print("✅ MEDIA_URL ajouté aux URLs")
    else:
        print("❌ MEDIA_URL non configuré dans urls.py")
        all_ok = False
else:
    print("❌ urls.py non trouvé")
    all_ok = False

print()
print("=" * 70)

if all_ok:
    print("✅ TOUT EST CORRECT !")
    print()
    print("Les images de background devraient s'afficher correctement.")
    print()
    print("URLs à tester :")
    print("  • Page d'accueil : http://127.0.0.1:8000/")
    print("  • Image camion : http://127.0.0.1:8000/media/downloaded_images/camion-bg.jpg")
    print("  • Image carte : http://127.0.0.1:8000/media/downloaded_images/map-bg.png")
    print()
    print("Si le serveur n'est pas démarré, lancez :")
    print("  python manage.py runserver")
else:
    print("❌ DES PROBLÈMES ONT ÉTÉ DÉTECTÉS")
    print()
    print("Vérifiez les points ci-dessus avant de tester.")

print("=" * 70)
