/*!
 *
 * Copyright (c) 2019-2020 Diality Inc. - All Rights Reserved.
 * \copyright                                                       \n
 *          THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM,  \n
 *          IN PART OR IN WHOLE,                                    \n
 *          WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. \n
 *
 * \file    TreatmentAdjustmentFlow.qml
 * \date    2020/03/18
 * \author  Behrouz NematiPour
 *
 */

// Qt
import QtQuick 2.12

// Project

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

import VTreatmentAdjustmentsResponse 0.1;

/*!
 * \brief   TreatmentAdjustmentFlow.qml is the screen
 *          To adjust the treatment blood/dialysate flow
 */
TreatmentAdjustmentBase { id: _root

    property alias      bloodFlowRateValue   :     _bloodFlowSlider.value
    property alias      bloodFlowRateMinimum :     _bloodFlowSlider.minimum
    property alias      bloodFlowRateMaximum :     _bloodFlowSlider.maximum
    property alias      bloodFlowRateStep    :     _bloodFlowSlider.step

    property alias  dialysateFlowRateValue   : _dialysateFlowSlider.value
    property alias  dialysateFlowRateMinimum : _dialysateFlowSlider.minimum
    property alias  dialysateFlowRateMaximum : _dialysateFlowSlider.maximum
    property alias  dialysateFlowRateStep    : _dialysateFlowSlider.step

    property string unit        : qsTr("mL/min")
    property int    textWidth   : 200

    onAboutToShow: {
        // TODO : When Testing data on Setting screen is removed
        //        This needs to be moved into the Treatment______.qml
            bloodFlowRateValue =     vTreatmentBloodFlow.    bloodFlow_FlowSetPoint
        dialysateFlowRateValue = vTreatmentDialysateFlow.dialysateFlow_FlowSetPoint
    }

    VTreatmentAdjustmentsResponse { id: vTreatmentAdjustmentsResponse
        onAdjustment_TriggeredChanged: {
            if ( adjustment_Accepted ) {
                accept()
            } else {
                _bloodFlowSlider    .value = vTreatmentAdjustmentsResponse.    bloodFlow_FlowSetPoint;
                _dialysateFlowSlider.value = vTreatmentAdjustmentsResponse.dialysateFlow_FlowSetPoint;
                notificationText           = vTreatmentAdjustmentsResponse.text();
            }
        }
    }
    onVisibleChanged: {
        notificationText = "";
    }

    Column { id : _flowsColumn
        spacing: 100
        anchors.centerIn: parent
        Row { id : _bloodFlowRow
            spacing: 100
            anchors.horizontalCenter: parent.horizontalCenter
            TextRect { id: _bloodFlowTextRect
                anchors.top: parent.top
                anchors.topMargin: 25
                width: textWidth
                title: qsTr("Blood Flow Rate")
                label: _bloodFlowSlider.value
                extra: _root.unit
                labelFont.weight: Font.ExtraLight
            }
            Slider { id : _bloodFlowSlider
                anchors.verticalCenter: parent.verticalCenter
                width   : 600
                height  : 5
                minimum : 100
                maximum : 500
                unit    : _root.unit
                step    : Variables.bloodFlowResolution
                ticks   : true
            }
        }
        Line {
            anchors.horizontalCenter: parent.horizontalCenter
            length  : _root.width - 100
            color   : "#5f809d"
        }
        Row { id : _dialysateInletFlowRow
            spacing: 100
            anchors.horizontalCenter: parent.horizontalCenter
            TextRect { id: _dialysateInletFlowTextRect
                anchors.top: parent.top
                anchors.topMargin: 25
                width: textWidth
                title: qsTr("Dialysate Flow Rate")
                label: _dialysateFlowSlider.value
                extra: _root.unit
                labelFont.weight: Font.ExtraLight
            }
            Slider { id : _dialysateFlowSlider
                anchors.verticalCenter: parent.verticalCenter
                width   : 600
                height  : 5
                minimum : 100
                maximum : 600
                unit    : _root.unit
                step    : Variables.dialysateFlowResolution
                ticks   : true
            }
        }
    }
}
