import Quickshell
import Quickshell.Io
import QtQuick
import QtQuick.Layouts
import Quickshell.Widgets
import Quickshell.Hyprland

RowLayout {
    id: root
    spacing: 3

    Repeater {
        model: Hyprland.workspaces
        delegate: Item {
            required property int index
            property HyprlandWorkspace index_workspace: Hyprland.workspaces.values[index]
            width: 25
            height: 30
            MouseArea {
                Rectangle {
                    id: reg
                    anchors.fill: parent
                    color: index_workspace.focused ? "#3B3B3B" : "#808080"
                }
                Layout.fillWidth: true
                Text {
                    anchors.centerIn: parent
                    text: index_workspace.id
                    color: "#FFFFFF"
                    font.pointSize: 10.75
                }
                anchors.fill: parent
                acceptedButtons: Qt.LeftButton
                onPressed: event => {
                    if (event.button === Qt.LeftButton) {
                        Hyprland.dispatch('workspace ' + index_workspace.id);
                    }
                    for (x in index_workspace.toplevels.values) {
                        console.log(index_workspace.toplevels.values[x].title);
                    }
                }
            }
        }
    }
}
