/*!
 *
 * Copyright (c) 2019-2020 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) Behrouz NematiPour
 * \date (last) 20-Aug-2020
 * \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   : vTreatmentUltrafiltration.precision
        property real minimum   : vTreatmentRanges.treatmentRanges_Ultrafiltration_Volume_Min
        property real maximum   : vTreatmentRanges.treatmentRanges_Ultrafiltration_Volume_Max
        property real value     : vTreatmentUltrafiltration.ultrafiltration_RefUFVol

        property real current   : vTreatmentUltrafiltration.maximum
        property real adjusted  : _volumeSlider.value
    }

    signal   nextClicked(real vVolume)

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

      closeVisible  : false
    confirmVisible  : false
       backVisible  : true
     pausedVisible  : true

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

    ProgressBarEx { id: _rangeProgressBar
        width   : Variables.ultrafiltrationProgressbarWidth
        height  : Variables.progressbarHeight
        anchors {
            top: parent.top
            topMargin: 250
            horizontalCenter: parent.horizontalCenter
        }
        decimal : _private.decimal
        minimum : _private.minimum
        maximum : _private.maximum
        value   : _private.value
        valueEx : _private.adjusted
        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

        height  : 2
        anchors {
            top: _rangeProgressBar.bottom
            topMargin: 50
        }
        bgColor: "#0c2135"

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

    Text { id: _textVolume
        visible : true
        color   : "white"
        text    : _private.adjusted.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
        }

        backgroundColor: Colors.backgroundButtonSelect

        text {
            text: qsTr("NEXT")
            font.weight   : Font .DemiBold
            font.pixelSize: Fonts.fontPixelUltrafiltrationAdjustmentNextButton
        }
        onClicked: nextClicked( _private.adjusted.toFixed(_private.decimal) )
    }
}
