/*!
 *
 * Copyright (c) 2019-2020 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    PostTreatmentRinseback.qml
 * \author  (last)      Behrouz NematiPour
 * \date    (last)      29-Jan-2021
 * \author  (original)  Behrouz NematiPour
 * \date    (original)  29-Jan-2021
 *
 */

// Qt
import QtQuick 2.12

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

/*!
 * \brief   the post treatment rinseback screen
 */
ScreenItem { id: _root
    objectName: "_PostTreatmentRinseback"

    property alias  reasonText  : _notification.text

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

    signal accelerateClicked  ()
    signal deccelerateClicked ()

    Text { id: _title
        anchors {
            top: parent.top
            topMargin: 65
            horizontalCenter: parent.horizontalCenter
        }
        color: "white"
        text: qsTr("Rinseback")
        font.pixelSize: Fonts.fontPixelTitle
    }

    TimeText { id: timeout
        visible         : false // has been removed for now // vTreatmentRinseback.timeoutTotal
        anchors {
            horizontalCenter: parent.horizontalCenter
            top             : _title.bottom
            topMargin       : 15
        }
        textPixelSize   : 30
        textWeight      : Font.Normal
        // the TimeText component works with hour and minute mainly
        // so changing the seconds to minuts was easier than changing the component
        secondsVisible  : false
        seconds         : vTreatmentRinseback.timeoutCountDown * 60
    }

    ImageText { id: _imageEnd
        visible: ! vHDTreatmentStates.rbAdditional
        anchors {
            right       : _root.right
            top         : _root.top
            rightMargin : 45
            topMargin   : 45
        }
        diameter        : Variables.rinsebackIconDiameterDefault
        source          : "qrc:/images/iRedCrossWCircle"
        text            : qsTr("End")
        fontSize        : Fonts.fontPixelRinsebackAdjustmentButton
        onClicked       : endClicked()
    }

    ProgressCircle { id: _circle
        diameter: 335
        anchors {
            horizontalCenter: parent.horizontalCenter
            top             : parent.top
            topMargin       : vHDTreatmentStates.rbAdditional ?
                                  _root.height/2 - height/2   :  // move the progress circle in the center of the screen
                                  170
        }

        minimum : 0
        maximum : vTreatmentRinseback.target
        value   : vTreatmentRinseback.current

        Text { id: _textVolume
            anchors.centerIn: parent
            color: "white"
            text: vTreatmentRinseback.current.toFixed(0) + " " + qsTr(Variables.unitTextFluid)
            font.pixelSize: 76
            font.weight: Font.ExtraLight

        }

        Text { id: _labelRate
            anchors {
                top: parent.bottom
                topMargin: 20
                horizontalCenter: parent.horizontalCenter
            }
            color: "white"
            text: vTreatmentRinseback.rate.toFixed(0) + " " + qsTr(Variables.unitTextFlowRate)
            font.pixelSize: 23
        }
    }

    Row { id: _buttonRow
        spacing: 175
        anchors {
            horizontalCenter: _root.horizontalCenter
            bottom          : _root.bottom
            bottomMargin    : Variables.notificationHeight + 55 // + the texts height
        }

        ImageText { id: _imageDecelerate
            visible         : vHDTreatmentStates.rbRun || vHDTreatmentStates.rbPaused
            enabled         : vHDTreatmentStates.rbRun
            anchors.bottom  : _buttonRow.bottom
            diameter        : Variables.rinsebackIconDiameterDefault
            source          : "qrc:/images/iDecelerate"
            text            : qsTr("Decelerate")
            fontSize        : Fonts.fontPixelRinsebackAdjustmentButton
            onClicked       : deccelerateClicked()
        }

        ImageText { id: _imageResume
            visible         : vHDTreatmentStates.rbPaused
            anchors.bottom  : _buttonRow.bottom
            diameter        : Variables.rinsebackIconDiameterResumePause
            source          : "qrc:/images/iResume"
            text            : qsTr("Resume")
            fontSize        : Fonts.fontPixelRinsebackAdjustmentButton
            onClicked       : resumeClicked()
        }

        ImageText { id: _imagePause
            visible         : vHDTreatmentStates.rbRun // not sure if it's possible || vHDTreatmentStates.rbAdditional
            anchors.bottom  : _buttonRow.bottom
            diameter        : Variables.rinsebackIconDiameterResumePause
            source          : "qrc:/images/iPauseLightBlue"
            text            : qsTr("Pause")
            fontSize        : Fonts.fontPixelRinsebackAdjustmentButton
            onClicked       : pauseClicked()
        }

        ImageText { id: _imageAccelerate
            visible         : vHDTreatmentStates.rbRun || vHDTreatmentStates.rbPaused
            enabled         : vHDTreatmentStates.rbRun
            anchors.bottom  : _buttonRow.bottom
            diameter        : Variables.rinsebackIconDiameterDefault
            source          : "qrc:/images/iAccelerate"
            text            : qsTr("Accelerate")
            fontSize        : Fonts.fontPixelRinsebackAdjustmentButton
            onClicked       : accelerateClicked()
        }
    }

    NotificationBar { id: _notification
        iconVisible: false
    }

    onVisibleChanged: {
        _notification.text = ""
        if (visible) {
            _mainMenu     .hidden = true
            _treatmentMenu.hidden = true
        }
    }
}
