/*!
 *
 * Copyright (c) 2023-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    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

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

/*!
 * \brief   SettingsROInput is the screen
 *          which enables the Ro Water Input
 */
SettingsBase    { id: _root
    itemIndex       : SettingsStack.Localization
    confirmVisible  : true
    notificationText: vLocalization.notification

    contentArea.anchors.topMargin: Variables.defaultMargin * 10

    contentItem: Item {
        LabelUnitContainer { id: _settingsLanguageItem
            anchors.horizontalCenter        : parent.horizontalCenter
            width                           : Variables.adjustmentLabelUnitContainerWidth
            height                          : Variables.adjustmentLabelUnitContainerHeight
            text                            : qsTr("Language")

            contentItem: BaseComboBox { id: _settingsLanguageCombo
                anchors.rightMargin : Variables.defaultMargin * 2
                anchors.leftMargin  : anchors.rightMargin
                anchors.topMargin   : Variables.defaultMargin / 2
                anchors.bottomMargin: anchors.topMargin
                currentIndex        : vLocalization.languageIndex
                model               : vLocalization.languageList
            }
        }
    }

    onConfirmClicked    : {
        _confirmDialog.titleText = _headerBar.titleText
        _confirmDialog.open()
    }

    Connections { target: _confirmDialog
        function onAccepted() {
            if ( _confirmDialog.titleText === _headerBar.titleText  ) { // use the title as the indication of what has been confirmed and if that is related to this function.
                vLocalization.doAdjustment(_settingsLanguageCombo.currentIndex)
            }
        }
    }

    Connections { target: _settingsLanguageCombo
        function onCurrentIndexChanged() {
            vLocalization.notification = ""
        }
    }

    onVisibleChanged: {
        if (visible) {
            vLocalization.notification = ""
        }
    }
}

