#!/bin/bash

function error {
  echo -e "\e[91m$1\e[39m"
  exit 1
}

DIRECTORY="$(readlink -f "$(dirname "$0")")"

if [ -z "$(dpkg-query -W --showformat='${Status}\n' yad 2>/dev/null | grep "install ok installed")" ];then
  zenity --title='Artian-Apps' --window-icon="${DIRECTORY}/icons/logo.png" \
	  --list --text="Do you want to uninstall YAD?" \
	  --ok-label=Yes --cancel-label=No \
	  --column=foo --hide-header 2>/dev/null && "${DIRECTORY}/etc/terminal-run" "sudo apt purge -y yad;echo -e '\nClosing in 5 seconds.';sleep 5" "Uninstalling YAD"
fi

echo "Removing menu button..."
rm -f ~/.local/share/applications/Artian-apps.desktop
rm -f ~/.local/share/applications/Artian-apps-settings.desktop
rm -f ~/.config/autostart/Artian-apps-updater.desktop
rm -f ~/Desktop/Artian-apps.desktop

echo "Removing terminal command..."
sudo rm -f /usr/local/bin/Artian-apps

echo -e "\e[32mUninstallation complete.\e[97m Only $HOME/Artian-apps still remains.
If Artian-apps didn"\'"t work for you, \e[4m\e[21m\e[5mPLEASE\e[0m\e[97m consider submitting a \e[1mbug report\e[0m!
--> \e[96mhttps://git.fdc.abrish.ir/a.kamyar/PublicFiles/issues/new\e[39m"

