#!/bin/bash

# omarchy:summary=Send a desktop notification with Omarchy glyph and body spacing
# omarchy:args=<headline> [description] [-g <glyph>] [-u <low|normal|critical>] [notify-send options]
# omarchy:examples=omarchy notification send "Reminder" "5 minutes are up" -g 󰔛 -u critical

set -euo pipefail

if (($# < 1)); then
  echo "Usage: omarchy-notification-send <headline> [description] [-g <glyph>] [-u <low|normal|critical>] [notify-send options]"
  exit 1
fi

headline=$1
description=""
glyph=""
urgency="low"
args=()
shift

if (($# > 0)) && [[ $1 != -* ]]; then
  description=$1
  shift
fi

while (($# > 0)); do
  case $1 in
    -g|--glyph)
      glyph="$2"
      shift 2
      ;;
    -u|--urgency)
      urgency="$2"
      shift 2
      ;;
    *)
      args+=("$1")
      shift
      ;;
  esac
done

summary="$glyph    $headline"
args+=("-u" "$urgency")

if [[ -n $description ]]; then
  description=$(printf '%b' "$description" | sed 's/^/      /')
  notify-send "${args[@]}" "$summary" "$description"
else
  notify-send "${args[@]}" "$summary"
fi
