from PySide2 import QtWidgets


class LocalisedQPushButton(QtWidgets.QPushButton):
    def __init__(self, NativeUI, text_key, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.text_key = text_key
        self.setStyleSheet(
            "QPushButton{"
            "   color:" + NativeUI.colors["button_foreground_enabled"].name() + ";"
            "   background-color:"
            + NativeUI.colors["button_background_enabled"].name()
            + ";"
            "   border:none;"
            "}"
            "QPushButton::pressed{"
            "   background-color:" + NativeUI.colors["highlight"].name() + ";"
            "}"
        )
        self.localise_text(NativeUI.text)

    def localise_text(self, text: dict) -> int:
        self.setText(text[self.text_key])
        return 0

    def set_size(self, x: int, y: int, spacing: int = 0) -> int:
        """
        Set the size of the button.
        Wraps setFixedWidth and setFixedHeight for convenience
        """
        if x is not None:
            self.setFixedWidth(x)
        if y is not None:
            self.setFixedHeight(y)
        return 0


class LocalisedQRadioButton(QtWidgets.QRadioButton):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

    def localise_text(self, text: dict) -> int:
        """
        Change the language of text elements.
        """
        pass


class LocalisedQWidget(QtWidgets.QWidget):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

    def localise_text(self, text: dict) -> int:
        """
        Change the language of text elements.
        """
        pass


class LocalisedQStackedWidget(QtWidgets.QStackedWidget):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

    def localise_text(self, text: dict) -> int:
        """
        Change the language of text elements.
        """
        pass


class LocalisedQLabel(QtWidgets.QLabel):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

    def localise_text(self, text: dict) -> int:
        """
        Change the language of text elements.
        """
        pass


class LocalisedQDialog(QtWidgets.QDialog):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

    def localise_text(self, text: dict) -> int:
        """
        Change the language of text elements.
        """
        pass
