from qgis.PyQt.QtGui import QIcon
from qgis.PyQt.QtWidgets import (
    QAction,
    QDialog,
    QGridLayout,
    QLabel,
    QMenu,
    QMessageBox,
    QPushButton,
    QSizePolicy,
    QWidget,
    QWizard,
)


def get_wizard_buttons(
    load_db: bool = True,
    save_db: bool = True,
    load_json: bool = True,
    save_json: bool = True,
):
    class WizardProfileButton:
        """
        Class containing wizard's button for saving/loading import profiles.
        """

        profile_btn = QPushButton("Import profile")
        profile_btn.setIcon(QIcon(":images/themes/default/mActionSharingImport.svg"))
        main_menu = QMenu()
        load_profile_menu = QMenu("Load")
        load_profile_menu.setIcon(QIcon(":images/themes/default/mActionFileOpen.svg"))
        load_profile_db = QAction(
            QIcon(":images/themes/default/dbmanager.svg"), "Database"
        )
        load_profile_db.setEnabled(load_db)
        load_profile_file = QAction(
            QIcon(":images/themes/default/mIconFieldJson.svg"), "JSON"
        )
        load_profile_file.setEnabled(load_json)
        load_profile_menu.addAction(load_profile_db)
        load_profile_menu.addAction(load_profile_file)
        save_profile_menu = QMenu("Save")
        save_profile_menu.setIcon(QIcon(":images/themes/default/mActionFileSaveAs.svg"))
        save_profile_db = QAction(
            QIcon(":images/themes/default/dbmanager.svg"), "Database"
        )
        save_profile_db.setEnabled(save_db)
        save_profile_file = QAction(
            QIcon(":images/themes/default/mIconFieldJson.svg"), "JSON"
        )
        save_profile_file.setEnabled(save_json)
        save_profile_menu.addAction(save_profile_db)
        save_profile_menu.addAction(save_profile_file)
        main_menu.addMenu(load_profile_menu)
        main_menu.addMenu(save_profile_menu)
        profile_btn.setMenu(main_menu)

    return WizardProfileButton()


class ImportProfileGenerator:
    """
    Class for importing/exporting profile from import wizard.
    Must be instantiated as import QWizard attribute.
    Args:
        - wizard : parent
        - load_db : True if dedicated button is enabled
        - save_db : True if dedicated button is enabled
        - load_json : True if dedicated button is enabled
        - save_json : True if dedicated button is enabled
    """

    def __init__(
        self,
        wizard: QWizard,
        load_db: bool = True,
        save_db: bool = True,
        load_json: bool = True,
        save_json: bool = True,
    ):
        self.wizard = wizard
        self.wizard_button = get_wizard_buttons(load_db, save_db, load_json, save_json)
        self.wizard_button.load_profile_db.triggered.connect(self._load_profile_db_slot)
        self.wizard_button.load_profile_file.triggered.connect(
            self._load_profile_file_slot
        )
        self.wizard_button.save_profile_db.triggered.connect(self._save_profile_db_slot)
        self.wizard_button.save_profile_file.triggered.connect(
            self._save_profile_file_slot
        )

    def get_wizard_button(self):
        return self.wizard_button.profile_btn

    def _load_profile_db_slot(self):
        pass

    def _load_profile_file_slot(self):
        pass

    def _save_profile_db_slot(self):
        pass

    def _save_profile_file_slot(self):
        pass


class ImportProfileManager(QDialog):
    pass
