{% load i18n %}
{% load common %}
{% if not team or team in stage.teams.all %}
{% if forloop.first and forloop.last %}
{% else %}
    <h3>
		{% url application.name|add:":stage" competition=competition.slug season=season.slug division=division.slug stage=stage.slug as url1 %}
		{% url application.name|add:":stage" season=season.slug division=division.slug stage=stage.slug as url2 %}
		{% url application.name|add:":stage" division=division.slug stage=stage.slug as url3 %}
        <a href="{{ url1|default:url2|default:url3 }}">{% trans stage.title %}</a>
    </h3>
{% endif %}

<table class="ladder">
	{% block thead %}
		<thead>
			<tr>
				<th class="team"></th>
				<th>{% trans "P" context "ladder: games played" %}</th>
				<th>{% trans "W" context "ladder: games won" %}</th>
				<th>{% trans "L" context "ladder: games lost" %}</th>
				<th>{% trans "D" context "ladder: games drawn" %}</th>
				<th>{% trans "B" context "ladder: byes" %}</th>
				<th>{% trans "FW" context "ladder: forfeit wins" %}</th>
				<th>{% trans "FL" context "ladder: forfeit losses" %}</th>
				<th>{% trans "+" context "ladder: points score (for)" %}</th>
				<th>{% trans "-" context "ladder: points conceded (against)" %}</th>
				<th>{% trans "+/-" context "ladder: difference (for-against)" %}</th>
				<th class="percentage">%{% trans "%" context "ladder: percentage (for/against*100)" %}</th>
				{% if stage.division.bonus_points_formula %}
					<th>{% trans "BP" context "ladder: bonus points" %}</th>
				{% endif %}
				<th>{% trans "Pts" context "ladder: points" %}</th>
			</tr>
		</thead>
	{% endblock %}

	{% block tbody %}
		<tbody>
			{% for ladder in pools %}
				<tr class="{% if forloop.first %}first {% endif %}{% cycle "odd" "even" %}{% if forloop.last %} last{% endif %}{% if team == ladder.team %} current{% endif %}">
					<td class="team {{ ladder.team.club.slug|cssify }}">
						{% url application.name|add:":team" competition=competition.slug season=season.slug division=division.slug team=ladder.team.slug as url1 %}
						{% url application.name|add:":team" season=season.slug division=division.slug team=ladder.team.slug as url2 %}
						{% url application.name|add:":team" division=division.slug team=ladder.team.slug as url3 %}
						<a href="">{% trans ladder.team.title %}</a>
					</td>
					<td>{{ ladder.played }}</td>
					<td>{{ ladder.win }}</td>
					<td>{{ ladder.loss }}</td>
					<td>{{ ladder.draw }}</td>
					<td>{{ ladder.bye }}</td>
					<td>{{ ladder.forfeit_for }}</td>
					<td>{{ ladder.forfeit_against }}</td>
					<td>{{ ladder.score_for }}</td>
					<td>{{ ladder.score_against }}</td>
					<td>{{ ladder.difference|stringformat:"g" }}</td>
					<td class="percentage">{{ ladder.percentage|stringformat:"g"|default:"&#8734;" }}</td>
					{% if stage.division.bonus_points_formula %}
						<td>{{ ladder.bonus_points }}</td>
					{% endif %}
					<td>{{ ladder.points|stringformat:"g" }}</td>
				</tr>
			{% endfor %}
		</tbody>
    {% endblock %}
</table>
{% endif %}
