import QtQuick
import QtQuick.Controls
import "../styles"

Rectangle {
    property alias currentIndex: listView.currentIndex
    // 信号定义 - 添加参数声明
    signal menuSelected(string viewPath)

    color: "transparent"
    radius: 12

    // 背景层
    Rectangle {
        anchors.fill: parent
        color: "#252541"
        opacity: 0.8
        radius: parent.radius
    }

    // 装饰边框
    Rectangle {
        anchors.fill: parent
        color: "transparent"
        radius: parent.radius
        border.width: 1
        border.color: "#4a4a7a"
    }

    // 标题
    Label {
        text: "功能导航"
        font {
            bold: true
            pixelSize: 22
        }
        color: "#e0e0ff"
        anchors.horizontalCenter: parent.horizontalCenter
        topPadding: 25
        bottomPadding: 15
    }

    ListView {
        id: listView
        anchors.fill: parent
        anchors.topMargin: 70
        anchors.bottomMargin: 20
        anchors.margins: 10
        model: ListModel {
            ListElement { name: "学生列表"; icon: "📋"; view: "qrc:/src/ui/views/ListView.qml" }
            ListElement { name: "添加学生"; icon: "➕"; view: "qrc:/src/ui/views/InputView.qml" }
            ListElement { name: "查询学生"; icon: "🔍"; view: "qrc:/src/ui/views/QueryView.qml" }
            ListElement { name: "数据统计"; icon: "📊"; view: "qrc:/src/ui/views/StatsView.qml" }
        }

        delegate: Rectangle {
            width: parent.width - 20
            height: 60
            x: 10
            color: ListView.isCurrentItem ? "#6a5acd" : "transparent"
            radius: 8

            Behavior on color {
                ColorAnimation { duration: 200 }
            }

            Row {
                spacing: 15
                anchors.verticalCenter: parent.verticalCenter
                anchors.left: parent.left
                anchors.leftMargin: 25

                Rectangle {
                    width: 36
                    height: 36
                    radius: 18
                    color: ListView.isCurrentItem ? "#ffffff" : "#6a5acd"
                    anchors.verticalCenter: parent.verticalCenter

                    Label {
                        text: icon
                        font.pixelSize: 18
                        anchors.centerIn: parent
                        color: ListView.isCurrentItem ? "#6a5acd" : "#ffffff"
                    }
                }

                Label {
                    text: name
                    font.pixelSize: 18
                    color: ListView.isCurrentItem ? "#ffffff" : "#c0c0e0"
                }
            }

            MouseArea {
                anchors.fill: parent
                hoverEnabled: true
                onEntered: {
                    if (!ListView.isCurrentItem) {
                        parent.color = "#4a4a7a"
                    }
                }
                onExited: {
                    if (!ListView.isCurrentItem) {
                        parent.color = "transparent"
                    }
                }
                onClicked: {
                    listView.currentIndex = index
                    // 使用带参数的信号调用
                    menuSelected(view)
                }
            }
        }
    }
}