
// Qt
import QtQuick 2.15
import QtQuick.Controls 2.15

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

WaterSampleBase { id: _root
    anchors.fill: parent

    property int attempt: 1
    readonly property var instructionsGroup : vSettings.instructions[qsTr("Water Sample")]

    component WaterSampleRadioButton: RadioButton { id: _waterSampleRadioButton
        property alias imageSource  : _resultImage.source

        indicator: Rectangle { id: _indicator
            width       : 35
            height      : 35
            radius      : 35
            border.width: 2
            border.color: Colors.backgroundMainMenu
            anchors.verticalCenter: parent.verticalCenter

            Rectangle {
                anchors.centerIn: parent
                width           : 25
                height          : 25
                radius          : 25
                color           : _waterSampleRadioButton.checked ?  Colors.highlightProgressBar: Colors.backgroundMainMenu
                visible         : _waterSampleRadioButton.checked
            }
        }

        contentItem: Row { id: _row
            spacing     : _waterSampleRadioButton.spacing
            leftPadding : 70
            anchors.verticalCenter: parent.verticalCenter

            Image { id: _resultImage }

            Text { id: _text
                text                : _waterSampleRadioButton.text
                font.pixelSize      : Fonts.fontPixelInstructionStep
                color               : Colors.backgroundMainMenu
                verticalAlignment   : Text.AlignVCenter
                height              : _row.height
                width               : _text.implicitWidth
            }
        }
    }

    contentItem : Rectangle { id: _content
        color           : Colors.offWhite
        radius          : Variables.alarmDialogRadius
        clip            : true

        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 * 2 // with current resolution this makes the screen look nice
            }
            text            : _root.instructionsGroup ? _root.instructionsGroup.title : ""
            height          : Variables.contentHeight
            color           : Colors.backgroundMainMenu
            font.pixelSize  : Fonts.fontPixelInstructionTitle
            font.weight     : Font.Medium
        }

        NotificationBarSmall { id: _infoNotificationBar
            anchors {
                bottom      : undefined
                right       : undefined
                left        : _title.left
                top         : _title.bottom
                topMargin   : Variables.defaultMargin * 2
            }
            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")
            textColor       : "#595959"
            imageDiameter   : 25
            imageTopMargin  : 3
        }

        Item { id: _instructionContainer
            anchors {
                right   : _content.right
                left    : _title.left
                top     : _infoNotificationBar.bottom
                bottom  : _content.bottom
            }

            Item { id: _instruction
                width   : _instructionContainer.width
                height  : Variables.instructionHeight

                Rectangle { id: _attemptRect
                    anchors.left            : parent.left
                    anchors.verticalCenter  : parent.verticalCenter

                    height  : 50
                    width   : height
                    radius  : height
                    color   : Colors.backgroundMainMenu

                    Text { id: _attemptNumberRect
                        anchors.centerIn: parent
                        text            : _root.attempt
                        color           : Colors.white
                        font.pixelSize  : 28
                        font.weight     : Font.Medium
                    }
                }

                Text { id: _message
                    anchors {
                        left            : _attemptRect.right
                        leftMargin      : Variables.defaultMargin * 2 // with current resolution this makes the screen look nice
                        right           : parent.right
                        verticalCenter  : parent.verticalCenter
                    }
                    text            : _root.instructionsGroup ? _root.instructionsGroup.keys[0] : "" //qsTr("Test the primary carbon filter and select the result below")
                    font.weight     : Font.Medium
                    color           : "#18559E"
                    wrapMode        : Text.WordWrap
                    font.pixelSize  : Fonts.fontPixelInstructionStep
                }
            }

            Column {
                anchors {
                    left        : parent.left
                    leftMargin  : Variables.defaultMargin * 6
                    top         : _instruction.bottom
                    topMargin   : Variables.defaultMargin
                }
                spacing: Variables.defaultMargin * 3

                ButtonGroup { id: _radioGroup }

                WaterSampleRadioButton {  id: _failContainer
                    text:  ("%1 > %2 %3")   .arg(qsTr("Chlorine level"))
                                            .arg(Variables.chlorineLevel)
                                            .arg(Variables.unitTextChlorine)
                    ButtonGroup.group   : _radioGroup
                    spacing             : Variables.defaultMargin
                    imageSource         : "qrc:/images/iWaterSampleFail"
                }

                WaterSampleRadioButton { id: _passContainer
                    text: ("%1 ≤ %2 %3").arg(qsTr("Chlorine level"))
                                        .arg(Variables.chlorineLevel)
                                        .arg(Variables.unitTextChlorine)
                    ButtonGroup.group: _radioGroup
                    spacing             : Variables.defaultMargin
                    imageSource         : "qrc:/images/iWaterSamplePass"
                }
            }
        }

        Image { id: _image
            anchors.right   : parent.right
            anchors.top     : parent.top
            anchors.bottom  : parent.bottom
            source          :  _root.instructionsGroup ? _root.instructionsGroup.values[0] : "" //"qrc:/images/iRedCrossWCircle" // TODO get actual image
        }

        ConfirmButton { id : _confirmButton
            objectName      : "_confirmButton"
            anchors {
                top     : undefined
                right   : undefined
                bottom  : parent.bottom
                horizontalCenter: parent.horizontalCenter
            }
            enabled     : _failContainer.checked || _passContainer.checked

            onClicked   : vPreTreatmentAdjustmentWaterSample.doResult( _passContainer.checked )
        }
    }

    // TODO water sample
//    Connections { target: vPreTreatmentAdjustmentWaterSample
//        function onAdjustmentTriggered          ( vValue ) {
//            if ( vPreTreatmentAdjustmentWaterSample.adjustment_Accepted ) {
//                _pretreatmentWaterSample.reasonText = ""
//                page ( _pretreatmentCreate )
//            } else {
//                _pretreatmentWaterSample.reasonText = vPreTreatmentAdjustmentWaterSample.text()
//            }
//        }
//    }

}
