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

// Qt
import QtQuick 2.12

// Project
import Gui.Actions 0.1;

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

/*!
 * \brief   SettingsHome is the screen
 * which is the default screen in the "Settings" stack
 */
ScreenItem { id: _root

    USBButton { id: _usbButton
        anchors {
            top         : parent.top
            right       : _exportButton.left
            topMargin   : (Variables.headerHeight - Variables.logoHeight) / 2
            rightMargin : (Variables.headerHeight - Variables.logoHeight) / 2
        }
    }

    ExportButton { id: _exportButton
        width: 150
        height: 50
        anchors {
            top         : parent.top
            right       : _poweroffButton.left
            topMargin   : (Variables.headerHeight - Variables.logoHeight) / 2
            rightMargin : (Variables.headerHeight - Variables.logoHeight) / 2
        }
    }

    TouchRect { id : _poweroffButton
        width: 150
        height: Variables.logoHeight
        animated: true
        anchors {
            top         : parent.top
            right       : parent.right
            topMargin   : (Variables.headerHeight - Variables.logoHeight) / 2
            rightMargin : (Variables.headerHeight - Variables.logoHeight) / 2
        }
        text.text: qsTr("Shutdown")
        button.onPressed: {
            _GuiView.doActionTransmit(GuiActions.PowerOff, GuiActions.NoData)
        }
    }

    Column { id: _BloodFlowColumn
        width: 150
        spacing: 20
        topPadding: 100
        leftPadding: 10
        Text {
            id: _BloodFlow_Title
            text: qsTr("  Blood  ")
            width: _BloodFlowColumn.width
            horizontalAlignment: Text.AlignHCenter
            color: Colors.textMain
            font.pixelSize: Fonts.fontPixelTitle
            font.underline: true
        }
        Repeater {
            model: [
                      vTreatmentBloodFlow.bloodFlow_FlowSetPoint                 ,
                      vTreatmentBloodFlow.bloodFlow_MeasuredFlow     .toFixed(2) ,
                      vTreatmentBloodFlow.bloodFlow_RotorSpeed       .toFixed(2) ,
                      vTreatmentBloodFlow.bloodFlow_MotorSpeed       .toFixed(2) ,
                      vTreatmentBloodFlow.bloodFlow_MotorCtlSpeed    .toFixed(2) ,
                      vTreatmentBloodFlow.bloodFlow_MotorCtlCurrent  .toFixed(2) ,
                "%" + vTreatmentBloodFlow.bloodFlow_PWMDutyCycle     .toFixed(2)
            ]
            Text {
                text: modelData
                width: _BloodFlowColumn.width
                horizontalAlignment: Text.AlignRight
                color: Colors.textMain
                font.pixelSize: Fonts.fontPixelTitle
            }
        }
    }

    Column { id: _DialysateInletFlowColumn
        width: 150
        spacing: 20
        topPadding: 100
        leftPadding: 180
        Text {
            id: _DialysateInletFlow_Title
            text: qsTr("  Dialysate I ")
            width: _DialysateInletFlowColumn.width
            horizontalAlignment: Text.AlignLeft
            color: Colors.textMain
            font.pixelSize: Fonts.fontPixelTitle
            font.underline: true
        }
        Repeater {
            model: [
                      vTreatmentDialysateFlow.dialysateFlow_FlowSetPoint   .toFixed(2) ,
                      vTreatmentDialysateFlow.dialysateFlow_MeasuredFlow   .toFixed(2) ,
                      vTreatmentDialysateFlow.dialysateFlow_RotorSpeed     .toFixed(2) ,
                      vTreatmentDialysateFlow.dialysateFlow_MotorSpeed     .toFixed(2) ,
                      vTreatmentDialysateFlow.dialysateFlow_MotorCtlSpeed  .toFixed(2) ,
                      vTreatmentDialysateFlow.dialysateFlow_MotorCtlCurrent.toFixed(2) ,
                "%" + vTreatmentDialysateFlow.dialysateFlow_PWMDutyCycle   .toFixed(2)
            ]
            Text {
                text: modelData
                width: _DialysateInletFlowColumn.width
                horizontalAlignment: Text.AlignRight
                color: Colors.textMain
                font.pixelSize: Fonts.fontPixelTitle
            }
        }
    }

    Column { id: _DialysateOutletFlowColumn
        width: 150
        spacing: 20
        topPadding: 100
        leftPadding: 400
        Text {
            id: _DialysateOutletFlow_Title
            text: qsTr("  Dialysate O ")
            width: _DialysateOutletFlowColumn.width
            horizontalAlignment: Text.AlignLeft
            color: Colors.textMain
            font.pixelSize: Fonts.fontPixelTitle
            font.underline: true
        }
        Repeater {
            model: [
                      vTreatmentUltrafiltration.ultrafiltration_RefUFVol       .toFixed(2) ,
                      vTreatmentUltrafiltration.ultrafiltration_MeasUFVol      .toFixed(2) ,
                      vTreatmentUltrafiltration.ultrafiltration_RotorSpeed     .toFixed(2) ,
                      vTreatmentUltrafiltration.ultrafiltration_MotorSpeed     .toFixed(2) ,
                      vTreatmentUltrafiltration.ultrafiltration_MotorCtlSpeed  .toFixed(2) ,
                      vTreatmentUltrafiltration.ultrafiltration_MotorCtlCurrent.toFixed(2) ,
                "%" + vTreatmentUltrafiltration.ultrafiltration_PWMDtCycle     .toFixed(2)
            ]
            Text {
                text: modelData
                width: _DialysateOutletFlowColumn.width
                horizontalAlignment: Text.AlignRight
                color: Colors.textMain
                font.pixelSize: Fonts.fontPixelTitle
            }
        }
    }
}
