#!/bin/bash

toolsMenu()
{
	# Enable input
	stty echo
	
	while true; do
		isHeader "Tools Menu"
		isOption "1. Menu - Docker"
		isOption "2. Menu - Crontab"
		# Only show Git reset option if not a local installation
		if [[ "$CFG_INSTALL_MODE" != "local" ]]; then
			isOption "3. Tool - Reset LibrePortal Git Folder"
			isOption "4. Tool - Force Pre-Installation"
			isOption "x. Exit to Main Menu"
		else
			isOption "3. Tool - Force Pre-Installation"
			isOption "x. Exit to Main Menu"
		fi
		echo ""
		isQuestion "What is your choice: "
		read -rp "" tools_menu_choice

		case $tools_menu_choice in
			1)
				dockerToolsMenu;
				;;
			2)
				crontabToolsMenu;
				;;
			3)
				# Handle different option numbers based on installation mode
				if [[ "$CFG_INSTALL_MODE" != "local" ]]; then
					toolsresetgit=y
					startOther;
				else
					toolstartpreinstallation=y
					startOther;
				fi
				;;
			4)
				# Only show this option if not local installation
				if [[ "$CFG_INSTALL_MODE" != "local" ]]; then
					toolstartpreinstallation=y
					startOther;
				else
					# For local installation, option 4 doesn't exist
					isNotice "Invalid choice. Please select a valid option."
				fi
				;;
			x)
				endStart;

				;;
			*)
				isNotice "Invalid choice. Please select a valid option."
				;;
		esac
	done
}
