#!/usr/bin/env python3
"""Test the full entry loading flow"""
import sys, os
BASE = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, BASE)
sys.path.insert(0, os.path.join(BASE, 'xstream'))
sys.path.insert(0, os.path.join(BASE, 'deps'))

# Minimal mocks like mini_app.py
import types
_MockAddon = type('_MockAddon', (), {
    '__init__': lambda s, *a, **kw: None,
    'getAddonInfo': lambda s, k: '1.0.0',
    'openSettings': lambda s: None,
    'getSetting': lambda s, k: '',
    'setSetting': lambda s, k, v: None,
})()
_MockDialog = type('_MockDialog', (), {
    'ok': lambda s, *a, **kw: None,
    'yesno': lambda s, *a, **kw: True,
    'select': lambda s, *a, **kw: 0,
    'notification': lambda s, *a, **kw: None,
})()
_MockDialogBusy = type('_DialogBusy', (), {
    'create': lambda s, *a, **k: None,
    'update': lambda s, *a, **k: None,
    'close': lambda s: None,
    'isFinished': lambda s: True,
})()
_MockWindowDialog = type('_WindowDialog', (), {'doModal': lambda s: None})()
_MockFile = type('_File', (), {
    '__enter__': lambda s: s,
    '__exit__': lambda s, *a: None,
    'read': lambda s: b'',
    'write': lambda s, b: 0,
    'close': lambda s: None,
})()
_MockPlayer = type('_Player', (), {
    'play': lambda s, *a, **k: None,
    'isPlaying': lambda s: False,
    'getPlayingFile': lambda s: '',
    'stop': lambda s: None,
})()
def _make_mod(name, **attrs):
    m = types.ModuleType(name)
    for k, v in attrs.items():
        setattr(m, k, v)
    return m
sys.modules['xbmcaddon'] = _make_mod('xbmcaddon', Addon=_MockAddon)
sys.modules['xbmcgui']   = _make_mod('xbmcgui', Dialog=_MockDialog, DialogBusy=_MockDialogBusy, WindowDialog=_MockWindowDialog)
sys.modules['xbmcvfs']   = _make_mod('xbmcvfs', File=_MockFile, exists=lambda s: False, mkdir=lambda s: True, mkdirs=lambda s: True, delete=lambda s: True, rename=lambda s,d: True, translatePath=lambda s: '/tmp')
sys.modules['xbmc']      = _make_mod('xbmc', Player=lambda: _MockPlayer, executebuiltin=lambda s: None, sleep=lambda s: None, getCondVisibility=lambda s: False, getInfoLabel=lambda s: '', log=lambda s: None)

try:
    # Try importing hdfilme
    from xstream.sites import hdfilme
    print("hdfilme imported OK")
    print("has showEntries:", hasattr(hdfilme, 'showEntries'))
    print("SITE_NAME:", getattr(hdfilme, 'SITE_NAME', 'NOT FOUND'))
except Exception as e:
    print(f"Import error: {e}")
    import traceback
    traceback.print_exc()
