import Quickshell
import Quickshell.Io
import QtQuick
import QtQuick.Layouts
import Quickshell.Widgets
import QtQuick.Effects

import Quickshell.Services.SystemTray

Item {
    id: root
    Layout.preferredHeight: 30
    Layout.preferredWidth: layout.implicitWidth
    RowLayout {
        spacing: 0
        anchors {
            top: parent.top
            bottom: parent.bottom
        }
        id: layout
        Repeater {
            model: SystemTray.items
            delegate: Item {
                required property SystemTrayItem modelData
                id: item
                Layout.preferredHeight: 30
                Layout.preferredWidth: 30
                MouseArea {
                    anchors.fill: parent
                    anchors.centerIn: parent
                    onPressed: event => {
                        item.modelData.display(trayItemPopupWindow, mouseX, mouseY)
                    }
                }
                IconImage {
                    anchors.centerIn: parent
                    implicitSize: 20
                    source: modelData.icon
                }
                PopupWindow {
                    // hacky ass way to get a tray item popup window
                    implicitHeight: 1
                    implicitWidth: 1
                    color: "transparent"
                    id: trayItemPopupWindow
                    anchor.item: item
                    visible: true
                }
            }
        }
    }
    Rectangle {
        z: -1
        anchors {
            left: root.left
            right: root.right
            verticalCenter: root.verticalCenter
        }
        height: root.height - 5
        radius: 6
        color: "black"
    }
}
