/*!
 *
 * Copyright (c) 2019-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    MainMenu.qml
 * \author  (last)      Behrouz NematiPour
 * \date    (last)      18-Jul-2023
 * \author  (original)  Behrouz NematiPour
 * \date    (original)  17-Oct-2019
 *
 */

// Qt
import QtQuick 2.12

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

/*!
 * \brief   The MainMenu Component
 * which contains three [Treatment, Manager, Settings]
 */
Rectangle { id: _root

    property alias          index           : _listView.currentIndex
    property bool           hidden          : false
    property bool           disable         : false
    property int            titlePixelSize  : 40
    property color          backgroundColor : Colors.backgroundMainMenu
    property int            highlightHeight : 10
    property bool           isMainMenu      : false
    property bool           isMainTreatment : false

    width                                   : parent.width
    height                                  : Variables.mainMenuHeight
    color                                   : _root.backgroundColor
    clip                                    : true

    gradient: Gradient {
        GradientStop { position: 0.2; color: Qt.lighter(Colors.backgroundMain, 1.2) }
        GradientStop { position: 0.8; color: Qt.darker (Colors.backgroundMain, 1.2) }
    }

    signal itemPressed(int vIndex)

    ListModel { id: _mainTreatmentModel
        ListElement {   text: qsTr("Treatment")     }
        ListElement {   text: qsTr("Trends")        }
        ListElement {   text: qsTr("Heparin")       }
    }

    ListModel { id: _mainMenuModel
        ListElement {   text: qsTr("Treatment")     }
        ListElement {   text: qsTr("Prescriptions") }
        ListElement {   text: qsTr("Settings")      }
    }

    ListView { id: _listView
        property alias  index                   : _listView.currentIndex

        anchors.fill                            : parent
        anchors.leftMargin                      : 30
        anchors.rightMargin                     : anchors.leftMargin
        model                                   : isMainMenu        ? _mainMenuModel        :
                                                  isMainTreatment   ? _mainTreatmentModel   :
                                                                      null
        currentIndex                            : 0
        highlightFollowsCurrentItem             : true
        highlightMoveDuration                   : 500
        highlightMoveVelocity                   : -1
        orientation                             : ListView.Horizontal
        interactive                             : false

        onCurrentIndexChanged: itemPressed(currentIndex)

        highlight: Rectangle { id: _highlightRectangle
            objectName: "_highlightRectangle"
            color: "transparent"

            Rectangle {
                id: _highlightedItem
                objectName: "highlightedItem"
                anchors {
                    horizontalCenter: parent.horizontalCenter
                    bottom: parent.bottom
                    bottomMargin: (height / 2) * -1
                }
                height: _root.highlightHeight
                width: parent.width / 2
                radius: 10
                color: Colors.backgroundButtonSelect
            }
        }

        delegate: Item { id: _delegateControl
            objectName  : "delegateControl"
            width       : ListView.view.count ? ListView.view.width / ListView.view.count : 0
            height      : ListView.view.height

            TouchRect { id : _touchRect
                objectName: "_touchRect" + index
                animated    : false
                anchors.fill: parent
                text.text   : model.text
                border.width: 0
                pixelSize   : titlePixelSize

                onPressed: {
                    if (_listView.currentIndex !== index) {
                        _listView.currentIndex = index
                    }
                }
            }
        }
    }
    Behavior on anchors.bottomMargin { PropertyAnimation { } }
}
