/*!
 *
 * 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    TreatmentHome.qml
 * \author  (last)      Behrouz NematiPour
 * \date    (last)      10-Jan-2024
 * \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:/dialogs"
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

    signal backClicked()

    signal sectionFlowClicked()
    signal sectionVitalsClicked()
    signal sectionPressuresClicked()
    signal sectionTimeClicked()
    signal sectionUltrafiltrationClicked()

    readonly property int cellWidth : (_root.width / 7) - 10 // = screen width / # columns
    readonly property int cellHeight: (Variables.screenContentHeight / 2) - Variables.notificationHeight  // = screen height / # rows - headerbar

    Column { id: _column
        objectName:    "column"

        spacing: Variables.defaultMargin

        anchors {
            fill: parent
            margins: Variables.defaultMargin
            topMargin : 30
        }

        Row { id: _topRow
            objectName:    "topRow"

            spacing: Variables.defaultMargin
            height: cellHeight

            TreatmentTime { id: _treatmentTime
                objectName:    "treatmentTime"
                width:  (cellWidth * 2) - (Variables.defaultMargin * 2)
                height: cellHeight
                onClicked: sectionTimeClicked()
            }

            TreatmentSaline { id: _treatmentSaline
                objectName:    "treatmentSaline"

                width:  cellWidth + Variables.defaultMargin
                height: cellHeight
            }

            TreatmentVitals { id: _treatmentVitals
                objectName:    "treatmentVitals"

                width:  cellWidth + Variables.defaultMargin
                height: cellHeight
                onEditClicked: sectionVitalsClicked()
            }

            TreatmentPressures          { id: _treatmentPressures
                objectName:    "treatmentPressures"

                width:  (cellWidth * 3) - (Variables.defaultMargin * 2) // without auto layouts needs to fine tune
                height: cellHeight
                onEditClicked: sectionPressuresClicked()
            }
        }

        Row { id: _bottomRow
            objectName:    "bottomRow"

            spacing: Variables.defaultMargin
            height: cellHeight

            TreatmentUltrafiltration    { id: _treatmentUltrafiltration;
                objectName:    "treatmentUltrafiltration"

                width:  cellWidth * 3
                height: cellHeight
                onEditClicked   : sectionUltrafiltrationClicked()
            }

            TreatmentFlows { id: _treatmentFlows
                objectName:    "treatmentFlows"

                width:  cellWidth * 4
                height: cellHeight

                onEditClicked   : sectionFlowClicked()
                onLockClicked   :  {
                    _lockDialog.isLocked = editEnabled
                    _lockDialog.showDialog (
                                editEnabled ? qsTr("Treatment Parameters Unlocked") :
                                              qsTr("Treatment Parameters Locked"),
                                750
                                )
                }
            }
        }
    }

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