import QtQuick
import Quickshell
import Quickshell.Hyprland
import "../../../colors"

Row {   // Workspace Row
    id: workspacesRow

    required property HyprlandMonitor thisMonitor
    spacing: 8

    Repeater {   // repeats workspaces
        model: Hyprland.workspaces

        Rectangle {  //workspace
            visible: modelData.monitor === thisMonitor
            width: (workspaceNum.width + 16) < (workspaceNum.height + 8) ? workspaceNum.height + 8 : workspaceNum.width + 16
            height: workspaceNum.height + 8
            radius: 4
            color: workspaceButton.containsMouse ? Colors.tertiaryContainer
                 : modelData.active ? Colors.primaryContainer
                 : Colors.secondaryContainer
            border.color: workspaceButton.containsMouse ? Colors.tertiaryContainer_fg
                 : modelData.active ? Colors.primaryContainer_fg
                 : Colors.secondaryContainer_fg
            border.width: 2

            MouseArea {
                id: workspaceButton
                hoverEnabled: true
                cursorShape: Qt.PointingHandCursor
                anchors.fill: parent
                onClicked: Hyprland.dispatch("workspace " + modelData.id)
    
                Rectangle {
                    anchors.fill: parent
                    color:  "transparent"
                    radius: 6
                }
            }

            Text {
                id: workspaceNum
                text: modelData.id
                anchors.centerIn: parent
                color: workspaceButton.containsMouse ? Colors.tertiary
                     : modelData.active ? Colors.primary
                     : Colors.secondary
                font.pixelSize: 18
                font.family: "Inter, sans-serif"
            }
        }

    }

    Text {
        visible: Hyprland.workspaces.length === 0
        text: "No Workspaces"
        color: Colors.error
        font.pixelSize: 18
    }
}
