/*!
 *
 * Copyright (c) 2020-2023 Diality Inc. - All Rights Reserved.
 * \copyright
 * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN
 * WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER.
 *
 * \file    TreatmentAdjustmentUltrafiltrationEdit.qml
 * \author  (last)      Vy
 * \date    (last)      20-Mar-2023
 * \author  (original)  Behrouz NematiPour
 * \date    (original)  15-May-2020
 *
 */

// Qt
import QtQuick 2.12

// Project

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

/*!
 * \brief   TreatmentAdjustmentUltrafiltrationEdit.qml is the screen
 *          To adjust the treatment ultrafiltration
 */
TreatmentAdjustmentBase { id: _root
    contentItem.objectName: "TreatmentAdjustmentUltrafiltrationEdit"  //SquishQt testability
    QtObject { id: _private
        property int  decimal   : Variables.ultrafiltrationPrecision
        property real minAdjust : vTreatmentRanges.treatmentRanges_Ultrafiltration_Volume_Min
        property real valAdjust : _volumeSlider.value
        property real maxAdjust : vTreatmentRanges.treatmentRanges_Ultrafiltration_Volume_Max

        property real min       : vTreatmentUltrafiltration.minimum
        property real val       : vTreatmentUltrafiltration.ultrafiltration_RefUFVol
        property real max       : vTreatmentUltrafiltration.maximum
    }

    signal   nextClicked(real vVolume)

    function reset() {
        _volumeSlider.value = _private.max
    }

      closeVisible  : false
    confirmVisible  : false
       backVisible  : true

   information {
       visible     : true && information.text && ! notification.visible
       imageSource : ufInfoImageSource
       text        : ufInfoText
   }

    titleText   : qsTr("ULTRAFILTRATION VOLUME") + "   " + Variables.unitTextUltrafiltrationVolume

    ProgressBarEx { id: _rangeProgressBar
        width   : Variables.ultrafiltrationProgressbarWidth
        height  : Variables.ultraFiltrationProgressBarHeight
        anchors {
            top         : parent.top
            topMargin   : 250
            right       : parent.right
            rightMargin : _volumeSliderArrows.width + Variables.sliderAdjustButtonSpacing*2
        }
        decimal : _private.decimal
        minimum : _private.min // suppose to be always 0 // DEN-6022 // _private.maxAdjust => _private.min
        maximum : _private.maxAdjust
        value   : _private.val
        valueEx : _private.valAdjust
        progressEx.maxText.visible: false
    }

    Slider { id: _volumeSlider
        // TODO : These two values shall get from a model
        property int minGapValue: 0 // No gap for now.
        property int maxGapValue: 0 // No gap for now.

        readonly property int minPrgWidth: _rangeProgressBar.maximum - _rangeProgressBar.minimum
        readonly property int maxPrgWidth: _rangeProgressBar.maximum - _rangeProgressBar.minimum
        readonly property int minGapWidth: minPrgWidth > 0 ? (minGapValue * _rangeProgressBar.width) / minPrgWidth : 0
        readonly property int maxGapWidth: maxPrgWidth > 0 ? (maxGapValue * _rangeProgressBar.width) / maxPrgWidth : 0

        anchors {
            top: _rangeProgressBar.bottom
            topMargin: 50
        }

        x       : _rangeProgressBar.x       + minGapWidth               + _rangeProgressBar.progressWidth
        width   : _rangeProgressBar.width   - maxGapWidth - minGapWidth - _rangeProgressBar.progressWidth
        height  : Variables.ultraFiltrationEditSliderHeight
        step    : 0.100
        stepSnap: true
        ticks   : true
        decimal : _private.decimal
        minimum : _private.minAdjust + minGapValue
        maximum : _private.maxAdjust - maxGapValue
    }

    SliderArrows{ id: _volumeSliderArrows
        visible : true
        anchors.verticalCenter  : _volumeSlider.verticalCenter
        anchors.right           : parent.right
        anchors.rightMargin     : Variables.sliderAdjustButtonSpacing

        onIncrementValue        : _volumeSlider.incrementValue(true)
        onDecrementValue        : _volumeSlider.decrementValue(true)
    }

    Text { id: _textVolume
        visible : true
        color   : Colors.textMain
        text    : _private.valAdjust.toFixed(_private.decimal)
        font {
            pixelSize  : Fonts.fontPixelUltrafiltrationAdjustmentEditValue
        }
        anchors {
            horizontalCenter: parent.horizontalCenter
            top             : parent.top
            topMargin       : 150
        }
    }

    TouchRect { id: _nextButton
        width   : 530
        height  :  95
        anchors {
            top: parent.top
            topMargin: 460
            horizontalCenter: parent.horizontalCenter
        }
        isDefault: true
        text {
            text: qsTr("NEXT")
            font.weight   : Font .DemiBold
            font.pixelSize: Fonts.fontPixelUltrafiltrationAdjustmentNextButton
        }
        onClicked: nextClicked( _private.valAdjust.toFixed(_private.decimal) )
    }
}
