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

// Qt
import QtQuick 2.12

// Project

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

/*!
 * \brief   Treatment Screen Treatment Time Remaining section
 */
Rectangle { id: _root
    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     : vTDTreatmentStates.txDialysis &&
                               !( vTDTreatmentStates.sbWaitPump || vTDTreatmentStates.sbRunning )

    property bool isComplete    : vTreatmentTime.time_Remaining <= 0 && vTreatmentTime.time_Elapsed > 0

    property string notificationText:   ! isRunning ? qsTr("Treatment Paused")  :
                                        isComplete  ? qsTr("Treatment Complete"):
                                                      ""

    color   : "transparent"
    width   : _circle.width
    height  : _circle.height

    signal clicked()

    ProgressCircle { id: _circle
        objectName  : "circle"
        minimum             : _root.minimum
        maximum             : _root.maximum

        anchors.fill        : parent
        value               : _root.progressValue
        thickness           : 35
        circleShadowColor   : Colors.mainTreatmentLighterBlue
        circleFillColor     : Colors.mainTreatmentDarkerBlue
        runAnimation        : ! _root.isRunning
    }

    TimeText { id: _timeText
        objectName: "timeText"

        anchors {
            centerIn                : parent
            horizontalCenterOffset  : -Variables.defaultMargin
        }
        seconds                     : _root.timeTextValue
        textWeight              : Font.Normal
        secsPixelSize           : 35
        secondsLeftMargin       : 10
    }

    Item { id: _timeTitleRect
        objectName: "timeTextRect"

        anchors {
            horizontalCenter: _root.horizontalCenter
            bottom          : _timeText.top
            bottomMargin    : Variables.defaultMargin * 2
        }

        width               : _root.width

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

            anchors {
                horizontalCenter: parent.horizontalCenter
            }

            font.pixelSize  : 26
            font.weight     : Font.Normal
            color           : Colors.textMain
        }

        IconButton { id  : _editTimeIcon
            objectName: "editTimeIcon"
            anchors {
                bottom: _timeTitle.top
                bottomMargin:  Variables.defaultMargin
                horizontalCenter: parent.horizontalCenter
            }
            iconSize            : 30
            iconImageSource     : "qrc:/images/iEdit"
            onClicked           : _root.clicked()
        }
    }

    NotificationBarSmall { id: _notification
        objectName: "notification"

        anchors {
            left        : _timeTitleRect.left
            leftMargin  : Variables.defaultMargin
            top         : _timeTitleRect.bottom
            topMargin   : Variables.defaultMargin * 2
        }

        visible                 : ! _root.isRunning || _root.isComplete
        height                  : 25
        color                   : "transparent"
        imageDiameter           : 25
        imageTopMargin          : 4
        imageSource             : "qrc:/images/iPauseOrange"
        imageVisible            : ! _root.isComplete
        text                    : _root.notificationText
        textColor               : _root.isComplete ? Colors.mainTreatmentGreen : Colors.mainTreatmentOrange
        textfontSize            : 26
        textfontWeight          : Font.Medium
    }
}

