#!/usr/bin/env bash

# omarchy:summary=Remove all the named Flathub apps from the system installation if they're installed (otherwise ignore).
# omarchy:args=<app-ids...>
# omarchy:requires-sudo=true

installed=()
for app in "$@"; do
  omarchy-pkg-flatpak-present "$app" && installed+=("$app")
done

if ((${#installed[@]} > 0)); then
  if ((EUID == 0)); then
    flatpak uninstall --system -y --noninteractive "${installed[@]}"
  else
    sudo flatpak uninstall --system -y --noninteractive "${installed[@]}"
  fi
fi
