from ngSkinTools2.python_compatibility import Object
from PySide2 import QtWidgets, QtCore
from ngSkinTools2.ui import qt
from maya import cmds

try:
    scale_multiplier = cmds.mayaDpiSetting(q=True, realScaleValue=True)
except:
    #  the command is not available on macos, using 1.0 for fallback
    scale_multiplier = 1


def createTitledRow(title, contents, *additional_rows):
    row = QtWidgets.QFormLayout()
    row.setMargin(0)
    label = QtWidgets.QLabel(title)
    # label.setAlignment(QtCore.Qt.AlignRight |QtCore.Qt.)
    label.setFixedWidth(100 * scale_multiplier)

    if contents is None:
        row.addRow(label, QtWidgets.QWidget())
        return row

    row.addRow(label, contents)
    for i in additional_rows:
        row.addRow(None, i)
    return row


class TabSetup(Object):
    def __init__(self):
        self.innerLayout = innerLayout = QtWidgets.QVBoxLayout()
        innerLayout.setMargin(0)
        innerLayout.setSpacing(3 * scale_multiplier)

        self.scrollArea = scrollArea = QtWidgets.QScrollArea()
        scrollArea.setFocusPolicy(QtCore.Qt.NoFocus)
        scrollArea.setFrameShape(QtWidgets.QFrame.NoFrame)
        scrollArea.setWidget(qt.wrap_layout_into_widget(innerLayout))
        scrollArea.setWidgetResizable(True)

        self.lowerButtonsRow = lowerButtonsRow = QtWidgets.QHBoxLayout()

        self.mainLayout = mainLayout = QtWidgets.QVBoxLayout()
        mainLayout.addWidget(scrollArea)
        mainLayout.addLayout(lowerButtonsRow)
        mainLayout.setMargin(7)

        self.tabContents = qt.wrap_layout_into_widget(mainLayout)
