/*!
 *
 * Copyright (c) 2020-2025 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)      Stephen Quong
 * \date    (last)      08-Oct-2025
 * \author  (original)  Behrouz NematiPour
 * \date    (original)  15-May-2020
 *
 */

// Qt
import QtQuick 2.12

// Project

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

/*!
 * \brief   TreatmentAdjustmentUltrafiltrationEdit.qml is the screen
 *          To adjust the treatment ultrafiltration
 */
TreatmentAdjustmentBase { id: _root
    contentItem.objectName: "TreatmentAdjustmentUltrafiltrationEdit"  //SquishQt testability
    QtObject { id: _private
        readonly property real minimum          : vTreatmentRanges.treatmentRanges_Ultrafiltration_Volume_Min
        readonly property real maximum          : vTreatmentRanges.treatmentRanges_Ultrafiltration_Volume_Max
        readonly property real volumeRes        : vTreatmentRanges.ultrafiltrationVolumeRes
        readonly property real setVolume        : vTreatmentUltrafiltration.setVolume
        readonly property real volumeRemoved    : vTreatmentUltrafiltration.volumeRemoved
    }

    signal   continueClicked(real vVolume)

    function reset() {
        _setVolumeSlider.reset(_private.setVolume)
    }

      closeVisible  : false
    confirmVisible  : false
       backVisible  : true

   information {
        visible     : true && information.text && ! notification.visible
        imageSource : ufInfoImageSource
        text        : ufInfoText
        color           : Colors.ufNotificationBarBg
        textColor       : Colors.ufVolumeGoalText
        textfontSize    : Fonts.fontPixelUltrafiltrationAdjustmentNotification
        textfontWeight  : Font.Medium
   }

    titleText   : qsTr("Ultrafiltration Volume ") + Variables.unitTextUltrafiltrationVolume

    TreatmentAdjustmentUltrafiltrationMetrics { id: _ufMetrics
        anchors {
            top             : parent.top
            topMargin       : Variables.ultrafiltrationHeaderMargin
            horizontalCenter: parent.horizontalCenter
        }
        setVolume       : _setVolumeSlider.value
        volumeRemoved   : _private.volumeRemoved
    }

    Item { id: _contentArea
        anchors {
            top         : _ufMetrics.bottom
            bottom      : _continueButton.top
            left        : parent.left
            leftMargin  : 80
            right       : parent.right
            rightMargin : anchors.leftMargin
        }

        StoppedSlider { id: _setVolumeSlider
            anchors {
                left            : parent.left
                right           : parent.right
                verticalCenter  : parent.verticalCenter
            }
            decimal         : Variables.ultrafiltrationPrecision
            minimum         : _private.minimum
            minStop         : _private.volumeRemoved
            maximum         : _private.maximum
            step            : _private.volumeRes.toFixed(Variables.ultrafiltrationPrecision)
            unit            : Variables.unitVolume
            defaultValue    : { defaultValue = _private.setVolume } // set without binding
            active          : true
        }
    }

    TouchRect { id: _continueButton
        anchors {
            bottom          : information.top
            bottomMargin    : Variables.ultrafiltrationButtonBottomMargin
            horizontalCenter: parent.horizontalCenter
        }
        width       : Variables.ultrafiltrationButtonWidth
        height      : Variables.ultrafiltrationButtonHeight
        text {
            text        : qsTr("Continue")
            font.weight : Font.Medium
        }
        isDefault   : true
        enabled     : _setVolumeSlider.value.toFixed(_setVolumeSlider.decimal) !==
                            _private.setVolume.toFixed(_setVolumeSlider.decimal)
        onClicked   : continueClicked(_setVolumeSlider.value.toFixed(_setVolumeSlider.decimal))
    }
}
