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

// Qt
import QtQuick 2.12

// Project

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

/*!
 * \brief   Treatment Screen Treatment Time Remaining section
 */
Rectangle { id: _root
    objectName: "TreatmentTime"
    property int minimum        : 0
    property int maximum        : vTreatmentTime.time_Total
    property int progressValue  : vTreatmentTime.time_Elapsed
    property int timeTextValue  : vTreatmentTime.time_Remaining

    property bool isRunning     : vHDTreatmentStates.txDialysis &&
                               !( vHDTreatmentStates.sbWaitPump || vHDTreatmentStates.sbRunning )

    signal clicked()

    anchors.centerIn: parent
    width : _circle.width
    height: _circle.height
    color: "transparent"

    ProgressCircle { id: _circle
        minimum: _root.minimum
        maximum: _root.maximum

        anchors.centerIn  : parent
        value: _root.progressValue
    }

    TimeText { id: _timeText
        anchors.centerIn  : parent
        seconds : _root.timeTextValue
        secondsVisible: _root.isRunning
    }

    Rectangle { id: _timeTitleRect
        color: "Transparent"
        anchors.horizontalCenter: _timeText.horizontalCenter
        anchors.bottom: _timeText.top

        width   : _timeTitle.width + _arrowImage.width + _arrowImage.anchors.leftMargin
        height  : _timeTitle.height

        Text { id: _timeTitle
            text: qsTr("Time Remaining")

            font.pixelSize: 26
            color: "white"

            anchors.left: parent.left
            Image { id: _arrowImage
                visible: _root.isRunning
                anchors.left  : parent.right
                anchors.bottom: parent.baseline
                anchors.leftMargin: 10
                width : Variables.arrowWidth
                height: Variables.arrowHeight
                source: "qrc:/images/iArrowRight"
            }
        }
    }

    NotificationBarSmall { id: _notification
        visible : ! _root.isRunning
        height  : 25
        imageAutoSize: false
        imageAnimated: true
        color: "transparent"
        anchors {
            leftMargin  : 80
            bottomMargin: 80
        }

        imageSource : "qrc:/images/iPauseGray"
        text        : qsTr("Treatment Paused")
        textColor   : "gray"
        textfontSize: 16
        rowAnchors.centerIn: null
    }

    MouseArea { id: _mouseArea
        anchors.fill: parent
        onClicked: {
            if (_root.isRunning) {
                _root.clicked()
            }
        }
    }
}

