package Gruntmaster::Page::Ct;

use 5.014000;
use strict;
use warnings;
use Gruntmaster::Page::Base ct => 'Contests';
our @ISA = qw/Gruntmaster::Page::Base/;
our $VERSION = '0.001';

use constant TEMPLATES => {
	en => <<'HTML',
<tmpl_if running>
<h1>Running contests</h1>
<table border>
<thead>
<tr><th>Name<th>Start date<th>End date<th>Owner
<tbody>
<tmpl_loop running><tr><td><a href="<tmpl_var id>"><tmpl_var name></a>
<td><tmpl_var start>
<td><tmpl_var end>
<td><tmpl_var owner>
</tmpl_loop>
</table>
</tmpl_if>

<tmpl_if pending>
<h1>Pending contests</h1>
<table border>
<thead>
<tr><th>Name<th>Start date<th>End date<th>Owner
<tbody>
<tmpl_loop pending><tr><td><a href="<tmpl_var id>"><tmpl_var name></a>
<td><tmpl_var start>
<td><tmpl_var end>
<td><tmpl_var owner>
</tmpl_loop>
</table>
</tmpl_if>

<tmpl_if finished>
<h1>Finished contests</h1>
<table border>
<thead>
<tr><th>Name<th>Start date<th>End date<th>Owner
<tbody>
<tmpl_loop finished><tr><td><a href="<tmpl_var id>"><tmpl_var name></a>
<td><tmpl_var start>
<td><tmpl_var end>
<td><tmpl_var owner>
</tmpl_loop>
</table>
</tmpl_if>
HTML
};

sub _generate{
	my ($self, $htc, $path, $lang) = @_;

	my (@running, @pending, @finished);
	for (contests) {
		my $ct = { id => $_,
				   name => contest_name,
				   start => strftime ('%c', localtime contest_start),
				   end => strftime ('%c', localtime contest_end),
				   owner => contest_owner };

		my $time = time;
		push @pending, $ct if time < contest_start;
		push @running, $ct if time >= contest_start && time < contest_end;
		push @finished, $ct if time > contest_end;
	}

	$htc->param(running => \@running) if @running;
	$htc->param(pending => \@pending) if @pending;
	$htc->param(finished => \@finished) if @finished;
}

1
