# -*-perl-*-
# keitairc/lib/plugins/00index
# `lꗗ
# $Id: 00index,v 1.1 2008/01/09 19:30:34 morimoto Exp $
# $Source: /cvsroot/keitairc/lib/plugins/00index,v $

$plugin = {
	name => 'index',
	action_imprementation => sub {
		my ($request, $name, $session_id, $param_string) = @_;
		my $unread_channels = 0;
		my $accesskey = 1;
		my $buf;

		for my $channel ($::ib->channels()){
			if($accesskey < 10){
				$buf .= sprintf('<a accesskey="%1d" href="all/%s">[%1d] %s</a>',
						$accesskey,
						::uri_escape($channel),
						$accesskey,
						$::ib->compact_channel_name($::ib->name($channel)));
			}else{
				$buf .= sprintf('<a href="all/%s">    %s</a>',
						::uri_escape($channel),
						$::ib->compact_channel_name($::ib->name($channel)));
			}
			$accesskey++;

			# Ǎs
			if($::ib->unread_lines($channel)){
				$buf .= sprintf(' <a href="unread/%s">%s</a>',
						::uri_escape($channel),
						$::ib->unread_lines($channel));
				$unread_channels++;
			}
			$buf .= "<br />\n";
		}

		my $ci = new Keitairc::ClientInfo($request);
		my $view = new Keitairc::View($::cf, $ci);
		return $view->render('index.html',
				     {
					     buf => $buf,
					     unread => $unread_channels,
				     });
	}
};

1;
