#!/usr/bin/env bash

#!/usr/bin/env bash
#shellcheck disable=SC2155,SC2034
#shellcheck source=/dev/null

#  /usr/share/bigbashview/bcc/apps/big-store/biglinux-category
#  Description: Control Center to help usage of BigLinux
#
#  Created: 2022/02/28
#  Altered: 2023/09/02
#
#  Copyright (c) 2023-2023, Vilmar Catafesta <vcatafesta@gmail.com>
#                2022-2023, Bruno Gonçalves <www.biglinux.com.br>
#                2022-2023, Rafael Ruscher <rruscher@gmail.com>
#  All rights reserved.
#
#  Redistribution and use in source and binary forms, with or without
#  modification, are permitted provided that the following conditions
#  are met:
#  1. Redistributions of source code must retain the above copyright
#     notice, this list of conditions and the following disclaimer.
#  2. Redistributions in binary form must reproduce the above copyright
#     notice, this list of conditions and the following disclaimer in the
#     documentation and/or other materials provided with the distribution.
#
#  THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
#  IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
#  OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
#  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
#  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
#  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
#  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
#  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
#  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
#  THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

APP="${0##*/}"
_VERSION_="1.0.0-20230902"
LIBRARY=${LIBRARY:-'/usr/share/bigbashview/bcc/shell'}
export BOOTLOG="/tmp/bigstore-$USER-$(date +"%d%m%Y").log"
export LOGGER='/dev/tty8'
export HOME_FOLDER="$HOME/.bigstore"
export TMP_FOLDER="/tmp/bigstore-$USER"
[[ -f "${LIBRARY}/bcclib.sh" ]] && source "${LIBRARY}/bcclib.sh"
[[ -f "${LIBRARY}/bstrlib.sh" ]] && source "${LIBRARY}/bstrlib.sh"

function sh_cleanup {
	[[ -e "$TMP_FOLDER/category_aur.txt" ]] && rm -f "$TMP_FOLDER/category_aur.txt"
}

