/*!
 *
 * Copyright (c) 2020-2024 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    TreatmentAdjustmentUltrafiltrationStart.qml
 * \author  (last)      Vy
 * \date    (last)      16-Mar-2023
 * \author  (original)  Behrouz NematiPour
 * \date    (original)  12-May-2020
 *
 */

// Qt
import QtQuick 2.12

// Project

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

/*!
 * \brief   TreatmentAdjustmentUltrafiltrationStart.qml is the screen
 *          To adjust the treatment ultrafiltration
 */
TreatmentAdjustmentBase { id: _root
    contentItem.objectName: "TreatmentAdjustmentUltrafiltrationStart"  //SquishQt testability

    QtObject { id: _private
        readonly property real minimum  : vTreatmentRanges.treatmentRanges_Ultrafiltration_Volume_Min
        readonly property real maximum  : vTreatmentRanges.treatmentRanges_Ultrafiltration_Volume_Max
        property real setVolume         : vTreatmentUltrafiltration.setVolume
        property real volumeRemoved     : vTreatmentUltrafiltration.volumeRemoved
    }

    signal editClicked()
    signal isolatedUfClicked()
    signal pauseClicked()
    signal resumeClicked()

    confirmVisible: false

    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       : _private.setVolume
        volumeRemoved   : _private.volumeRemoved
    }

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

        ProgressBarEx { id: _progressbarex
            anchors {
                left            : parent.left
                right           : parent.right
                verticalCenter  : parent.verticalCenter
            }
            height  : Variables.ultraFiltrationProgressBarHeight
            decimal : Variables.ultrafiltrationPrecision
            minimum : _private.minimum
            maximum : _private.setVolume
            value   : _private.volumeRemoved
            valueEx : 0
            color   : Colors.ufProgressBarFill
            bgColor : Colors.ufAdjustmentDeltaFill
            minText {
                font {
                    pixelSize   : Fonts.fontPixelUltrafiltrationMinMaxLabel
                    weight      : Font.Normal
                }
                color           : Colors.progressBarMinMax
                text            : minimum.toFixed(Variables.ultrafiltrationPrecision) + " " + Variables.unitVolume
            }
            maxText {
                font {
                    pixelSize   : minText.font.pixelSize
                    weight      : minText.font.weight
                }
                color           : Colors.progressBarMinMax
                text            : _private.setVolume.toFixed(Variables.ultrafiltrationPrecision) + " " + Variables.unitVolume
            }
            marker {
                width           : Variables.ultrafiltrationRangeMarkerWidth
                handle.width    : Variables.ultrafiltrationRangeMarkerHandleWidth
                valueOnTop      : true
                text {
                    anchors.bottomMargin: marker.valueOnTop ? 13 : 0
                    font {
                        pixelSize: Fonts.fontPixelUltrafiltrationRangeMarker
                        weight   : Font.DemiBold
                    }
                }
            }
        }
    }

    TouchRect { id: _pauseButton
        anchors {
            bottom          : information.top
            bottomMargin    : Variables.ultrafiltrationButtonBottomMargin
            horizontalCenter: parent.horizontalCenter
        }
        width       : Variables.defaultButtonWidth
        height      : Variables.defaultButtonHeight
        text {
            text        : qsTr("Pause Ultrafiltration")
            font.weight : Font.Medium
        }
        isDefault   : true
        visible     : isUFPaused === false

        onClicked   : _root.pauseClicked()
    }

    Row { id: _pausedButtonArea
        anchors.centerIn    : _pauseButton
        spacing             : Variables.defaultMargin
        visible             : ! _pauseButton.visible

        TouchRect { id: _resumeButton
            width       : Variables.defaultButtonWidth
            height      : Variables.defaultButtonHeight
            text {
                text        : qsTr("Resume Ultrafiltration")
                font.weight : Font.Medium
            }
            isDefault   : true
            onClicked   : _root.resumeClicked()
        }

        TouchRect { id: _editButton
            width       : Variables.defaultButtonWidth
            height      : Variables.defaultButtonHeight
            text {
                text        : qsTr("Edit UF")
                font.weight : Font.Medium
            }
            isDefault   : true
            onClicked   : _root.editClicked()
        }

        TouchRect { id: _isolatedUfButton
            width       : Variables.defaultButtonWidth
            height      : Variables.defaultButtonHeight
            text {
                text        : qsTr("Isolated UF")
                font.weight : Font.Medium
            }
            isDefault   : true
            onClicked   : _root.isolatedUfClicked()
        }
    }

    Text { id: _informationText
        text: qsTr("Note: Ultrafiltration must be paused to edit the volume.")
        color: "#a3b7c9"
        font {
           pixelSize: 25
       }

        anchors {
            bottom          : _pauseButton.top
            bottomMargin    : 25
            horizontalCenter: parent.horizontalCenter
        }
        visible: _pauseButton.visible
    }
}
