/*!
 *
 * Copyright (c) 2021-2022 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)      Behrouz NematiPour
 * \date    (last)      22-May-2021
 * \author  (original)  Behrouz NematiPour
 * \date    (original)  16-Apr-2021
 *
 */

// Qt
import QtQuick 2.12

//  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 itemsEnabled   : _settingItems.itemsEnabled
    property alias itemsVisible   : _settingItems.itemsVisible

    readonly property int rowCount      : 5
    readonly property int colCount      : itemsText.length > rowCount ? Math.ceil(itemsText.length / rowCount) : 1

    signal itemClicked(int vIndex)

    TouchGrid { id: _settingItems
        anchors.centerIn: _root
        onItemClicked   : _root.itemClicked(vIndex)
        rowCount        : _root.rowCount
        colCount        : _root.colCount
    }

    // Test Codes
    Row {
        spacing : Variables.minVGap2
        anchors {
            top : parent.top
            left: parent.left
            topMargin   : 35
            leftMargin  : 35
        }
        TouchRect { id : _clearAlarmCondition
            visible : false                                     // TODO : phase 1 doesn't have this feature (disinfection schedule)
            objectName: "_clearAlarmCondition"
            width   : 300
            height  : Variables.logoDiameter
            text.text: qsTr("Clear Alarm Condition")
            onClicked:                 _alarmItem.clearAlarm()
        }
    }

    // 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 = serviceMode
        }
    }
}

