
// Qt
import QtQuick 2.15
import QtQuick.Controls 2.15

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

WaterSampleBase { id: _root
    anchors.fill: parent

    readonly property bool isPrimary    : vWaterSample.Valve === WaterSamplePage.PRIMARY

    enum Valve {
        PRIMARY     ,
        SECONDARY
    }

    contentItem : Item { id: _content
        Text { id: _title
            anchors {
                left        : parent.left
                leftMargin  : Variables.defaultMargin * 3 // with current resolution this makes the screen look nice
                top         : parent.top
                topMargin   : Variables.defaultMargin // with current resolution this makes the screen look nice
            }
            text            : qsTr("Test %1 Carbon Filter").arg(_root.isPrimary ? qsTr("Primary") : qsTr("Secondary") )
            height          : Variables.contentHeight
            color           : Colors.offWhite
            font.pixelSize  : Fonts.fontPixelTextRectLabel
            font.weight     : Font.Medium
        }

        NotificationBarSmall { id: _infoNotificationBar
            anchors {
                bottom      : undefined
                right       : undefined
                left        : _title.left
                top         : _title.bottom
                topMargin   : Variables.defaultMargin
            }
            width           : parent.width / 3
            height          : Variables.contentHeight
            color           : "transparent"
            imageSource     : "qrc:/images/iHelp"
            imageVisible    : true
            text            : qsTr("Test the carbon filters per your clinic's instructions")
            textfontWeight  : Font.Medium
            textColor       : Colors.statusTextPaused
            imageDiameter   : 25
            imageTopMargin  : 3
        }

        Text { id: _message
            anchors {
                top         : _infoNotificationBar.bottom
                topMargin   : Variables.defaultMargin * 3
                left        : _title.left
            }

            text            :  qsTr("Test the %1 carbon filter and enter the result below").arg( _root.isPrimary ? qsTr("primary") : qsTr("secondary") )
            font.weight     : Font.Medium
            color           : Colors.offWhite
            font.pixelSize  : Fonts.fontPixelInstructionStep
        }

        LabelUnitValueAdjuster { id: _chlorineLevel
            anchors {
                top         : _message.bottom
                topMargin   : Variables.defaultMargin * 4
                left        : _title.left
            }

            text            : qsTr("Chlorine Level")
            unitText        : Variables.unitTextChlorine
            minimum         : vTreatmentRanges.chlorineWaterSampleMin
            maximum         : vTreatmentRanges.chlorineWaterSampleMax
            step            : vTreatmentRanges.chlorineWaterSampleRes
            defaultValue    : vTreatmentRanges.chlorineWaterSampleDef
            value           : vTreatmentRanges.chlorineWaterSampleDef
            decimal         : Variables.chlorinePrecision
            isActive        : true

            onDidChange     : {
                value = vValue
            }
        }

        Text { id: _lastRecorded
            anchors {
                top         : _chlorineLevel.bottom
                topMargin   : Variables.defaultMargin * 4
                left        : _title.left
            }
            height              : 30
            width               : _content.width
            font.pixelSize      : Fonts.fontPixelNotification
            font.weight         : Font.Normal
            verticalAlignment   : Text.AlignBottom
            color               : Colors.offWhite
            text                : ("<b>%1</b> %2")  .arg(qsTr("Last Tested:"))
                                                    .arg(vPreTreatmentAdjustmentWaterSample.resultTime)
            visible             : _lastValue.visible
        }

        Text { id: _lastValue
            anchors {
                top         : _lastRecorded.bottom
                topMargin   : Variables.defaultMargin
                left        : _title.left
            }

            height              : 30
            width               : _content.width
            font.pixelSize      : Fonts.fontPixelNotification
            font.weight         : Font.Normal
            verticalAlignment   : Text.AlignBottom
            color               : Colors.offWhite
            text                : ("<b>%1</b> %2 %3")    .arg(qsTr("Last Result:"))
                                                        .arg(vPreTreatmentAdjustmentWaterSample.resultValue.toFixed(Variables.chlorinePrecision))
                                                        .arg(Variables.unitTextChlorine)
            visible             : vPreTreatmentAdjustmentWaterSample.resultValue
        }


        Image { id: _image
            anchors.right   : parent.right
            anchors.top     : parent.top
            source          : _root.isPrimary ? "qrc:/images/iCarbonFilter1" :
                                                "qrc:/images/iCarbonFilter2"
        }

        ConfirmButton { id : _confirmButton
            objectName      : "_confirmButton"
            anchors {
                top             : undefined
                right           : undefined
                bottom          : parent.bottom
                bottomMargin    : notification.height + Variables.defaultMargin
                horizontalCenter: parent.horizontalCenter
            }
            height      : Variables.defaultButtonHeight
            width       : Variables.defaultButtonWidth

            onClicked   : vPreTreatmentAdjustmentWaterSample.doResult( _chlorineLevel.value )
        }
    }

    // this notification shall not be confused with the _notification in the parent ModalDailog
    // this meant to be used specifically as current state notification like paused/off in UF
    // it is also available in TreatmentAdjustmentFlow and TreatmentAdjustmentDuration but not used.
    NotificationBarSmall { id: _information
        anchors.bottom      : parent.bottom
        imageSource         : ""
        text                : ""
    }

    Connections { target: vPreTreatmentAdjustmentWaterSample
        function onAdjustmentTriggered          ( vValue ) {
            if ( vPreTreatmentAdjustmentWaterSample.adjustment_Accepted ) {
                _information.text = ""
            } else {
                _information.text = vPreTreatmentAdjustmentWaterSample.text()
            }
        }
    }
}
