/*!
 *
 * 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    SettingsBase.qml
 * \author  (last)      Behrouz NematiPour
 * \date    (last)      13-Mar-2024
 * \author  (original)  Behrouz NematiPour
 * \date    (original)  16-Apr-2021
 *
 */

// Qt
import QtQuick 2.12

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

/*!
 * \brief   SettingsBase is the screen
 *          which is the parent screen of all setting screens in the "Settings" stack
 */
ScreenItem { id: _root
    objectName: "_SettingsBase"

    property Item contentItem           : null
    property alias contentArea          : _contentArea

    property int    labelWidth          : 200
    property int    entryWidth          : 100

    property var    firstFocusInput     : undefined

    property int    itemIndex           : 0
    property alias  title               : _titleText.text

    property alias  notificationText    : _information.text
    property int    notificationMargin  : Variables.notificationHeight + Variables.minVGap

    property alias     backVisible      : _backButton   .visible
    property alias     backEnabled      : _backButton   .enabled
    property alias  confirmVisible      : _confirmButton.visible
    property alias  confirmEnabled      : _confirmButton.enabled
    property alias  confirmText         : _confirmButton.text

    signal    backClicked()
    signal confirmClicked()

    function setFocus() {
        if (firstFocusInput) {
            firstFocusInput.textInput.forceActiveFocus()
            _keyboard.setVisible(true)
        }
    }

    BackButton { id : _backButton
        objectName: "_backButton"
        visible: true
        enabled: true
        anchors {
            top     : _root.top
            left    : _root.left
        }
        onClicked: {
            _root.backClicked()
            _headerBar.titleText = settingsTitle
            pop()
        }
    }

    ConfirmButton { id : _confirmButton
        objectName: "_confirmButton"
        visible: true
        enabled: true
        onClicked: {
            _root.confirmClicked()
            _keyboard.setVisible(false)
        }
    }

    Text { id: _titleText
        anchors {
            top             : _root.top
            topMargin       : Variables.defaultMargin * 3       // add margins to match design
            horizontalCenter: parent.horizontalCenter
        }
        horizontalAlignment : Text.AlignHCenter
        color               : Colors.textMain
        font.pixelSize      : Fonts.fontPixelTitle
    }

    ContentArea { id : _contentArea
        anchors {
            fill        :  _root
            topMargin   : Variables.defaultMargin * 6   // add margins for content in each settings page to match design
            leftMargin  : Variables.defaultMargin * 2
            rightMargin : Variables.defaultMargin * 2
            bottomMargin: Variables.settingsContentBottomMargin
        }

        contentItem: _root.contentItem
    }

    // this meant to be used specifically as current state notification mostly for the message respose back reasons.
    NotificationBarSmall { id: _information
        visible     : text
        color       : Colors.transparent
        textColor   : Colors.white
        imageSource : ""
        text        : ""
        anchors {
            bottom          : undefined
            bottomMargin    : _root.notificationMargin
            verticalCenter  : _backButton.verticalCenter
            left            : _backButton.right
            right           : _confirmButton.left
        }
    }

    onVisibleChanged: {
        if (visible) {
            _mainMenu.hidden = true
        }
    }
}
