
// Qt
import QtQuick 2.12

// Project
import "qrc:/globals"
import "qrc:/components"
import "qrc:/compounds"

TreatmentAdjustmentBase { id: _root
    contentItem.objectName: "TreatmentAdjustmentHDF"
    titleText           : qsTr("HDF Adjustments")

    titlePixelSize      : Fonts.fontPixelSection
    height              : Variables.smallDialogHeight
    width               : Variables.smallDialogWidth

    readonly property bool  isValid         :   _prescribedFluidVolume.valid && _treatmentMode.valid
    readonly property int   txMode          :   _treatmentModeControl.value
    readonly property real  prescFluidVolume:   _prescribedFluidVolume.value

    function confirm() {
        vTreatmentAdjustmentHDF.doAdjustment(   _treatmentModeControl.value                    ,
                                                _prescribedFluidVolume.value                    )
    }

    onOpened: {
        _treatmentModeControl.currentIndex  = vTreatmentCreate.hdfTreatmentMode
        _prescribedFluidVolume.value        = vTreatmentCreate.substitutionFluidVolume
    }

    Column { id: _column
        spacing: Variables.defaultMargin * 2

        anchors {
            verticalCenter      : _root.contentItem.verticalCenter
            verticalCenterOffset: Variables.defaultMargin * -3 // better align label with dialog height
            horizontalCenter    : _root.contentItem.horizontalCenter
        }

        LabelUnitContainer { id: _treatmentMode
            objectName      : "_treatmentMode"
            text            : qsTr("Treatment Mode")
            width           : Variables.adjustmentLabelUnitContainerWidth
            height          : Variables.adjustmentLabelUnitContainerHeight
            valid           : ! vTreatmentAdjustmentHDF.treatmentModeRejectionReason

            onEditClicked   : _root.treatmentHDFEditClicked()

            contentItem : ValueAdjusterCustom { id: _treatmentModeControl
                value       : vTreatmentCreate.hdfTreatmentMode
                model       : vTreatmentRanges.hdfTreatmentModeOptions

                onDidChange         : function(vValue) {
                    if ( ! _treatmentMode.valid ) { vTreatmentAdjustmentHDF.treatmentModeRejectionReason = Variables.noRejectReason }
                    value = vValue
                }
            }
        }

        LabelUnitValueAdjuster { id: _prescribedFluidVolume
            objectName          : "_prescribedFluidVolume"
            text                : qsTr("Prescribed Sub. Fluid Volume")
            width               : Variables.adjustmentLabelUnitContainerWidth
            height              : Variables.adjustmentLabelUnitContainerHeight
            valid               : ! vTreatmentAdjustmentHDF.prescSubVolumeRejectionReason

            unitText            : Variables.unitVolume
            decimal             : Variables.substitutionPrecision
            valueTextColor      : Colors.offWhite
            isActive            : true
            minimum             : vTreatmentRanges.substitutionVolumeMin
            maximum             : vTreatmentRanges.substitutionVolumeMax
            step                : vTreatmentRanges.substitutionVolumeRes
            value               : vTreatmentCreate.substitutionFluidVolume
            defaultValue        : vTreatmentRanges.substitutionVolumeDef

            onDidChange         : function(vValue) {
                if ( ! _prescribedFluidVolume.valid ) { vTreatmentAdjustmentHDF.prescSubVolumeRejectionReason = Variables.noRejectReason }
                value = vValue
            }
        }
    }

    ConfirmButton { id : _confirmButton
        anchors {
            bottom          : _root.contentItem.bottom
            bottomMargin    : Variables.defaultMargin * 4
            horizontalCenter: _root.contentItem.horizontalCenter
        }

        width       : Variables.defaultButtonWidth
        height      : Variables.defaultButtonHeight
        enabled     : _root.isValid

        anchors {
            top     : undefined
            right   : undefined
            margins : 0
        }

        onClicked   : {
            _root.confirm()
        }
    }
}
