package Gruntmaster::Page::Pb;

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

use constant TEMPLATES => {
	en => <<'HTML',
<tmpl_if levels>
<h2>Beginner</h2>
<div class="list-group">
<tmpl_loop beginner><a class="list-group-item" href="<tmpl_var id>"><tmpl_var name></a>
</tmpl_loop></div>

<h2>Easy</h2>
<div class="list-group">
<tmpl_loop easy><a class="list-group-item" href="<tmpl_var id>"><tmpl_var name></a>
</tmpl_loop></div>

<h2>Medium</h2>
<div class="list-group">
<tmpl_loop medium><a class="list-group-item" href="<tmpl_var id>"><tmpl_var name></a>
</tmpl_loop></div>

<h2>Hard</h2>
<div class="list-group">
<tmpl_loop hard><a class="list-group-item" href="<tmpl_var id>"><tmpl_var name></a>
</tmpl_loop></div>

<tmpl_else>
<div class="list-group">
<tmpl_loop problems><a class="list-group-item" href="<tmpl_var id>"><tmpl_var name></a>
</tmpl_loop></div>
</tmpl_if>
HTML
};

sub _generate{
	my ($self, $htc, $lang, $logger, $ct) = @_;
	debug $logger => "language is '$lang' and contest is '$ct'";
	local $Gruntmaster::Data::contest = $ct if $ct;

	my @problems = sort { $b->{name} cmp $a->{name} } map +{
		id    => $_,
		name  => problem_name,
		level => problem_level}, problems;

	for my $d (qw/beginner easy medium advanced hard/) {
		$htc->param($d => [grep {$_->{level} and $_->{level} eq $d} @problems]);
	}
	$htc->param(levels => grep { $_->{level} } @problems);
	$htc->param(problems => \@problems);
}

1
