/*!
 *
 * Copyright (c) 2019-2020 Diality Inc. - All Rights Reserved.
 * \copyright                                                       \n
 *          THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM,  \n
 *          IN PART OR IN WHOLE,                                    \n
 *          WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. \n
 *
 * \file    main.qml
 * \date    2019/09/30
 * \author  Behrouz NematiPour
 *
 */

// Qt
import QtQuick 2.12
import QtQuick.Controls 2.12

// Project
//  C++ imports
import Gui.View 0.1;
import Gui.Actions 0.1;
//  Qml imports
import "qrc:/globals"
import "qrc:/pages"
import "qrc:/components"
import "qrc:/dialogs"

/*
 * \brief   Initialization and start point of the QML
 */
Item { id : _mainItem
    width : Variables.applicationWidth
    height: Variables.applicationHeight

    property alias powerOffDialog: _powerOffDialog

    GuiView { id: _GuiView
        onDidActionReceive: {
            switch(vAction) {
            case GuiActions.PowerOff:
                if (vData[GuiActions.PowerOff_Show] === GuiActions.Command)
                    _powerOffDialog.open()
                if (vData[GuiActions.PowerOff_Show] === GuiActions.Timeout)
                    _powerOffDialog.close()
                break;
            }
        }
    }

    // ----- Follow the below Z order -----
    // 1 - Screens
    // 1 - 1
    SettingsStack  { id: _settingsStack  }
    // 1 - 2
    ManagerStack   { id: _mansagerStack  }
    // 1 - 3
    TreatmentStack { id: _treatmentStack }

    // 2 - Header
    LogoD { id: _headerLogo }

    // 3 - Footer
    MainMenu { id: _mainMenu
        titles: [ qsTr("Treatment") , qsTr("Manager") , qsTr("Settings") ]
        Component.onCompleted: {
            _treatmentStack.visible = true
        }
        onItemPressed: {
            _treatmentStack .visible = vIndex == 0;
            _mansagerStack  .visible = vIndex == 1;
            _settingsStack  .visible = vIndex == 2;
        }
    }

    // 4 - Modals
    PowerOff { id: _powerOffDialog
        onAccepted: {
            _GuiView.doActionTransmit(GuiActions.PowerOff, GuiActions.Accepted)
        }
        onRejected: {
            _GuiView.doActionTransmit(GuiActions.PowerOff, GuiActions.Rejected)
        }
    }

    // 9 - Others
    Text { // TODO : Test Code
        color: Colors.textMain
        x: 1172
        y: 767
        width: 104
        height: 27
        text: Qt.application.version
        horizontalAlignment: Text.AlignRight
        anchors.bottom: parent.bottom
        anchors.bottomMargin: 6
        anchors.right: parent.right
        anchors.rightMargin: 4
        font.pixelSize: 14
    }
}
