/*!
 *
 * 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"
    title.text      : qsTr("Rinseback")

    signal pauseClicked  ()
    signal resumeClicked ()
    signal endClicked    ()

    signal accelerateClicked  ()
    signal deccelerateClicked ()

    ProgressCircle { id: _targetVolumeProgress
        objectName          : "_targetVolumeProgress"
        anchors {
            left            : parent.left
            leftMargin      : Variables.defaultMargin * 2
            verticalCenter  : parent.verticalCenter
        }
        thickness           : 35
        circleShadowColor   : Colors.mainTreatmentLighterBlue
        circleFillColor     : Colors.mainTreatmentDarkerBlue
        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           : Colors.textMain
            text            : vTreatmentRinseback.current.toFixed(0) + " " + qsTr(Variables.unitTextFluid)
        }

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

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

    TreatmentSection { id: _treatmentFlowRate
        objectName      : "_treatmentFlowRate"
        anchors {
            left            : _targetVolumeProgress.right
            leftMargin      : Variables.defaultMargin
            right           : _treatmentPressures.left
            rightMargin     : Variables.defaultMargin
            verticalCenter  : parent.verticalCenter
        }
        height          : _treatmentPressures.height
        header {
            title       : qsTr("Rinseback 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: _endButton
                    objectName  : "_endButton"
                    width       : Variables.defaultButtonWidth
                    height      : Variables.defaultButtonHeight
                    text {
                        text        : qsTr("End Rinseback")
                        font.weight : Font.Medium
                    }
                    isDefault   : true
                    enabled     : true

                    onClicked   : { _root.endClicked() }
                }

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

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

    TreatmentPressures { id: _treatmentPressures
        objectName      : "_treatmentPressures"
        anchors {
            right           : parent.right
            rightMargin     : Variables.defaultMargin * 2
            verticalCenter  : parent.verticalCenter
        }
        width           : 750
        height          : 420
        header.showEdit : false
    }
}
