#!/bin/bash

# omarchy:summary=Toggle permanent Hyprland flags by copying them into a directory that's sourced entirely.
# omarchy:args=<flag-name> [on|off|toggle]

usage() {
  echo "Usage: omarchy-hyprland-toggle <flag-name> [on|off|toggle]" >&2
}

if (($# < 1)); then
  usage
  exit 1
fi

FLAG_NAME="$1"
ACTION="${2:-toggle}"
FLAG_FILE="$HOME/.local/state/omarchy/toggles/hypr/$FLAG_NAME.lua"
FLAG_SOURCE="$OMARCHY_PATH/default/hypr/toggles/$FLAG_NAME.lua"

on() {
  if [[ -f $FLAG_SOURCE ]]; then
    mkdir -p "$(dirname "$FLAG_FILE")"
    cp "$FLAG_SOURCE" "$FLAG_FILE"
  else
    echo "Flag not found: $FLAG_NAME" >&2
    exit 1
  fi
}

off() {
  rm -f "$FLAG_FILE"
}

toggle() {
  if [[ -f $FLAG_FILE ]]; then
    off
    echo "off"
  else
    on
    echo "on"
  fi
}

case $ACTION in
  on) on ;;
  off) off ;;
  toggle) toggle ;;
  *)
    usage
    exit 1
    ;;
esac

hyprctl reload >/dev/null
