#!/bin/bash
# Grid Notification Hook
# Sends OS notifications for Grid events

# Read input from stdin
INPUT=$(cat)
EVENT_TYPE=$(echo "$INPUT" | jq -r '.event // "unknown"')
MESSAGE=$(echo "$INPUT" | jq -r '.message // ""')
TITLE=$(echo "$INPUT" | jq -r '.title // "The Grid"')

# Determine notification style based on event
case "$EVENT_TYPE" in
    "success")
        SOUND="Glass"
        SUBTITLE="Mission Complete"
        ;;
    "failure"|"error")
        SOUND="Basso"
        SUBTITLE="Mission Failed"
        ;;
    "warning")
        SOUND="Ping"
        SUBTITLE="Warning"
        ;;
    "checkpoint")
        SOUND="Pop"
        SUBTITLE="Checkpoint Reached"
        ;;
    *)
        SOUND="Pop"
        SUBTITLE="Notification"
        ;;
esac

# macOS notification
if command -v osascript &> /dev/null; then
    osascript -e "display notification \"$MESSAGE\" with title \"$TITLE\" subtitle \"$SUBTITLE\" sound name \"$SOUND\""
fi

# Linux notification (if available)
if command -v notify-send &> /dev/null; then
    notify-send "$TITLE" "$MESSAGE"
fi

# Terminal bell as fallback
echo -e "\a"

exit 0
