#!/bin/bash
# info: list web statistics
# options: [FORMAT]
# labels: web panel
#
# example: v-list-web-stats
#
# This function for obtaining the list of web statistics analyzer.

#----------------------------------------------------------#
#                Variables & Functions                     #
#----------------------------------------------------------#

# Argument definition
format=${1-shell}

# Includes
# shellcheck source=/etc/hestiacp/hestia.conf
source /etc/hestiacp/hestia.conf
# shellcheck source=/usr/local/hestia/func/main.sh
source $HESTIA/func/main.sh
# load config file
source_conf "$HESTIA/conf/hestia.conf"

# JSON list function
json_list() {
	objects=$(echo "$stats" | wc -w)
	i=1
	echo '['
	for str in $stats; do
		if [ "$i" -lt "$objects" ]; then
			echo -e "\t\"$str\","
		else
			echo -e "\t\"$str\""
		fi
		((++i))
	done
	echo "]"
}

# SHELL list function
shell_list() {
	echo "PARSER"
	echo "------"
	for parser in $stats; do
		echo "$parser"
	done
}

# PLAIN list function
plain_list() {
	for parser in $stats; do
		echo "$parser"
	done
}

# CSV list function
csv_list() {
	echo "PARSER"
	for parser in $stats; do
		echo "$parser"
	done
}

#----------------------------------------------------------#
#                       Action                             #
#----------------------------------------------------------#

# Parsing stats system
stats=$(echo "none ${STATS_SYSTEM//,/ }")

# Listing data
case $format in
	json) json_list ;;
	plain) plain_list ;;
	csv) csv_list ;;
	shell) shell_list ;;
esac

#----------------------------------------------------------#
#                       Hestia                             #
#----------------------------------------------------------#

exit
