/*!
 *
 * Copyright (c) 2019-2025 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    RxManagerHeader.qml
 * \author  (original)  Tiffnay Mejia
 * \date    (original)  10-Oct-2025
 *
 */

// Qt
import QtQuick 2.12

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

Item {  id: _root
    property bool onShow: true
    property int rxProfileCount: vRxProfiles.rxProfiles.rowCount()
    signal addClicked()


    Row { id: _headerRow
        anchors {
            left    : parent.left
        }
        spacing: Variables.defaultMargin * 2

        Text { id   : headerText
            text    : qsTr("Saved Prescriptions") + (" (%1/10)").arg(_root.rxProfileCount)
            color   : Colors.textButton
            font.pointSize      : Fonts.fontPixelButton * 1.4
            verticalAlignment   : Text.AlignVCenter
        }

        BaseComboBox { id: _sortdropdown
            visible : _root.onShow
            model   : [qsTr("Favorites"), qsTr("Last Modified"), qsTr("Last Used"), qsTr("Name")]
            height  : 70
            width   : 300
            onActivated: {
                switch (currentIndex) {
                case 0:
                    print("TODO: Favorites selected " )
                    break
                case 1:
                    print("TODO: Last modified selected " )
                    break
                case 2:
                    print("TODO: Last used selected" )
                    break
                case 3:
                    print("TODO: name selected " )
                    break
                default: // Unknown state
                    break
                }
            }
        }


        TouchRect { id: _orderButton
            visible : _root.onShow
            color :  Colors.highlightMedProgressBar
            height: 70
            width : 70
            borderColor: Colors.transparent
            property bool isAscending: true // Add a property connected to this button that will; affect the model that has the list View of Rx profiles

            Image { id  : _orderImage
                source  : _orderButton.isAscending ? "qrc:/images/iAscendingSortArrow" : "qrc:/images/iDescendingSortArrow"
                width   : 35
                height  : 35
                fillMode        : Image.PreserveAspectFit
                anchors.centerIn: parent
            }
           onClicked:{
               isAscending = !isAscending
           }
        }
    }
    Row { id: _rxButtons
        visible : _root.onShow
        anchors {
            right           : parent.right
        }
        spacing: Variables.defaultMargin * 4

        TouchRect { id: _rxImportButton
            text.text : qsTr("Import")
            height: 70
            width: 244
            visible: _root.rxProfileCount === 10 && _root.onShow ? false : true
            onClicked :{
                print("TODO: import rx profile")
            }
        }

        TouchRect {id: _rxAddButton
            text.text : qsTr("Add Prescription")
            height: 70
            width: 244
            visible: _root.rxProfileCount === 10 && _root.onShow ? false : true
            onClicked :{
                addClicked()
            }
        }
    }
}
