/*!
 *
 * 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    SettingsRootSSHAccess.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   SettingsRootSSHAccess is the screen
 *          which enables the Ro Water Input
 */
SettingsBase    { id: _root
    itemIndex       : SettingsStack.RootSSHAccess

    confirmVisible  : false

    Row { id: _settingsRootSSHAccessRow
        anchors.centerIn: parent

        Text { id           : _settingsRootSSHAccessLabel
            text            : qsTr("Root SSH Login")
            width           : 300
            height          : _settingsRootSSHAccessSwitch.height
            color           : Colors.white
            font.pixelSize: Fonts.fontPixelButton
            verticalAlignment       : Text.AlignVCenter
            horizontalAlignment     : Text.AlignLeft
        }

        Switch { id: _settingsRootSSHAccessSwitch
            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           : _settingsRootSSHAccessSwitch.checked ? Colors.backgroundButtonSelect  : Colors.createTreatmentInactive
                border.color    : _settingsRootSSHAccessSwitch.checked ? Colors.borderButton            : Colors.createTreatmentInactive
                Rectangle {
                    property real diameter  : Variables.sliderCircleDiameter
                    x: _settingsRootSSHAccessSwitch.checked ? parent.width - width : 0
                    anchors.verticalCenter: parent.verticalCenter
                    width   : diameter
                    height  : diameter
                    radius  : diameter
                    color   : _settingsRootSSHAccessSwitch.active ? Colors.highlightProgressBar : Colors.createTreatmentInactive
                    border  {
                        width: Variables.progressbarHandlerBorderWidth
                        color: Colors.textMain
                    }
                }
            }

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

    Connections { target: _settingsRootSSHAccessSwitch
        function onClicked() {
            vDevice.rootSSHAccess = _settingsRootSSHAccessSwitch.checked
        }
    }
    Connections { target: vDevice
        // in case the value is rejecte it will be set to the previous value
        // also the init value shall be set when navigate to the screen
        function onRootSSHAccessChanged ( vValue ) { _settingsRootSSHAccessSwitch.checked   = vValue }
        function onStatusChanged        ( vValue ) { _root.notificationText                 = vValue }
    }
}

