/*!
 *
 * Copyright (c) 2023-2023 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    SettingsROInput.qml
 * \author  (last)      Behrouz NematiPour
 * \date    (last)      18-Jul-2023
 * \author  (original)  Behrouz NematiPour
 * \date    (original)  18-Jul-2023
 *
 */

// Qt
import QtQuick                  2.12
import QtQuick.Controls         2.12 // Switch


//  Qml imports
import "qrc:/globals"

/*!
 * \brief   SettingsROInput is the screen
 *          which enables the Ro Water Input
 */
SettingsBase    { id: _root
    itemIndex       : SettingsStack.RoInput

    confirmVisible  : false

    Row { id: _settingsRoInputRow
        anchors.centerIn: parent

        Text { id           : _settingsRoInputLabel
            text            : qsTr("Pure Water Mode")
            width           : 300
            height          : _settingsRoInputSwitch.height
            color           : Colors.white
            font.pixelSize: Fonts.fontPixelButton
            verticalAlignment       : Text.AlignVCenter
            horizontalAlignment     : Text.AlignLeft
        }

        Switch { id: _settingsRoInputSwitch
            property bool active: true

            checked : vDuetRoWaterDG.status

            width   : 85
            height  : 85

            indicator: Rectangle {
                implicitWidth   : Variables.sliderCircleDiameter * 1.7
                implicitHeight  : Variables.sliderCircleDiameter - ( Variables.progressbarHandlerBorderWidth * 2 )
                radius          : implicitHeight
                anchors.centerIn: parent
                color           : _settingsRoInputSwitch.checked ? Colors.backgroundButtonSelect  : Colors.createTreatmentInactive
                border.color    : _settingsRoInputSwitch.checked ? Colors.borderButton            : Colors.createTreatmentInactive
                Rectangle {
                    property real diameter  : Variables.sliderCircleDiameter
                    x: _settingsRoInputSwitch.checked ? parent.width - width : 0
                    anchors.verticalCenter: parent.verticalCenter
                    width   : diameter
                    height  : diameter
                    radius  : diameter
                    color   : _settingsRoInputSwitch.active ? Colors.highlightProgressBar : Colors.createTreatmentInactive
                    border  {
                        width: Variables.progressbarHandlerBorderWidth
                        color: Colors.textMain
                    }
                }
            }

            contentItem: Text {
                width   : parent.width
                height  : parent.height
                text    : _settingsRoInputSwitch.checked ? qsTr("ON") : qsTr("OFF")
                font.pixelSize: Fonts.fontPixelButton
                color   : _settingsRoInputSwitch.active  ? Colors.textMain : Colors.textDisableButton
                verticalAlignment       : Text.AlignTop
                horizontalAlignment     : Text.AlignHCenter
            }
        }
    }

    Connections { target: _settingsRoInputSwitch
        function onClicked() {
            vDuetRoWaterDG.doAdjustment ( _settingsRoInputSwitch.checked )
        }
    }
    Connections { target: vDuetRoWaterDG
        function onAdjustmentTriggered(vValue) {
            if ( vDuetRoWaterDG.adjustment_Accepted ) {
                _settingsRoInput.notificationText = ""
            }
            else {
                _settingsRoInput.notificationText = vDuetRoWaterDG.notification // adjustment_ReasonText
            }
            vSettings.roWaterMode = vDuetRoWaterDG.status
        }
    }
}

