"""
Point d'entrée pour le GUI classique Web Sentinel.
Wrapper pour éviter les erreurs d'imports relatifs avec PyInstaller.
"""

import sys
import os
from pathlib import Path

# Fix encodage UTF-8 pour Windows
if sys.platform == 'win32':
    if hasattr(sys.stdout, 'reconfigure'):
        if sys.stdout.encoding != 'utf-8':
            sys.stdout.reconfigure(encoding='utf-8', errors='replace')
        if sys.stderr.encoding != 'utf-8':
            sys.stderr.reconfigure(encoding='utf-8', errors='replace')

# Ajouter le dossier racine au path AVANT les imports
sys.path.insert(0, str(Path(__file__).parent.parent.parent))

def main():
    """Lance le GUI classique."""
    try:
        from web_sentinel.gui.main_window import WebSentinelGUI
        from web_sentinel.gui.themes_gui.shared import get_data_manager
        from web_sentinel.gui.theme_applicator import ThemeApplicator
        
        # Récupérer le thème
        data_manager = get_data_manager()
        theme = data_manager.get_gui_theme()
        
        print(f"[Web Sentinel Classic] Démarrage avec thème: {theme}")
        
        # Créer et lancer l'interface classique
        app = WebSentinelGUI()
        
        # Appliquer le thème si différent de classic
        if theme != "classic":
            ThemeApplicator.apply_theme(app.root, theme)
            print(f"[Web Sentinel Classic] Thème '{theme}' appliqué")
        
        app.run()
        
    except ImportError as e:
        print(f"Erreur d'import: {e}")
        import traceback
        traceback.print_exc()
        sys.exit(1)
    except Exception as e:
        print(f"Erreur inattendue: {e}")
        import traceback
        traceback.print_exc()
        sys.exit(1)


if __name__ == "__main__":
    main()
