#!/usr/bin/env bash
# Screenshot helper: region | window | output. Saves under ~/Pictures/Screenshots
# and copies to the clipboard.
set -euo pipefail

mode="${1:-region}"
dir="$HOME/Pictures/Screenshots"
mkdir -p "$dir"
file="$dir/$(date +%Y-%m-%d_%H-%M-%S).png"

case "$mode" in
  region)
    geom="$(slurp)" || exit 0
    grim -g "$geom" "$file"
    ;;
  window)
    geom="$(hyprctl activewindow -j | jq -r '"\(.at[0]),\(.at[1]) \(.size[0])x\(.size[1])"')"
    grim -g "$geom" "$file"
    ;;
  output)
    grim "$file"
    ;;
  *)
    echo "Usage: omarchy-capture-screenshot [region|window|output]" >&2
    exit 1
    ;;
esac

wl-copy <"$file" 2>/dev/null || true
command -v notify-send >/dev/null && notify-send -u low "Screenshot saved" "$file" || true
exit 0
