/*!
 *
 * 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    TreatmentPressures.qml
 * \author  (last)      Behrouz NematiPour
 * \date    (last)      31-May-2023
 * \author  (original)  Behrouz NematiPour
 * \date    (original)  01-Nov-2020
 *
 */

// Qt
import QtQuick 2.12

// Project

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

/*!
 * \brief   Treatment Screen Pressure section
 */
TreatmentSection { id: _root
    property int    arterialMinimum     : vTreatmentRanges.arterialPressureMonitorMin
    property int    arterialMaximum     : vTreatmentRanges.arterialPressureMonitorMax
    property int    venousMinimum       : vTreatmentRanges.venousPressureMonitorMin
    property int    venousMaximum       : vTreatmentRanges.venousPressureMonitorMax
    property int    tmpMinimum          : vTreatmentRanges.transmembranePressureMonitorMin
    property int    tmpMaximum          : vTreatmentRanges.transmembranePressureMonitorMax

    property int    arterialLowerBound  : vTreatmentPressureOcclusion.arterialMin
    property int    arterialUpperBound  : vTreatmentPressureOcclusion.arterialMax
    property int    venousLowerBound    : vTreatmentPressureOcclusion.venousMin
    property int    venousUpperBound    : vTreatmentPressureOcclusion.venousMax
    property int    tmpLowerBound       : vTreatmentPressureOcclusion.tmpMin
    property int    tmpUpperBound       : vTreatmentPressureOcclusion.tmpMax
    property int    arterialPressure    : vTreatmentPressureOcclusion.arterialPressure
    property int    venousPressure      : vTreatmentPressureOcclusion.venousPressure
    property int    tmpPressure         : vTreatmentPressureOcclusion.tmpPressure

    header.title                    : qsTr("Pressures") + " (" + qsTr("mmHg") + ")"
    header.showExpanding            : true

    contentArea.anchors.topMargin   : Variables.defaultMargin

    onExpandingClicked              : vTreatmentAdjustmentPressuresWidening.doAdjustment()

    function checkMinimum (minimum, lowerBound) { return lowerBound < minimum ? lowerBound : minimum }
    function checkMaximum (maximum, upperBound) { return upperBound > maximum ? upperBound : maximum }

    contentItem: Column { id: _column
        property int cellHeight : Variables.contentHeight / 3
        property int cellWidth  : contentItem.width * 0.9

        spacing         : Variables.defaultMargin * 4
        topPadding      : Variables.defaultMargin
        leftPadding     : Variables.defaultMargin / 2
        rightPadding    : Variables.defaultMargin

        TreatmentPressureComponent { id: _arterialRangeBar
            title       : qsTr("Arterial:")
            height      : _column.cellHeight
            width       : _column.cellWidth
            barColor    : Colors.pressuresArterialBar

            minimum     : checkMinimum(_root.arterialMinimum, lowerBound)
            lowerBound  : _root.arterialLowerBound
            upperBound  : _root.arterialUpperBound
            maximum     : checkMaximum(_root.arterialMaximum, upperBound)
            pressure    : _root.arterialPressure
        }

        TreatmentPressureComponent { id: _venousRangeBar
            title       : qsTr("Venous:")
            height      : _column.cellHeight
            width       : _column.cellWidth
            barColor    : Colors.pressuresVenousBar

            minimum     : checkMinimum(_root.venousMinimum, lowerBound)
            lowerBound  : _root.venousLowerBound
            upperBound  : _root.venousUpperBound
            maximum     : checkMaximum(_root.venousMaximum, upperBound)
            pressure    : _root.venousPressure
        }

        TreatmentPressureComponent { id: _tmpRangeBar
            title       : qsTr("TMP:")
            height      : _column.cellHeight
            width       : _column.cellWidth
            barColor    : Colors.pressuresTmpBar

            minimum     : checkMinimum(_root.tmpMinimum, lowerBound)
            lowerBound  : _root.tmpLowerBound
            upperBound  : _root.tmpUpperBound
            maximum     : checkMaximum(_root.tmpMaximum, upperBound)
            pressure    : _root.tmpPressure
        }
    }
}
