# Plain Theme for MJ's Photo Gallery
# (c) 2012 Martin Mares <mj@ucw.cz>; GPL'ed

package UCW::Gallery::Web::Plain;

use common::sense;

use UCW::Gallery;
use UCW::Gallery::Web;

our @ISA = qw(UCW::Gallery::Web);

my $theme_name = "plain";
my $navw = 48;
my $navh = 48;
my $box_w = 130;
my $box_h = 110;

sub theme_dir($) {
	my ($self) = @_;
	return $self->get('ThemeUrlPrefix') . $theme_name;
}

sub theme_head_extras($) {
	my ($self) = @_;
	my $stylesheet = $self->theme_dir . "/style.css";
	return "<link rel=stylesheet href='$stylesheet' type='text/css' media=all>\n";
}

sub show_links($$$$) {
	my ($self, $prev, $up, $next) = @_;
	my $theme = $self->theme_dir;
	print "<p class=parent>";
	print "<span class=back style='width: ${navw}px; height: ${navh}px'>";
	print "<a href='$prev'><img src='$theme/prev.png' width=${navw} height=${navh} alt='Back'></a>" if $prev ne "";
	print "</span>\n";
	printf "<span class=fwd style='width: ${navw}px; height: ${navh}px'>";
	printf "<a href='$next'><img src='$theme/next.png' width=${navw} height=${navh} alt='Forward'></a>" if $next ne "";
	print "</span>\n";
	printf "<a href='$up'><img src='$theme/back.png' width=${navw} height=${navh} alt='Up'></a>" if $up ne "";
}

sub show_thumb($) {
	my ($self, $meta, $photo_id, $click_url) = @_;
	my $theme = $self->theme_dir;
	my $m = $meta->{photo}->{$photo_id};
	my $annot = UCW::CGI::html_escape($m->{title});
	my $tf = $self->get('ThumbFormats')->[0];
	my ($thumb_w, $thumb_h) = $self->{gal}->thumb_fmt_to_size($tf);
	my $tm = $meta->{thumb}->{$tf}->{$photo_id} or die "No thumbnails for format $tf found!\n";
	my $tw = $tm->{w};
	my $th = $tm->{h};
	my $thumb = $self->get('ThumbUrlPrefix') . "$tf/$photo_id.jpg";
	print "<div class=thf><div class=thumb>\n";
	my $ol = int(($box_w - $tw)/2);
	my $ot = int(($box_h - $th)/2);
	my $tit = ($annot ne "") ? " title=\"$annot\"" : "";
	print "<a href='$click_url'><img src='$thumb' width=$tw height=$th alt='Photo'$tit class=ti style='left: ${ol}px; top: ${ot}px'></a>\n";
	print "</div></div>\n\n";
}

sub run($$) {
	my ($class, $gal) = @_;
	my $self = $class->SUPER::attach($gal);
	$self->dispatch();
	return $self;
}

1;
