/*!
 *
 * Copyright (c) 2021-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    PreTreatmentWaterSampleStack.qml
 * \author  (last)      Vy
 * \date    (last)      17-May-2023
 * \author  (original)  Behrouz NematiPour
 * \date    (original)  18-Mar-2021
 *
 */

// Qt
import QtQuick 2.12

// Project
//  Qml imports
import "qrc:/globals"
import "qrc:/components"
import "qrc:/pages/pretreatment"

/*!
 * \brief   the pre treatment water sample stack screen
 */
PreTreatmentBase { id: _root
    objectName: "_PreTreatmentSampleStack"

    title.text          : qsTr("Test the water sample per your clinic's instructions and select the result.")
    title.font.pixelSize: Fonts.fontPixelSection
    titleTopMargin      : Variables.defaultMargin * 8 // with current resolution this makes the screen look nice

    readonly property bool confirmEnabled   : _failContainer.selected || _passContainer.selected
    readonly property bool result           : _passContainer.selected

    onVisibleChanged: if ( visible ) { reset() }

    function reset() {
        _failContainer.selected = false
        _passContainer.selected = false
    }

    component WaterSampleContainer: Rectangle { id: _waterSampleContainer
        property bool selected      : false
        property alias imageSource  : _resultImage.source
        property alias buttonText   : _button.textString
        property alias description  : _description.text

        signal clicked()

        color           : Colors.waterSampleContainer
        radius          : Variables.touchRectRadius
        width           : 400
        height          : 450 // with current resolution this makes the screen look nice

        border {
            width   : 2
            color   : _waterSampleContainer.selected ? Colors.backgroundButtonSelect : Colors.waterSampleContainer
        }

        Image { id: _resultImage
            anchors {
                top             : _waterSampleContainer.top
                topMargin       : Variables.defaultMargin * 3 // with current resolution this makes the screen look nice
                horizontalCenter: parent.horizontalCenter
            }
        }

        Text { id: _description
            anchors.centerIn: parent
            color           : Colors.textMain
            font.pixelSize  : Fonts.fontPixelInstructionStep
            font.weight     : Font.Medium
        }

        TouchRect { id : _button
            width   : Variables.confirmButtonWidth
            height  : Variables.contentHeight
            text    {
                font.pixelSize  : Fonts.fontPixelConfirm
                font.weight     : Font.Medium
            }

            isDefault: true

            anchors {
                horizontalCenter: _waterSampleContainer.horizontalCenter
                bottom          : _waterSampleContainer.bottom
                bottomMargin    : Variables.defaultMargin * 2 // with current resolution this makes the screen look nice
            }

            onClicked: _waterSampleContainer.clicked()
        }
    }

    Row { id: _row
        anchors {
            top             : _root.title.bottom
            topMargin       : Variables.defaultMargin * 4 // with current resolution this makes the screen look nice
            horizontalCenter: parent.horizontalCenter
        }

        spacing             : Variables.defaultMargin * 2 // with current resolution this makes the screen look nice

        WaterSampleContainer { id: _failContainer
            imageSource : "qrc:/images/iWaterSampleFail"
            buttonText  : qsTr("Fail")
            description : ("%1 > %2 %3").arg(qsTr("Chlorine level"))
                                        .arg(Variables.chlorineLevel)
                                        .arg(Variables.unitTextChlorine)
            onClicked   :{
                _failContainer.selected = true
                _passContainer.selected = false
            }
        }

        WaterSampleContainer { id: _passContainer
            imageSource : "qrc:/images/iWaterSamplePass"
            buttonText  : qsTr("Pass")
            description : ("%1 ≤ %2 %3").arg(qsTr("Chlorine level"))
                                        .arg(Variables.chlorineLevel)
                                        .arg(Variables.unitTextChlorine)
            onClicked   :{
                _failContainer.selected = false
                _passContainer.selected = true
            }
        }
    }
}
