/*!
 *
 * 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 TreatmentSaline.qml
 * \author (last) Behrouz NematiPour
 * \date (last) 16-Oct-2020
 * \author (original) Behrouz NematiPour
 * \date (original) 10-Aug-2020
 *
 */

// Qt
import QtQuick 2.12

// Project
import VTreatmentSaline 0.1;

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

/*!
 * \brief   Treatment Screen Saline Management section
 */
TreatmentFluid { id: _root
    readonly property bool isStarted            : vHDTreatmentStates.sbRunning
    readonly property bool isIdle               : vHDTreatmentStates.sbIdle
    // other that max saline bolus delivered,
    // if saline started but still is waiting for pump the button is disabled so user won't tap multiple times.
    readonly property bool isDisabled           : vHDTreatmentStates.sbMaxReached
    readonly property bool isWaitPump           : vHDTreatmentStates.sbWaitPump

    QtObject { id: _private
        readonly property string textStart          : qsTr("START BOLUS")
        readonly property string textStop           : qsTr("STOP BOLUS" )
        readonly property string textVolumeTarget   : "(" + valueTarget + unit + ")"
        readonly property string mesgDisabled       : qsTr("Maximum cumulative saline bolus volume delivered")
        readonly property string mesgWaitForPump    : "" // qsTr("Saline Bolus is starting") // Not sure if we shouls show any message at this point
        readonly property string mesgRejectReason   : vTreatmentAdjustmentSaline.adjustment_ReasonText
    }

    hasArrow        : false
    isTouchable     : false
    buttonEnabled   :  ! ( _root.isDisabled || _root.isWaitPump )
    buttonText      :    ( _root.isDisabled || _root.isWaitPump ) ? _private.textStart :
                           _root.isStarted                        ? _private.textStop  :
                                                                    _private.textStart
    title       : qsTr("SALINE BOLUS")
    unit        : Variables.unitTextSaline

    valueTarget    : vTreatmentSaline.target || vTreatmentAdjustmentSaline.target
    valueCumulative: vTreatmentSaline.cumulative .toFixed(0)
    valueDelivered : vTreatmentSaline.delivered  .toFixed(0)

    VTreatmentSaline  { id: vTreatmentSaline }

    onClicked: {
        if ( isIdle    ) vTreatmentAdjustmentSaline.doStart() // IDLE
        if ( isStarted ) vTreatmentAdjustmentSaline.doStop () // IN_PROGRESS
    }

    notification {
        visible : true
        text    : isDisabled ? _private.mesgDisabled    :
                  isWaitPump ? _private.mesgWaitForPump :
                  _private.mesgRejectReason
    }
}
