/*!
 *
 * 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    TreatmentFlows.qml
 * \author  (last)      Behrouz NematiPour
 * \date    (last)      14-Mar-2023
 * \author  (original)  Behrouz NematiPour
 * \date    (original)  27-Jan-2020
 *
 */

// Qt
import QtQuick 2.12

// Project

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

/*!
 * \brief   Treatment Screen Flows section
 */
TreatmentSection { id: _root
    property bool editEnabled       : true

    header.title    : qsTr("Treatment Parameters")
    header.showLock : true

    contentItem: Row { id   : _row
        objectName          : "row"

        property int cellWidth      : (contentItem.width / 4) - (Variables.defaultMargin) + 5
        property int cellHeight     : contentItem.height - 10

        spacing: Variables.defaultMargin
        topPadding: -Variables.defaultMargin

        TreatmentFlowsComponent { id: _bloodFlow
            objectName      : "bloodFlowComponent"
            title           : qsTr("Blood Flow")
            height          : _row.cellHeight
            width           : _row.cellWidth
            value           : vTreatmentParametersSetPoint.bloodFlow
            precision       : Variables.bloodFlowPrecision
            minimum         : vTreatmentRanges.bloodFlowRateMin
            maximum         : vTreatmentRanges.bloodFlowRateMax
            step            : vTreatmentRanges.bloodFlowRateRes
            unitText        : Variables.unitTextFlowRate
            buttonsEnabled  : editEnabled                       // LEAHI-PRS-376

            onIncrement     : function(newValue) { vTreatmentAdjustmentBloodFlowRate.doAdjustment(newValue) }
            onDecrement     : function(newValue) { vTreatmentAdjustmentBloodFlowRate.doAdjustment(newValue) }
        }

        TreatmentFlowsComponent { id: _dialysateFlow
            objectName      : "dialysateFlowComponent"
            title           : qsTr("Dialysate Flow")
            height          : _row.cellHeight
            width           : _row.cellWidth
            value           : vTreatmentParametersSetPoint.dialysateFlow
            precision       : Variables.dialysateFlowPrecision
            minimum         : vTreatmentRanges.dialysateFlowRateMin
            maximum         : vTreatmentRanges.dialysateFlowRateMax
            step            : vTreatmentRanges.dialysateFlowRateRes
            unitText        : Variables.unitTextFlowRate
            buttonsEnabled  : isTreatmentEnd ? false : editEnabled  // LEAHI-PRS-376
            extraText       :   vTreatmentParametersSetPoint.dialysateFlow === 0    ?   qsTr("OFF")  :
                              ! vDDGenDialysate.isDialGood                          ?   qsTr("Bypass") :
                                ""

            onIncrement     : function(newValue) { vTreatmentAdjustmentDialysateFlowRate.doAdjustment(newValue) }
            onDecrement     : function(newValue) { vTreatmentAdjustmentDialysateFlowRate.doAdjustment(newValue) }
        }

        TreatmentFlowsComponent { id: _dialysateTemp
            objectName      : "dialysateTempComponent"
            title           : qsTr("Dialysate Temp.")
            height          : _row.cellHeight
            width           : _row.cellWidth
            value           : vTreatmentParametersSetPoint.dialysateTemp
            precision       : Variables.dialysateTempPrecision
            minimum         : vTreatmentRanges.dialysateTempMin
            maximum         : vTreatmentRanges.dialysateTempMax
            step            : vTreatmentRanges.dialysateTempRes
            unitText        : Variables.unitTextTemperature
            buttonsEnabled  : isTreatmentEnd ? false : editEnabled  // LEAHI-PRS-376

            onIncrement     : function(newValue) { vTreatmentAdjustmentDialysateTemperature.doAdjustment(newValue) }
            onDecrement     : function(newValue) { vTreatmentAdjustmentDialysateTemperature.doAdjustment(newValue) }
        }

        TreatmentFlowsComponent { id: _dialysateCond
            objectName      : "dialysateCondComponent"
            title           : qsTr("Dialysate Cond.")
            height          : _row.cellHeight
            width           : _row.cellWidth
            value           : Variables.notSetVariable(vDDConductivity.acidBicarbCondutivity2.toFixed(Variables.dialysateCondPrecision)) // D29
            unitText        : Variables.unitTextDialCond
            showButtons     : false
            dropShadowEnabled : false
        }
    }
}
