#!/usr/bin/env bash
# Removes the helper completely. Printing falls back to the browser dialog.
set -euo pipefail
APP="ams-print-helper"
DIR="${AMS_HELPER_DIR:-$HOME/.$APP}"
if [ "$(uname -s)" = "Darwin" ]; then
  # Both labels: com.aams.printhelper is what older installers wrote.
  for A in "com.astitva.$APP" "com.aams.printhelper"; do
    PLIST="$HOME/Library/LaunchAgents/$A.plist"
    launchctl unload "$PLIST" 2>/dev/null || true
    rm -f "$PLIST"
  done
else
  systemctl --user disable --now "$APP.service" 2>/dev/null || true
  rm -f "$HOME/.config/systemd/user/$APP.service"
  systemctl --user daemon-reload 2>/dev/null || true
fi
pkill -u "$(id -u)" -f "ams_print_helper\.py" 2>/dev/null || true
rm -rf "$DIR"
echo "Astitvaams Print Helper removed."
