/*!
 *
 * 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"
import "qrc:/compounds"

/*!
 * \brief   SettingsVolumeBrightness is used to adjust the
 *          volume (alarm/system), brightness on the device
 */
SettingsBase    { id: _root
    readonly property int spacing: 100

    itemIndex                       : SettingsStack.VolumeBrightness
    confirmVisible                  : false
    notificationText                :  ""
    contentArea.anchors.topMargin   : Variables.defaultMargin * 10

    QtObject { id: _private
        readonly property int   contentWidth     : _root.width / 2.5
    }

    contentItem: Column {
        spacing     : _root.spacing

        Row { id: _themeRow
            anchors.horizontalCenter: parent.horizontalCenter
            width                   : _private.contentWidth

            Text  { id  : _text
                font.pixelSize  : Fonts.fontPixelContainerTitle
                color           : Colors.offWhite
                width           : 200
                text            : qsTr("Theme")
            }

            BaseSwitch  { id: _darkMode
                source          : vSettings.darkMode ? "qrc:/images/iMoon" : "qrc:/images/iSun"
                checked         : vSettings.darkMode
                activeColor     : Colors.switchActiveColor
                inactiveColor   : Colors.switchInactiveColor
                knobColor       : vSettings.darkMode ?  Colors.switchKnobActiveColor :
                                                        Colors.switchKnobInactiveColor

                onClicked: {
                    vSettings.darkMode = ! vSettings.darkMode
                }
            }
        }

        SettingsSlider { id: _brightness
            anchors.horizontalCenter: parent.horizontalCenter
            width                   : _private.contentWidth
            value                   : vDevice.brightnesss ?? 0
            text                    : qsTr("Brightness")
            textOnly                : true
            sliderBkgndColor        : Colors.createTreatmentInactive

            onValueChanged          :  vDevice.brightness = slider.value
        }

        SettingsSlider { id: _volume
            anchors.horizontalCenter: parent.horizontalCenter
            width                   : _private.contentWidth
            value                   : vAdjustmentAlarmVolume.tdAlarmVolume ?? 0
            text                    : qsTr("Alarm Volume")
            textOnly                : true
            sliderBkgndColor        : Colors.createTreatmentInactive

            onValueChanged  : vAdjustmentAlarmVolume.doAdjustment( slider.value )
        }
    }

    Connections { target: vAdjustmentAlarmVolume
        function onAdjustmentTriggered  ( vValue ) {
            if ( vAdjustmentAlarmVolume.adjustment_Accepted ) {
                vSettings   .alarmVolume   = vAdjustmentAlarmVolume.tdAlarmVolume
                _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.tdAlarmVolume )
        }
    }

    Connections { target: vDevice
        function onStatusChanged    ( vValue ) { _root.notificationText  = vValue ? qsTr("Brightness Status: %1" ).arg(vValue) : "" }
    }
}
