/*!
 *
 * Copyright (c) 2021-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    EndTreatmentRinseback.qml
 * \author  (last)      Behrouz NematiPour
 * \date    (last)      13-Sep-2023
 * \author  (original)  Behrouz NematiPour
 * \date    (original)  11-Apr-2021
 *
 */

// Qt
import QtQuick 2.12

// Project
//  Qml imports
import "qrc:/globals"
import "qrc:/components"
import "qrc:/pages/endtreatment"
import "qrc:/pages/treatment"
import "qrc:/pages/treatment/sections"

/*!
 * \brief   the end treatment rinseback screen
 */
EndTreatmentBase { id: _root
    objectName      : "_EndTreatmentRinseback"

    headerTitle     : qsTr("Blood Return")

    signal pauseClicked  ()
    signal resumeClicked ()

    signal accelerateClicked  ()
    signal deccelerateClicked ()

    Column { id: _contentColumn
        objectName  : "_contentColumn"
        anchors {
            top                 : parent.top
            topMargin           : Variables.defaultMargin
            horizontalCenter    : parent.horizontalCenter
        }
        spacing     : Variables.defaultMargin * 2

        ProgressCircle { id: _targetVolumeProgress
            objectName                  : "_targetVolumeProgress"
            anchors.horizontalCenter    : parent.horizontalCenter
            thickness                   : 35
            circleShadowColor           : Colors.mainTreatmentLighterBlue
            runAnimation                : vTDTreatmentStates.rbPaused
            minimum                     : 0
            maximum                     : vTreatmentRinseback.target
            value                       : vTreatmentRinseback.current

            Text { id: _deliveredVolumeText
                objectName      : "_deliveredVolumeText"
                anchors.centerIn: parent
                height          : contentHeight
                font {
                    pixelSize   : 76
                    weight      : Font.Light
                }
                color           : vTDTreatmentStates.rbPaused ? Colors.ufVolumeGoalText : Colors.offWhite
                text            : vTreatmentRinseback.current.toFixed(0) + " " + qsTr(Variables.unitTextFluid)
            }

            TimeText { id: _timeout
                objectName      : "_timeout"
                anchors {
                    bottom          : _deliveredVolumeText.top
                    bottomMargin    : Variables.defaultMargin * 2
                    horizontalCenter: parent.horizontalCenter
                }
                textPixelSize   : 30
                textWeight      : Font.DemiBold
                secondsVisible  : false
                seconds         : vTreatmentRinseback.timeoutCountDown * 60
                visible         : vTreatmentRinseback.timeoutTotal
            }

            NotificationBarSmall { id: _pausedNotification
                objectName      : "_pausedNotification"
                anchors {
                    top                 : _deliveredVolumeText.bottom
                    bottom              : undefined
                    topMargin           : _timeout.anchors.bottomMargin
                }
                visible         : vTDTreatmentStates.rbPaused
                height          : 25
                color           : "transparent"
                imageDiameter   : 25
                imageTopMargin  : 4
                imageSource     : "qrc:/images/iPauseOrange"
                text            : qsTr("Rinseback Paused")
                textColor       : Colors.mainTreatmentOrange
                textfontSize    : 22
                textfontWeight  : Font.Medium
            }
        }

        Row { id: _bottomContentRow
            objectName                  : "_bottomContentRow"
            anchors.horizontalCenter    : parent.horizontalCenter
            spacing                     : Variables.defaultMargin

            TreatmentSection { id: _treatmentFlowRate
                objectName              : "_treatmentFlowRate"
                anchors.verticalCenter  : parent.verticalCenter
                width                   : parent.width / 3
                height                  : _treatmentPressures.height
                header {
                    title               : qsTr("Blood Flow Rate")
                    showEdit            : false
                }
                contentItem             : Item { id: _flowRateItem
                    objectName: "_flowRatItem"

                    Item { id: _flowRateControlArea
                        objectName          : "_flowRateControlArea"
                        anchors {
                            top             : parent.top
                            bottom          : _flowRateButtonRow.top
                            bottomMargin    : Variables.defaultMargin * 2
                            left            : parent.left
                            leftMargin      : Variables.defaultMargin
                            right           : parent.right
                            rightMargin     : anchors.leftMargin
                        }

                        Item { id: _flowRateValueItem
                            objectName          : "_flowRateValueItem"
                            anchors.centerIn    : parent
                            width               : childrenRect.width
                            height              : childrenRect.height

                            ArrowButton { id: _decrementFlowRateButton
                                objectName  : "_decrementFlowRateButton"
                                anchors {
                                    left            : parent.left
                                    verticalCenter  : _flowRateValue.verticalCenter
                                }
                                leftArrow   : true
                                enabled     : vTreatmentRinseback.rate > vTreatmentRanges.rinsebackFlowRateMin

                                onClicked   : { _root.deccelerateClicked() }
                            }

                            Text { id: _flowRateValue
                                objectName          : "_flowRateValue"
                                anchors {
                                    top         : parent.top
                                    left        : _decrementFlowRateButton.right
                                    leftMargin  : Variables.defaultMargin
                                }
                                width               : 200
                                height              : Variables.defaultButtonHeight
                                font {
                                    pixelSize   : Fonts.fontPixelVitals
                                    weight      : Font.Medium
                                }
                                color               : Colors.textTextRectLabel
                                horizontalAlignment : Text.AlignHCenter
                                verticalAlignment   : Text.AlignVCenter
                                text                : vTreatmentRinseback.rate
                            }

                            Text { id: _flowRateUnit
                                objectName          : "_flowRateUnit"
                                anchors {
                                    top                 : _flowRateValue.bottom
                                    topMargin           : Variables.defaultMargin
                                    horizontalCenter    : _flowRateValue.horizontalCenter
                                }
                                width               : contentWidth
                                height              : contentHeight
                                font {
                                    pixelSize   : Fonts.fontPixelContainerUnit
                                    weight      : Font.Thin
                                }
                                color               : Colors.offWhite
                                horizontalAlignment : Text.AlignHCenter
                                verticalAlignment   : Text.AlignVCenter
                                text                : Variables.unitTextFlowRate
                            }

                            ArrowButton { id: _incrementFlowRateButton
                                objectName  : "_incrementFlowRateButton"
                                anchors {
                                    left            : _flowRateValue.right
                                    leftMargin      : _flowRateValue.anchors.leftMargin
                                    verticalCenter  : _flowRateValue.verticalCenter
                                }
                                rightArrow  : true
                                enabled     : vTreatmentRinseback.rate < vTreatmentRanges.rinsebackFlowRateMax

                                onClicked   : { _root.accelerateClicked() }
                            }
                        }
                    }

                    Row { id: _flowRateButtonRow
                        objectName: "_flowRateButtonRow"
                        anchors {
                            bottom          : parent.bottom
                            horizontalCenter: parent.horizontalCenter
                            margins         : Variables.defaultMargin
                        }
                        spacing: Variables.defaultMargin * 2

                        TouchRect { id: _pauseResumeButton
                            objectName: "_pauseResumeButton"
                            width       : Variables.defaultButtonWidth
                            height      : Variables.defaultButtonHeight
                            text {
                                text        : vTDTreatmentStates.rbPaused ? qsTr("Resume") : qsTr("Pause")
                                font.weight : Font.Medium
                            }
                            isDefault   : true
                            enabled     : true

                            onClicked   : { vTDTreatmentStates.rbPaused
                                ? _root.resumeClicked()
                                : _root.pauseClicked()
                            }
                        }
                    }
                }
            }

            TreatmentPressures { id: _treatmentPressures
                objectName              : "_treatmentPressures"
                anchors.verticalCenter  : parent.verticalCenter
                width                   : 750
                height                  : 420
                header.showEdit         : false
            }
        }
    }
}
