# -*- coding: utf-8 -*-

from __future__ import annotations

try:
    from .__version__ import __version__
except Exception:
    __version__ = "6.1.0"


__all__ = ["install", "uninstall", "get_settings_widget", "__version__"]


_INSTALLED = False


def _get_bootstrap_module():
    from . import bootstrap
    return bootstrap


def _get_preferences_dialog_class():
    from .plugin_preferences_dialog import PreferencesDialog
    return PreferencesDialog


def install():
    global _INSTALLED

    if _INSTALLED:
        return

    bootstrap = _get_bootstrap_module()
    bootstrap.install_all()
    _INSTALLED = True


def uninstall():
    global _INSTALLED

    try:
        bootstrap = _get_bootstrap_module()
        bootstrap.uninstall_all()
    finally:
        _INSTALLED = False


def get_settings_widget(parent=None):
    PreferencesDialog = _get_preferences_dialog_class()
    return PreferencesDialog(parent)