/*!
 *
 * 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 ) ||  vTDTreatmentStates.txEnd

    property bool isHDTreatment : vTreatmentCreate.treatmentModality === 0
    property bool isHDFTreatment: vTreatmentCreate.treatmentModality === 1
    property bool isIsoTreatment: vTreatmentCreate.treatmentModality === 2

    property string notificationText:   isComplete      ? qsTr("Treatment Complete")    :
                                        ! isRunning     ? qsTr("Treatment Paused")      :
                                        isHDTreatment   ? qsTr("HD Time")               :
                                        isHDFTreatment  ? qsTr("HDF Time")              :
                                        isIsoTreatment  ? qsTr("Isolated UF Time")      :
                                                          ""

    property color notificationColor:   isComplete          ? Colors.statusComplete     :
                                        ! isRunning         ? Colors.statusTextPaused   :
                                        isHDTreatment   ||
                                        isHDFTreatment  ||
                                        isIsoTreatment      ? Colors.statusTextActive   :
                                                              ""

    property bool editEnabled   : ! isTreatmentEnd      // LEAHI-PRS-376

    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.transparent
        runAnimation        : ! _root.isRunning

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

    TimeText { id: _timeText
        objectName: "timeText"

        anchors {
            centerIn                : parent
            horizontalCenterOffset  : -Variables.defaultMargin
        }
        seconds                     : _root.timeTextValue
        textWeight              : Font.Normal
        secsPixelSize           : 35
        secondsLeftMargin       : 10
        textColor               : _root.isRunning || _root.isComplete ? Colors.offWhite : Colors.mainTreatmentOrange
    }

    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
            }
            enabled             : _root.editEnabled
            iconSize            : 30
            iconImageSource     : enabled ? "qrc:/images/iEdit" : "qrc:/images/iEditDisabled"
            onClicked           : _root.clicked()
        }
    }

    NotificationBarSmall { id: _notification
        objectName: "notification"

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

        height                  : 25
        color                   : "transparent"
        imageDiameter           : 25
        imageTopMargin          : 4
        imageSource             : "qrc:/images/iPauseOrange"
        imageVisible            : ! _root.isRunning && ! _root.isComplete
        text                    : _root.notificationText
        textColor               : _root.notificationColor
        textfontSize            : 26
        textfontWeight          : Font.Medium
    }
}

