/*!
 *
 * 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
import QtQuick.Controls 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
            }
        }
    }

    Column { id: _AlarmStatusColumn
        width: 270
        spacing: 5
        topPadding: 100
        leftPadding: 700
        Text {
            id: _AlarmStatus_Title
            text: qsTr("  Alarm Status  ")
            width: _AlarmStatusColumn.width
            horizontalAlignment: Text.AlignLeft
            color: Colors.textMain
            font.pixelSize: Fonts.fontPixelTitle
            font.underline: true
        }
        Repeater {
            model: [
                _GuiView.alarmPriorityName(vAlarmStatus.alarm_Priority)                             ,
                _GuiView.alarmIDName      (vAlarmStatus.alarm_AlarmID)                              ,
                "Escalates In : "        + vAlarmStatus.alarm_EscalateIn                            ,
                "MuteTimeout  : "        + vAlarmStatus.alarm_MuteTimeout                           ,
                (vAlarmStatus.alarm_Flag_systemFault        ? "1" : "0" ) + " : systemFault      "  ,
                (vAlarmStatus.alarm_Flag_stop               ? "1" : "0" ) + " : stop             "  ,
                (vAlarmStatus.alarm_Flag_noClear            ? "1" : "0" ) + " : noClear          "  ,
                (vAlarmStatus.alarm_Flag_noResume           ? "1" : "0" ) + " : noResume         "  ,
                (vAlarmStatus.alarm_Flag_noRinseback        ? "1" : "0" ) + " : noRinseback      "  ,
                (vAlarmStatus.alarm_Flag_noEndTreatment     ? "1" : "0" ) + " : noEndTreatment   "  ,
                (vAlarmStatus.alarm_Flag_noNewTreatment     ? "1" : "0" ) + " : noNewTreatment   "  ,
                (vAlarmStatus.alarm_Flag_bypassDialyzer     ? "1" : "0" ) + " : bypassDialyzer   "  ,
                (vAlarmStatus.alarm_Flag_alarmsToEscalate   ? "1" : "0" ) + " : alarmsToEscalate "  ,
                (vAlarmStatus.alarm_Flag_alarmsSilenced     ? "1" : "0" ) + " : alarmsSilenced   "
            ]
            Text {
                id: _AlarmStatus_Priority
                text: modelData
                width: _AlarmStatusColumn.width
                horizontalAlignment: Text.AlignLeft
                color: Colors.textMain
                font.pixelSize: Fonts.fontPixelButton
            }
        }
    }
}