function sh_config {
	declare -gA CATEGORIES
	declare -g lcode=$(sh_get_code_language)
	declare -g Programas_AUR=$"Programas AUR"
	declare -g Programas_Flatpak=$"Programas Flatpak"
	declare -g Programas_Nativos=$"Programas Nativos"

	[[ -z "$lcode" ]] && lcode=$(sh_get_code_lang)
	CATEGORIES["browser"]="firefox firefox-i18n-$lcode brave-browser opera vivaldi chromium falkon palemoon-bin librewolf-bin epiphany google-chrome microsoft-edge-stable-bin lynx"
	CATEGORIES["mail"]="thunderbird thunderbird-i18n-$lcode evolution geary kmail kube balsa claws-mail sylpheed trojita mailspring"
	CATEGORIES["download"]="kget gwget uget steadyflow jdownloader2 clipgrab youtubedl-gui xdman flareget"
	CATEGORIES["torrent"]="qbittorrent torrential deluge-gtk ktorrent fragments transmission-qt amule tixati frostwire"
	CATEGORIES["messages"]="telegram-desktop discord teamspeak3 mumble signal-desktop element-desktop caprine gajim murmur mattermost jami-gnome pidgin polari hexchat wire-desktop quassel-client zoom skypeforlinux-stable-bin slack-desktop teams viber icq-bin"
	CATEGORIES["remote"]="remmina vinagre tigervnc krdc krfb filezilla putty tmate rustdesk-bin anydesk-bin teamviewer chrome-remote-desktop"
	CATEGORIES["cloud"]="nextcloud-client owncloud-client syncthing-gtk sparkleshare rclone cozy-desktop dropbox megasync overgrive cloudcross seafile-client"
	CATEGORIES["network"]="wireshark-qt ipscan gnome-nettool mtr-gtk"
	CATEGORIES["news"]="newsflash akregator gfeeds pan liferea rssguard quiterss"
	CATEGORIES["book"]="okular foliate evince atril gnome-books bookworm fbreader coolreader calibre peruse"
	CATEGORIES["pdf"]="pdfarranger diffpdf pdfmod pdftricks pdfmixtool pdfslicer gscan2pdf mupdf masterpdfeditor masterpdfeditor-free"
	CATEGORIES["office"]="libreoffice-fresh libreoffice-fresh-$lcode libreoffice-still libreoffice-still-$lcode freeoffice onlyoffice-desktopeditors softmaker-office-2021 softmaker-office-2018 calligra wps-office wps-office-mui-$lcode"
	CATEGORIES["calendar"]="osmo kalarm gnome-calendar pantheon-calendar gnome-contacts kontact korganizer kaddressbook evolution evolution-ews morgen-bin"
	CATEGORIES["deveditor"]="atom code brackets-bin netbeans geany bluefish arduino rider gambas3-ide gnome-builder pycharm-community-edition intellij-idea-community-edition codeblocks kdevelop kdevelop-python kdevelop-php android-studio eclipse-java-bin goland visual-studio-code-bin sublime-text-3 sublime-text-4-dev okteta phpstorm webstorm cudatext-gtk2-bin cudatext-qt5-bin vscodium-bin"
	CATEGORIES["devbd"]="dbeaver mysql-workbench mariadb phpmyadmin postgresql pgadmin4 phppgadmin mysql mongodb-tools mongodb-bin percona-server questdb"
	CATEGORIES["devwebserver"]="apache nginx dnsmasq caddy cherokee tomcat10 lighttpd openlitespeed"
	CATEGORIES["devgames"]="godot gb-studio-bin blender renpy unity-editor unreal-engine makehuman"
	CATEGORIES["audioplayer"]="clementine audacious elisa rhythmbox qmmp deadbeef lollypop quodlibet strawberry spotify"
	CATEGORIES["radio"]="vocal gnome-podcasts gogglesmm gpodder great-little-radio-player radiotray-ng shortwave odio-appimage goodvibes streamtuner2 tuner"
	CATEGORIES["audioconvert"]="gnome-sound-recorder soundkonverter ciano gnac soundconverter audacity"
	CATEGORIES["audioeditor"]="audacity kwave lmms ardour mixxx Rosegarden qtractor hydrogen cecilia ocenaudio-bin"
	CATEGORIES["videoplayer"]="smplayer vlc-luajit vlc kodi-x11 mpv totem celluloid parole"
	CATEGORIES["videostream"]="hypnotix minitube youtube-viewer clipgrab youtubedl-gui freetube-bin kodi-x11 plex-media-server plex-media-player"
	CATEGORIES["videoeditor"]="handbrake ciano kdenlive shotcut pitivi openshot vidcutter flowblade lightworks avidemux-qt blender losslesscut-bin qencoder mystiq davinci-resolve davinci-resolve-studio lightworks lives"
	CATEGORIES["imageplayer"]="gwenview eog shotwell gthumb digikam ristretto kphotoalbum phototonic viewnior"
	CATEGORIES["imageeditor"]="gimp krita inkscape pinta kolourpaint mypaint drawing scribus digikam rawtherapee fotoxx gravit-designer-bin sK1"
	CATEGORIES["dvd"]="k3b brasero dvdstyler devede xfburn acetoneiso2"
	CATEGORIES["webcam"]="obs-studio cheese kamoso simplescreenrecorder vokoscreen peek v4l-utils"
	CATEGORIES["screenshot"]="spectacle gnome-screenshot flameshot pantheon-screenshot ksnip kazam screencloud"
	CATEGORIES["imageconvert"]="converseen ciano xnconvert"
	CATEGORIES["3d"]="blender wings3d sweethome3d freecad openscad cura-bin librecad qcad godot gb-studio-bin meshroom unity-editor unreal-engine makehuman brlcad"
	CATEGORIES["gameretroarch"]="retroarch-biglinux retroarch retroarch-assets-glui retroarch-assets-ozone retroarch-assets-xmb libretro-beetle-pce libretro-beetle-pce-fast libretro-beetle-psx libretro-beetle-psx-hw libretro-beetle-supergrafx libretro-blastem libretro-bsnes libretro-bsnes-hd libretro-bsnes2014 libretro-citra libretro-core-info libretro-desmume libretro-dolphin libretro-duckstation libretro-flycast libretro-gambatte libretro-genesis-plus-gx libretro-kronos libretro-melonds libretro-mesen libretro-mesen-s libretro-mgba libretro-mupen64plus-next libretro-nestopia libretro-overlays libretro-parallel-n64 libretro-picodrive libretro-play libretro-ppsspp libretro-retrodream libretro-sameboy libretro-scummvm libretro-shaders-slang libretro-snes9x libretro-yabause"
	CATEGORIES["gameemulator"]="desmume dgen-sdl dolphin-emu dosbox dosemu fceux fs-uae fs-uae-launcher hatari higan mame mame-tools qmc2 mednafen mgba-qt mupen64plus pcsx2 ppsspp snes9x-gtk stella vbam-wx vice yabause-qt gens-gs zsnes cemu duckstation-qt-bin epsxe yuzu-mainline-bin rpcs3-bin ryujinx-ldn-bind citra-bin fightcade2 melonds nestopia flycast-git m64p openmsx"
	CATEGORIES["gamemanager"]="steam-manjaro steam-native lutris gamehub itch gnome-games heroic-games-launcher-bin"
	CATEGORIES["gamearcade"]="minetest xonotic supertux supertuxkart abuse warzone2100 warsow frozen-bubble pingus armagetronad astromenace barrage knavalbattle kspaceduel blobby blobwars fltk-examples bomber chromium-bsu cuyo endless-sky extremetuxracer gnome-nibbles gnome-robots gnujump granatier hedgewars kapman kblackbox kbounce kbreakout kgoldrunner killbots klickety kobodeluxe kolf kolision ksnakeduel lbreakout2 ltis quadrapassel sauerbraten teeworlds uqm frogatto"
	CATEGORIES["gamecard"]="kpat lskat aisleriot pysolfc"
	CATEGORIES["gamestrategy"]="0ad wesnoth konquest freeciv glob2 klines ksirk lincity-ng openra widelands"
	CATEGORIES["gamepuzzle"]="atomix puzzles kmines gnome-mines fillets-ng gnome-2048 hitori gnome-klotsky gnome-taquin gnome-tetravex kblocks kdiamond knetwalk lightsoff palapeli picmi zaz"
	CATEGORIES["gameboard"]="bovo five-or-more gnome-mahjongg iagno gnome-sudoku gnome-chess kajongg kfourinline four-in-a-row kigo kjumpingcube kmahjongg knights kshisen ksquares ksudoku pychess qgo kreversi swell-foop xboard"
	CATEGORIES["gamerpg"]="freedroidrpg manaplus megaglest naev openmw scummvm springlobby"
	CATEGORIES["gameother"]="kiriki openbve openrct2 openttd peformous simutrans tali"
	CATEGORIES["gameeducational"]="atomix blinken gbrainy gcompris-qt ktuberling kanagram katomic khangman kubrick kturtle minuet cantor kalgebra kalzium kbruch kgeography kig kiten klettres ktouch kwordquiz parley solfege step"
	CATEGORIES["gameutility"]="goverlay-bin mangohud-x11 sdl2-gamepad-mapper gamemode qt5-gamepad adriconf joyutils corectrl winetricks"
	CATEGORIES["javajar"]="jre-openjdk jre7-openjdk jre8-openjdk jre11-openjdk icedtea-web jre jre6 jre7 jre8 jre9 jre10 jre11 jre12 jre13 jre14 jre15 jre16 jre17"
	CATEGORIES["storage"]="gparted partitionmanager bleachbit gnome-dist-utility kdiskmark gsmartcontrol mintstick baobab filelight balena-etcher-appimage ventoy gnome-multi-writer"
	CATEGORIES["fonts"]="font-manager ttf-bitstream-vera ttf-caladea ttf-carlito ttf-dejavu ttf-anonymous-pro ttf-fira-code ttf-fira-mono ttf-fira-sans ttf-font-icons ttf-ibm-plex ttf-lato ttf-linux-libertine ttf-montserrat ttf-opensans ttf-roboto ttf-roboto-mono ttf-ms-fonts ttf-mac-fonts ttf-ms-win10-auto ttf-wps-fonts"
	CATEGORIES["virtualization"]="virtualbox virtualbox-guest-utils virt-manager qemu qemu-guest-agent gnome-boxes"
}

function sh_main {
	local category="$1"
	local appstream_packages
	local flatpak_packages
	local aexceptions=(network news book devwebserver gameretroarch)

	sh_cleanup
	[[ -n "$category" ]] && {
		appstream_packages="${CATEGORIES[$category]}"
		aur_packages="${CATEGORIES[$category]}"
		flatpak_packages="${CATEGORIES[$category]}"
		snap_packages="${CATEGORIES[$category]}"

		[[ -n "$appstream_packages" ]] && appstream_search_category=1 APPSTREAM_CATEGORY "$appstream_packages"
		[[ -n "$aur_packages"       ]] && aur_search_category=1       AUR_CATEGORY "$aur_packages"
		[[ -n "$flatpak_packages"   ]] && flatpak_search_category=1   FLATPAK_CATEGORY "$flatpak_packages"
		[[ -n "$snap_packages"      ]] && snap_search_category=1      SNAP_CATEGORY "$snap_packages"

#		case "$category" in
#		network | news | book | devwebserver | gameretroarch) ;;
#		*) AUR_CATEGORY ;;
#		esac
	}
}

#sh_debug
sh_config
sh_main "$category"
