"""Item-Namensdatenbank (Tibia-Item-ID → Name, aus BBot.Items.txt)."""
import pathlib

_path = pathlib.Path(__file__).parent.resolve() / 'items.txt'

_cache = None


def _load():
    global _cache
    if _cache is None:
        _cache = {}
        with open(_path, encoding='latin-1') as handle:
            for line in handle:
                parts = line.rstrip('\n').split(',')
                if len(parts) >= 6 and parts[0].isdigit():
                    item_id = int(parts[0])
                    if item_id not in _cache and parts[-1].strip():
                        _cache[item_id] = parts[-1].strip()
    return _cache


def itemName(item_id):
    """Name der Item-ID oder None (unbekannt)."""
    return _load().get(item_id)
