// Qt
import QtQuick                  2.15
import QtGraphicalEffects       1.12

//  Qml imports
import "qrc:/globals"
import "qrc:/components"
import "qrc:/compounds"


SettingsBase    { id: _root
    property var fieldList  : []

    itemIndex       : SettingsStack.CalibrationSettings

    confirmVisible  : false

    Component.onCompleted:  _root.updateList (SettingsCalibrationSettings.Pressure)

    enum CalibrationSensor {
        Pressure    = 0,
        Temperature = 1
    }

    BaseComboBox { id: _componentComboBox
        anchors.top                 : _root.top
        anchors.topMargin           : Variables.headerButtonsMargin
        anchors.horizontalCenter    : parent.horizontalCenter
        height                      : Variables.contentHeight
        currentIndex                : 0
        model                       : [
            "Pressure Sensors"      ,
            "Temperature"           ,
            "Filters"
        ]

        onActivated: _root.updateList(currentIndex)
    }

    function updateList(vCurrentIndex) {
        fieldList = []

        switch(vCurrentIndex) {
        case SettingsCalibrationSettings.Pressure:
            fieldList.push("Gain")
            fieldList.push("Offset")
            fieldList.push("Offset")
            fieldList.push("Offset")

            break
        case SettingsCalibrationSettings.Temperature:
            fieldList.push("3f34")
            fieldList.push("34f43")
            break

        default:
            break
        }

        // Notify QML that the array changed
        fieldList = fieldList
    }

    component HeaderText: Text { id: _headerText
        property string title   : ""
        anchors.verticalCenter  : parent.verticalCenter
        leftPadding             : Variables.defaultMargin * 2
        text                    : _headerText.title
        color                   : Colors.white
        font.pixelSize          : Fonts.fontPixelTextRectTitle
        font.weight             : Font.Medium
    }

    contentItem: Item { id: _contentItem
        anchors.fill : parent
        readonly property int contentWith: _listView.width - Variables.defaultMargin * 2 // added margin to have scroll bar show on right

        Rectangle { id: _header
            color   : Colors.treatmentSectionHeader
            height  : Variables.institutionaltContainerHeight
            width   : _contentItem.contentWith
            radius  : 8.5

            Row { id: _headerRow
                width   : _contentItem.width
                height  : Variables.institutionaltContainerHeight

                HeaderText { id: _parameters;   title: qsTr("Description"); width: _contentItem.width * 0.2     }
                HeaderText { id: _minimum;      title: qsTr("Component");   width: _contentItem.width * 0.2     }

                Row { id: _headerComponentRow
                    width       : _contentItem.width * 0.6
                    height      : Variables.institutionaltContainerHeight

                    Repeater { id: _repeater
                        model   : _root.fieldList

                        delegate: HeaderText {
                            title               :  modelData
                            height              : Variables.institutionaltContainerHeight
                            width               : _headerComponentRow.width / _root.fieldList.length
                            verticalAlignment   : Text.AlignVCenter
                        }
                    }
                }
            }

            layer.enabled   : true
            layer.effect: DropShadow {
                id: _dropShadow
                horizontalOffset: 0
                verticalOffset  : 3
                radius          : 3.0
                samples         : 7
                color           : "#50000000"
                source          : _header
                anchors.fill    : _header
            }
        }

        ListView { id: _listView
            anchors {
                top         :_header.bottom
                topMargin   : 10
                left        : parent.left
                right       : parent.right
                bottom      : parent.bottom
            }
            boundsBehavior      : Flickable.StopAtBounds
            clip                : true
//            model               : vInstitutionalRecord.model
            spacing             : anchors.topMargin
            flickableDirection  : Flickable.VerticalFlick

        }

    }
}
