#!/mod/bin/jimsh

package require cgi
source /mod/webif/lib/setup
require tvdb.class

set term [cgi_get term -]
if {$term eq "-"} exit

httpheader

set slist [[tvdb] searchseries $term]
if {[llength $slist]} {
	foreach series $slist {
	puts "
<div>
	<div class=tvdbseries>
		<a target=_blank href=[tvdb seriesurl $series(seriesid)]>
	"
	if {[dict exists $series banner]} {
		puts "
		<img class=tvdbbanner src=\"[tvdb bannerurl $series(banner)]\">
		"
	} else {
		puts "View on TheTVDB"
	}
	puts "
		</a>
		<span title=\"Series ID: $series(seriesid)\">
			$series(seriesname)
		</span>
		<button class=tvdbselect sid=\"$series(seriesid)\">
			Select
		</button>
	</div>
	<div class=tvdbsynopsis>
	"
	if {[dict exists $series overview]} {
		puts $series(overview)
	}
	puts "
	</div>
</div>
	"
	}
} else {
	puts "No matches found."
}

