#!/bin/sh -e

[ ! -d "$HOME/Pictures/Screenshots" ] && mkdir -p "$HOME/Pictures/Screenshots"
SAVEPATH="$HOME/Pictures/Screenshots/$(date +'%Y%m%d-%H%M%S').png"

_notify() {
	notify-send -u normal -t 2000 -a "Screenshot" \
		-i "${XDG_DATA_HOME:-$HOME/.local/share}/icons/notifications/photograph.png" \
		"Screenshot" "$1"
}

case $1 in
{% if screenshot == 'grim' %}
	--full)
		grim "${SAVEPATH}"
		_notify "Fullscreen taken..." ;;
	--region)
		grim -g "$(slurp)" "${SAVEPATH}"
		_notify "Selected region taken..." ;;
	--full-optional)
		grim - | swappy -f - ;;
	--region-optional)
		grim -g "$(slurp)" - | swappy -f - ;;
	--full-copy)
		grim - | wl-copy
		_notify "Fullscreen copied to clipboard..." ;;
	--region-copy)
		grim -g "$(slurp)" - | wl-copy
		_notify "Selected region copied to clipboard..." ;;
{% elif screenshot == 'wayshot' %}
	--full)
		wayshot -f "${SAVEPATH}"
		_notify "Fullscreen taken..." ;;
	--region)
		wayshot -s "$(slurp -f '%x %y %w %h')" -f "${SAVEPATH}"
		_notify "Selected region taken..." ;;
	--full-optional)
		wayshot --stdout | swappy -f - ;;
	--region-optional)
		wayshot -s "$(slurp -f '%x %y %w %h')" --stdout | swappy -f - ;;
	--full-copy)
		wayshot --stdout | wl-copy
		_notify "Fullscreen copied to clipboard..." ;;
	--region-copy)
		wayshot -s "$(slurp -f '%x %y %w %h')" --stdout | wl-copy
		_notify "Selected region copied to clipboard..." ;;
{% endif %}
	*) ;;
esac
