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

// Qt
import QtQuick 2.15

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

/*!
 * \brief   SettingsHome is the screen
 * which is the default screen in the "Settings" stack
 */
SettingsBase { id: _root
    objectName: "_SettingsHome"

    property alias itemsText      : _settingItems.itemsText
    property alias itemsVisible   : _settingItems.itemsVisible

    readonly property int rowCount      : Math.ceil(_settingItems.itemsVisible.filter(value => value).length / 2)
    readonly property int colCount      : 2

    readonly property int delegateWidth : parent.width / 2.5
    readonly property int delegateHeight: 80

    signal itemClicked(int vIndex)

    contentArea.anchors.topMargin: serviceMode ? Variables.defaultMargin * 2 : 0

    contentItem: TouchGrid { id: _settingItems
        onItemClicked       : _root.itemClicked(vIndex)
        rowCount            : _root.rowCount
        colCount            : _root.colCount
        itemWidth           : _root.delegateWidth
        itemHeight          : _root.delegateHeight
        lineThickness       : 0
        arrowWidth          : Variables.iconButtonSize
        arrowHeight         : Variables.iconButtonSize
        arrowRightMargin    : Variables.defaultMargin
        delegateColor       :  Colors.panelBackgroundColor
        delegateBorderWidth : 1
        delegateBorderColor : Colors.panelBorderColor
        itemsHasIndent      : Array(itemsText.length).fill(true) // sets all to true
    }

    // The Main menu need to hide in case we have any alarm, if not the menu is covered by keyboard but the alram does not.
    // So what happens is alarm shows up on keyboard but a little higher (main menu height) and it makes the UI not nice.
    // In the Sub Settings Screens we hide the main menu since those have back button,
    // but we need to show it back again in the settings home screen since it is a main screen and the only navigation is through the main menu.
    // So it overrides the parent logic.
    onVisibleChanged: {
        if (visible) {
            _mainMenu.hidden = false
        }
    }
}

