# -*- coding: utf-8 -*-
# Runtime patch for PLTW_K20 config to avoid NameError: 'Brak' is not defined.
# Import the real CONFIG and then ensure open_settings has safe defaults.
from __future__ import annotations
from resources.libs.common.config import CONFIG as REAL_CONFIG  # type: ignore

try:
    # If the original module defined a free name 'Brak', ignore it and ensure safe defaults.
    def _safe_open_settings(self, id=None, cat=None, set=None, activate=False):
        return REAL_CONFIG.open_settings.__wrapped__(self, id, cat, set, activate)  # type: ignore
except Exception:
    # Fallback: just provide a no-op that opens addon settings.
    import xbmcaddon
    def _safe_open_settings(self, id=None, cat=None, set=None, activate=False):
        xbmcaddon.Addon().openSettings()

# Expose CONFIG proxy with patched method (monkey patch if attribute exists).
CONFIG = REAL_CONFIG
try:
    import types
    if hasattr(CONFIG, "open_settings"):
        # Preserve original implementation for internal use if it had __wrapped__
        setattr(CONFIG, "open_settings", _safe_open_settings.__get__(CONFIG, type(CONFIG)))
except Exception:
    pass
