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

from View.Tools.PamhyrWindow import PamhyrDialog

from PyQt5.QtGui import (
    QKeySequence,
)

from PyQt5.QtCore import (
    Qt, QVariant, QAbstractTableModel,
)

from PyQt5.QtWidgets import (
    QDialogButtonBox, QComboBox, QUndoStack, QShortcut,
    QDoubleSpinBox,
)

from View.SedimentLayers.Reach.translate import *

_translate = QCoreApplication.translate


class SLDialog(PamhyrDialog):
    _pamhyr_ui = "SLDialog"
    _pamhyr_name = "SL"

    def __init__(self, study=None, config=None, parent=None):
        super(SLDialog, self).__init__(
            title=self._pamhyr_name,
            study=study,
            config=config,
            parent=parent
        )

        self.setup_combobox()

        self.value = None

    def setup_combobox(self):
        self.combobox_add_items(
            "comboBox",
            [_translate("SedimentLayers", "Not defined")] +
            list(
                map(
                    lambda sl: str(sl),
                    self._study.river.sediment_layers.sediment_layers
                )
            )
        )

    @property
    def sl(self):
        if self.value == _translate("SedimentLayers", "Not defined"):
            return None

        return next(
            filter(
                lambda sl: str(sl) == self.value,
                self._study.river.sediment_layers.sediment_layers
            )
        )

    def accept(self):
        self.value = self.get_combobox_text("comboBox")
        super().accept()
