#!/bin/bash

# Usage: workspace-handler.sh <mode> <direction>
# mode: "change" | "move"
# direction: "next" | "previous"

mode="$1"
direction="$2"

if [[ -z "$mode" || -z "$direction" ]]; then
  exit 1
fi

if [[ "$mode" != "change" && "$mode" != "move" ]]; then
  exit 1
fi

if [[ "$direction" != "next" && "$direction" != "previous" ]]; then
  exit 1
fi

if [[ "$GNOME_STYLE_WORKSPACES" == "true" ]] && command -v hyprnome &>/dev/null; then
  # Hyprnome style
  if [[ "$mode" == "change" ]]; then
    if [[ "$direction" == "previous" ]]; then
      exec hyprnome --previous
    else
      exec hyprnome
    fi
  else
    if [[ "$direction" == "previous" ]]; then
      exec hyprnome --previous --move
    else
      exec hyprnome --move
    fi
  fi
else
  # Hyprland style
  if [[ "$mode" == "change" ]]; then
    if [[ "$direction" == "previous" ]]; then
      exec hyprctl dispatch focusworkspaceoncurrentmonitor r-1
    else
      exec hyprctl dispatch focusworkspaceoncurrentmonitor r+1
    fi
  else
    if [[ "$direction" == "previous" ]]; then
      exec hyprctl dispatch movetoworkspace r-1
    else
      exec hyprctl dispatch movetoworkspace r+1
    fi
  fi
fi
