/*!
 *
 * 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    ManagerHome.qml
 * \date    2019/10/21
 * \author  Behrouz NematiPour
 *
 */

// Qt
import QtQuick 2.12
import QtQuick.Controls 2.12

// Project
import Gui.Actions 0.1;

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

/*!
 * \brief   ManagerHome is the screen
 * which is the default screen in the "Manager" stack
 */
ScreenItem { id: _root
    property int          bloodFlow_MeasuredFlow_Precision: 0
    property int dialysateInletFlow_MeasuredFlow_Precision: 0

    property int leftColumnX    :  40
    property int rightColumnX   : 875

    property int row1Y          : 100
    property int row2Y          : 320
    property int row3Y          : 570

    property int lineLength     : 450
    property int leftLinesX     :   0
    property int rightLinesX    : Variables.applicationWidth - lineLength
    property int row1LineY      : 275
    property int row2LineY      : 525

    signal backPressed()

    // ---------- COLUMN LEFT
    TreatmentFlows              { id: _flowsTouchArea }
    Line                        { x: 0; y: row1LineY; length: lineLength }
    TreatmentVitals             { id: _vitalsTouchArea }
    Line                        { x: 0; y: row2LineY; length: lineLength }
    TreatmentPressure           { id: _pressureTouchArea }

    // ---------- COLUMN RIGHT
    TreatmentUltrafiltration    { id: _ultrafiltrationTouchArea; maximum: 1000 } // TEST : this is a test has to be read form the prescreprion values
    Line                        { x: rightLinesX; y: row1LineY; length: lineLength }
    TreatmentFluid              { id: _fluidManagementTouchArea }
    Line                        { x: rightLinesX; y: row2LineY; length: lineLength; }
    TreatmentInfusion           { id: _solutionInfusionTouchArea }

    // ---------- Center
    TreatmentTime               { id: _treatmentTime }

    onVisibleChanged: {
        if (visible) {
            _mainMenu.hidden = true
            _treatmentMenu.hidden = false
        }
    }

    Connections { target: _GuiView
        onDidActionReceive: {
            if ( ! visible ) return;
            switch(vAction) {
            case GuiActions.BloodFlow:
                _flowsTouchArea.textRectBloodFlow.label = vData[GuiActions.BloodFlow_MeasuredFlow].toFixed(bloodFlow_MeasuredFlow_Precision);
                break
            case GuiActions.DialysateInletFlow:
                _flowsTouchArea.textRectDialysateInletFlow.label = vData[GuiActions.DialysateInletFlow_MeasuredFlow].toFixed(dialysateInletFlow_MeasuredFlow_Precision);
                break
            case GuiActions.DialysateOutletFlow:
                _ultrafiltrationTouchArea.value = vData[GuiActions.DialysateOutletFlow_MeasUFVol].toFixed(2);
                break;
            case GuiActions.TreatmentTime:
                _treatmentTime.maximum          = vData[GuiActions.TreatmentTime_Total      ];
                _treatmentTime.progressValue    = vData[GuiActions.TreatmentTime_Elapsed    ];
                _treatmentTime.timeTextValue    = vData[GuiActions.TreatmentTime_Remaining  ];
                break;
            }
        }
    }
    Connections { target: _treatmentMenu
        onItemPressed: {
            // TEST : this is a test code since the back button has been removed
            // and also we don't have Treatment complete yet.
            if (vIndex == 0) {
                _treatmentMenu.hidden = true
                backPressed()
            }
        }

    }
}
