/*!
 *
 * 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    SettingsVolumeBrightness.qml
 * \author  (last)      Behrouz NematiPour
 * \date    (last)      18-Jul-2023
 * \author  (original)  Behrouz NematiPour
 * \date    (original)  06-Jun-2021
 *
 */

// Qt
import QtQuick 2.12

// Project
import Gui.Actions 0.1

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

/*!
 * \brief   SettingsVolumeBrightness is used to adjust the
 *          volume (alarm/system), brightness on the device
 */
SettingsBase    { id: _root
    itemIndex       : SettingsStack.VolumeBrightness

    readonly property int spacing: 50

    confirmVisible  : false

    notificationText:  ""


    Column {
        spacing     : _root.spacing
        anchors.centerIn: parent
        Row {
            spacing : _root.spacing
            anchors.horizontalCenter: parent.horizontalCenter
            Label  {
                anchors.verticalCenter: parent.verticalCenter
                width   : labelWidth
                text    : qsTr("Brightness")
            }
            Slider { id : _brightness
                anchors.verticalCenter: parent.verticalCenter
                width   : 500
                step    : 1    // no zero
                minimum : 1
                maximum : 5
                ticks   : true
                unit    : ""
                onReleased  : vDevice.brightness = _brightness.value
                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 onBrightnessChanged    ( vValue ) { _brightness.reset(vValue) }
                    function onStatusChanged        ( vValue ) { _root.notificationText = vValue }
                }
            }
            Label  {
                anchors.verticalCenter: parent.verticalCenter
                width   : 100
                text    : vDevice.brightness + _brightness.unit
            }
        }

        Row {
            spacing     : _root.spacing
            anchors.horizontalCenter: parent.horizontalCenter
            Label  {
                anchors.verticalCenter: parent.verticalCenter
                width   : labelWidth
                text: qsTr("Alarm Volume")
            }
            Slider { id : _alarmVolume
                anchors.verticalCenter: parent.verticalCenter
                width   : 500
                step    : 1    // no zero
                minimum : 1
                maximum : 5
                ticks   : true
                unit    : ""
                onReleased  : {
                    vAdjustmentAlarmVolume.doAdjustment( _alarmVolume.value )
                }
                Connections { target: vAdjustmentAlarmVolume
                    function onAdjustmentTriggered  ( vValue ) {
                        if ( vAdjustmentAlarmVolume.adjustment_Accepted ) {
                            vSettings   .alarmVolume   = vAdjustmentAlarmVolume.hdAlarmVolume
                            _root.notificationText  = ""
                        }
                        else {
                            _root.notificationText  = vAdjustmentAlarmVolume.adjustment_ReasonText
                        }
                        // regardless of the rejection or acceptance the value will be sent from C++ to be adjusted.
                        _alarmVolume.reset          ( vAdjustmentAlarmVolume.hdAlarmVolume )
                    }
                }
            }
            Label  {
                anchors.verticalCenter: parent.verticalCenter
                width   : 100
                text    : vAdjustmentAlarmVolume.hdAlarmVolume + _alarmVolume.unit
            }
        }

        Row {
            visible     : false
            spacing     : _root.spacing
            anchors.horizontalCenter: parent.horizontalCenter
            Label  {
                anchors.verticalCenter: parent.verticalCenter
                width   : labelWidth
                text    : qsTr("System Volume")
            }
            Slider { id : _systemVolume
                anchors.verticalCenter: parent.verticalCenter
                width   : 500
                step    : 20    // no zero
                minimum : 20    // 1
                maximum : 100   // 5
                ticks   : true
                unit    : qsTr("%")
            }
            Label  {
                anchors.verticalCenter: parent.verticalCenter
                width   : 100
                text    : "0" + _systemVolume.unit
            }
        }
    }
}
