#!/bin/sh

#turn off auto expansion
set -f

_()
{
LANG=${in_language%%;*}.utf8 gettext "alterator-lightsquid" "$1"
}


. /usr/share/alterator/build/backend3.sh

on_message()
{
	case "$in_action" in
		#information for renderer
		template)
			echo '('
			echo 'template "form"'
			ip="${in__objects#*/*/}"
			if [ "$ip" = "$in__objects" ]; then
				echo 'url "lightsquid.html"'
				ip=
			else
				echo 'url "lightsquid-sites.html"'
			fi
			echo 'help "lightsquid.html"'
			if [ -n "$in_select" ]; then
				[ -n "$in_from" ] || in_from=-1
				[ -n "$in_to" ] || in_to=-1
				printf ' redirect "/lightsquid/%s/%s/%s"' "$in_from" "$in_to" "$ip"
			fi
			echo ')'
			;;
		info)
			echo '('
			printf ' title "%s"' "$(_ "Proxy server")"
			printf ' description "%s"' "$(_ "Proxy server statistics")"
			echo ')'
			;;
		*)
			echo '#f'
			;;
	esac
}

message_loop
