/*!
 *
 * 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 TreatmentHeparin.qml
 * \author  (last)      Behrouz NematiPour
 * \date    (last)      17-Nov-2020
 * \author  (original)  Behrouz NematiPour
 * \date    (original)  17-Nov-2020
 *
 */

// Qt
import QtQuick 2.12

// Project
import VTreatmentHeparin 0.1;

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

/*!
 * \brief   Treatment Screen Heparin Management section
 */
TreatmentFluid { id: _root
    readonly property bool isOff            : vHDTreatmentStates.hpOff
    readonly property bool isStopped        : vHDTreatmentStates.hpStopped
    readonly property bool isPaused         : vHDTreatmentStates.hpPaused
    readonly property bool isBolus          : vHDTreatmentStates.hpInitial_bolus
    readonly property bool isDispensing     : vHDTreatmentStates.hpDispensing
    readonly property bool isCompleted      : vHDTreatmentStates.hpCompleted
    readonly property bool isEmpty          : vHDTreatmentStates.hpEmpty

    readonly property bool isTxRunning      : vHDTreatmentStates.txDialysis

    QtObject { id: _private
        readonly property string textHeparin        : qsTr("HEPARIN DELIVERY")
        readonly property string textPause          : qsTr("PAUSE DELIVERY")
        readonly property string textResume         : qsTr("RESUME DELIVERY")
        readonly property string textVolumeTarget   : "(" + valueTarget + unit + ")"
        readonly property string mesgBolus          : qsTr("Heparin Bolus Active")
        readonly property string mesgCompleted      : qsTr("Maximum Cumulative Heparin Volume Delivered")
        readonly property string mesgEmpty          : qsTr("Heparin Syringe Empty")
        readonly property string mesgOff            : qsTr("Heparin Delivery Off")
        readonly property string mesgStopped        : qsTr("Heparin Delivery Stopped")
        readonly property string mesgRejectReason   : vTreatmentAdjustmentHeparin.adjustment_ReasonText
    }

    title   : qsTr("HEPARIN")
    cumulativeVisible   : false
    targetVisible       : false
    progressBarVisible  : false

    hasArrow        : false
    isTouchable     : false
    buttonEnabled   :  ! (isOff || isStopped || isBolus || isEmpty
                                || isCompleted                          // decided to not to enable user to resume the heparin while completed (1/Apr/2021 - I,Sean,Nick)
                         )      && ! isSBInProgress && isTxRunning
    buttonText      : ! isTxRunning   ? _private.textHeparin  :
                        isDispensing  ? _private.textPause    :
                        isPaused      ? _private.textResume   :
                        isCompleted   ? _private.textHeparin  :             // decided to not to enable user to resume the heparin while completed (1/Apr/2021 - I,Sean,Nick)
                     // isCompleted   ? _private.textResume   :
                                        _private.textHeparin
    unit            : Variables.unitTextSaline

    valueDelivered: vTreatmentHeparin.cumulative.toFixed(1) // this is the cumulative volume of the Heparin bolus and despensing.

    VTreatmentHeparin  { id: vTreatmentHeparin }

    onClicked: {
        // if ( isCompleted  ) vTreatmentAdjustmentHeparin.doResume()   // decided to not to enable user to resume the heparin while completed (1/Apr/2021 - I,Sean,Nick)
        if ( isPaused     ) vTreatmentAdjustmentHeparin.doResume()
        if ( isDispensing ) vTreatmentAdjustmentHeparin.doPause ()
    }

    notification {
        visible : true
        text    : isBolus       ? _private.mesgBolus        :
                  isOff         ? _private.mesgOff          :
                  isStopped     ? _private.mesgStopped      :
                  isCompleted   ? _private.mesgCompleted    :
                  isEmpty       ? _private.mesgEmpty        :
                                  _private.mesgRejectReason
    }
}
