from pathlib import Path

from qgis.PyQt.QtWidgets import QDialog, QWidget

# Import needed for CSS images
import oslandia.resources.resource_rc
from oslandia.__about__ import DIR_PLUGIN_ROOT


BACKGROUND_BLACK_SEMI_TRANSPARENT = "background-color: rgba(0, 0, 0, 180);"

SPLITTER = """
QSplitter::handle {
    background-color: palette(mid);
}

QSplitter::handle:hover {
    background-color: palette(highlight);
}

QSplitter::handle:pressed {
    background-color: palette(dark);
}

""".strip()


class BaseStyleSheet:
    """Mixin to apply a global stylesheet to any QWidget or QDialog."""

    def apply_global_stylesheet(self):
        """Loads and applies the global plugin stylesheet."""
        style_path = Path(DIR_PLUGIN_ROOT) / "resources/style/light_oslandia.qss"
        if style_path.exists():
            with open(style_path, "r") as file:
                stylesheet = file.read()
            self.setStyleSheet(stylesheet)


class WidgetStyleSheet(QWidget, BaseStyleSheet):
    """QWidget with an automatically applied oslandia global stylesheet."""

    def __init__(self, parent=None):
        super().__init__(parent)
        self.apply_global_stylesheet()


class DialogStyleSheet(QDialog, BaseStyleSheet):
    """QDialog with an automatically applied oslandia global stylesheet."""

    def __init__(self, parent=None):
        super().__init__(parent)
        self.apply_global_stylesheet()
