/*!
 *
 * 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    TreatmentUltrafiltration.qml
 * \author  (last)      Behrouz NematiPour
 * \date    (last)      26-Sep-2023
 * \author  (original)  Behrouz NematiPour
 * \date    (original)  27-Jan-2020
 *
 */

// Qt
import QtQuick 2.12

// Project

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

/*!
 * \brief   Treatment Screen Ultrafiltration section
 */

TreatmentSection { id: _root
    readonly property real minimum  : vTreatmentRanges.treatmentRanges_Ultrafiltration_Volume_Min
    readonly property real maximum  : vTreatmentUltrafiltration.setVolume
    readonly property real value    : vTreatmentUltrafiltration.volumeRemoved
    readonly property real paused   : vTreatmentUltrafiltration.ufPaused
    readonly property real running  : vTreatmentUltrafiltration.ufRunning

    readonly property int topTextFontSize       : 25
    readonly property int bottomTextFontSize    : 60
    readonly property bool isUfCompleted        : value >= maximum && maximum > 0

    readonly property string statusText        :    isUfCompleted   ? qsTr ("Ultrafiltration Complete") :
                                                    paused          ? qsTr ("Ultrafiltration Paused")   :
                                                    running         ? ""                                : ""

    readonly property color statusColor        :    isUfCompleted   ? Colors.statusTextComplete :
                                                    paused          ? Colors.statusPaused       :
                                                    running         ? Colors.transparent        : Colors.transparent
    header.showPauseResume          : true
    header.isPaused                 : _root.paused
    header.title                    : qsTr("Ultrafiltration") + " (" + qsTr("UF") + ")"
    contentArea.anchors.topMargin   : Variables.defaultMargin

    onPauseResumeClicked: _root.paused ? vTreatmentAdjustmentUltrafiltrationState.doResume() :
                                         vTreatmentAdjustmentUltrafiltrationState.doPause()

    contentItem: Row { id: _row
        spacing     : Variables.defaultMargin * 6
        rightPadding: Variables.defaultMargin
        leftPadding : Variables.defaultMargin

        Column { id: _leftColumn
            spacing : Variables.defaultMargin * 6
            width   : contentItem.width * 0.2
            height  : _root.height

            LabelValue { id: _ufVolume
                height                  : 40
                width                   : contentItem.width * 0.2

                topText                 : qsTr("UF Volume Goal")
                topTextFont.pixelSize   : topTextFontSize
                topTextFont.weight      : Font.Medium

                bottomText              : vTreatmentUltrafiltration.setVolume.toFixed(Variables.ultrafiltrationPrecision)
                bottomTextFont.pixelSize: bottomTextFontSize
                bottomTextFont.weight   : Font.Normal
                leftAlign               : true
                unitText                : Variables.unitVolume
                showCenterText          : true
            }

            LabelValue { id: _ufRate
                height                  : 40
                width                   : contentItem.width * 0.2

                topText                 : qsTr("UF Rate")
                topTextFont.pixelSize   : topTextFontSize
                topTextFont.weight      : Font.Medium

                bottomText              :  isTreatmentEnd || _root.isUfCompleted ? qsTr("OFF") :
                                                                                   vTreatmentUltrafiltration.targetRate.toFixed(Variables.ultrafiltrationPrecision)
                bottomTextFont.pixelSize: bottomTextFontSize
                bottomTextFont.weight   : Font.Normal
                bottomTextColor         : _root.paused ? Colors.statusTextPaused : Colors.textTextRectLabel
                leftAlign               : true
                unitText                : Variables.unitTextRate
                bottomTextTopMargin     : Variables.defaultMargin
            }
        }

        Column { id: _rightColumn
            topPadding  : Variables.defaultMargin
            spacing     : Variables.defaultMargin * 5
            width       : contentItem.width
            height      : _root.height

            Item { id: _statusItem
                width   : _rightColumn.width * 0.6
                height  : 40
                Rectangle { id: _status
                    anchors.verticalCenter  : parent.verticalCenter
                    anchors.right           : parent.right
                    color                   : _root.statusColor
                    width                   : _statusText.contentWidth + Variables.defaultMargin * 2
                    height                  : _statusText.contentHeight + Variables.defaultMargin
                    radius                  : height

                    Text { id: _statusText
                        anchors.centerIn: parent
                        font.pixelSize  : 18
                        font.weight     : Font.DemiBold
                        text            : _root.statusText
                        color           : Colors.offWhite
                    }
                }
            }

            ProgressBar { id: _progressbar
                enabled : ! isSBInProgress

                width   : contentItem.width * 0.6
                height  : 20

                decimal : Variables.ultrafiltrationPrecision
                minimum : _root.minimum
                maximum : _root.maximum
                value   : _root.value
                unitText: Variables.unitVolume
                color   : _root.paused ? Colors.pauseColor : Colors.progressBarUltrafiltration
                radius          : height
                showMarker      : false

                minText.color: "#818181"
                minText.font {
                    pixelSize   : 18
                    weight      : Font.Normal
                }

                maxText.color: "#818181"
                maxText.font {
                    pixelSize   : 18
                    weight      : Font.Normal
                }

                Text { id: _valueText
                    anchors {
                        bottom      : parent.top
                        bottomMargin   : Variables.defaultMargin
                        right       : parent.right
                    }
                    text            : _root.value.toFixed(Variables.ultrafiltrationPrecision) + " " + Variables.unitVolume
                    color           :  _root.paused ? Colors.statusTextPaused : Colors.offWhite
                    font.pixelSize  : 40
                    font.weight     : Font.DemiBold

                }

                Text { id: _volumeRemovedText
                    anchors {
                        top         : parent.bottom
                        topMargin   : Variables.defaultMargin * 2.5
                        right       : parent.right
                    }
                    text            : qsTr("Volume Removed")
                    color           : Colors.textTextRectLabel
                    font.pixelSize  : 20
                    font.weight     : Font.Medium
                }
            }
        }
    }
}
