{% extends "tournamentcontrol/competition/base.html" %}
{% load i18n tz %}
{% load common %}

{% block page_title %}{% trans competition.title %} - {% trans season.title %} - {% trans division.title %}{% endblock %}

{% block content %}
	{% trans "TBA" as tba context "abbreviation: to be advised" %}
	{% trans "TBC" as tbc context "abbreviation: to be confirmed" %}

	{% block calendar %}
		{% url application.name|add:":calendar" competition=competition.slug season=season.slug division=division.slug as url1 %}
		{% url application.name|add:":calendar" season=season.slug division=division.slug as url2 %}
		{% url application.name|add:":calendar" division=division.slug as url3 %}
		<a class="calendar" title="Calendar"{% if debug %} target="_blank"{% endif %} href="{% if not debug %}webcal:{% endif %}//{{ request.get_host }}{{ url1|default:url2|default:url3 }}">&#128197;</a>
	{% endblock %}

	{% block heading %}
		<h1>{% trans competition.title %} - {% trans season.title %}</h1>
		<h2>{% trans division.title %}</h2>
	{% endblock %}

	{% for stage, pools in parent.ladders.items %}
		{% if pools %}
			<div id="stage_{{ stage.pk }}" class="stage">
				{% if stage.pool_count %}
					{% include "tournamentcontrol/competition/ladder/pool.html" %}
				{% else %}
					{% include "tournamentcontrol/competition/ladder/standard.html" %}
				{% endif %}
			</div>
		{% endif %}
	{% endfor %}

	{% for current_stage, dates in parent.matches_by_date.items %}
		{% if not stage %}
			{% url application.name|add:":stage" competition=competition.slug season=season.slug division=division.slug stage=current_stage.slug as url1 %}
			{% url application.name|add:":stage" season=season.slug division=division.slug stage=current_stage.slug as url2 %}
			{% url application.name|add:":stage" division=division.slug stage=current_stage.slug as url3 %}
			<h3><a href="{{ url1|default:url2|default:url3 }}">{% trans current_stage.title %}</a></h3>
		{% endif %}

		{% for date, matches in dates.items %}
			{% if matches %}
				{% ifchanged date %}
					<h4>{{ date|default_if_none:tbc }}</h4>
				{% endifchanged %}

				<table class="draw">
					<tbody>
						{% for match in matches %}
							<tr class="{% if forloop.first %}first {% endif %}{% cycle "odd" "even" %}{% if forloop.last %} last{% endif %}{% ifchanged match.round %} group{% endifchanged %}">
								<td class="label">
									{% ifchanged %}
										{% if match.label %}
											{% trans match.label %}
										{% else %}
											{% if not match.is_final %}
												{% blocktrans with num=match.round|default:forloop.parentloop.counter %}Round {{ num }}{% endblocktrans %}
											{% endif %}
										{% endif %}
									{% endifchanged %}
								</td>
								{% if match.is_bye %}
									<td></td>
									<td></td>
								{% else %}
									{% if not match.is_forfeit %}
										<td class="time">{{ match.datetime|date:"G:i"|default:tba }}</td>
										<td class="field">{{ match.play_at.title|default:tba }}</td>
									{% else %}
										<td class="forfeit" colspan="2">{% trans "Forfeit" %}</td>
									{% endif %}
								{% endif %}

								<td class="team right {{ match.home_team.club.slug|cssify }}">
									{% if match.home_team %}
										{% url application.name|add:":team" competition=competition.slug season=season.slug division=division.slug team=match.home_team.slug as url1 %}
										{% url application.name|add:":team" season=season.slug division=division.slug team=match.home_team.slug as url2 %}
										{% url application.name|add:":team" division=division.slug team=match.home_team.slug as url3 %}
										<a href="{{ url1|default:url2|default:url3 }}">{% trans match.home_team.title %}</a>
									{% else %}
										{% trans match.get_home_team.title %}
									{% endif %}
								</td>

								<td class="score center">{{ match.home_team_score|default_if_none:"-" }}</td>
								<td class="versus center">{% trans "vs" context "abbreviation: versus" %}</td>
								<td class="score center">{{ match.away_team_score|default_if_none:"-" }}</td>

								<td class="team {{ match.away_team.club.slug|cssify }}">
									{% if match.away_team %}
										{% url application.name|add:":team" competition=competition.slug season=season.slug division=division.slug team=match.away_team.slug as url1 %}
										{% url application.name|add:":team" season=season.slug division=division.slug team=match.away_team.slug as url2 %}
										{% url application.name|add:":team" division=division.slug team=match.away_team.slug as url3 %}
										<a href="{{ url1|default:url2|default:url3 }}">{% trans match.away_team.title %}</a>
									{% else %}
										{% trans match.get_away_team.title %}
									{% endif %}
								</td>

								<td class="report{% if not match.statistics_count %} none{% endif %}">
									{% url application.name|add:":match" competition=competition.slug season=season.slug division=division.slug match=match.pk as url1 %}
									{% url application.name|add:":match" season=season.slug division=division.slug match=match.pk as url2 %}
									{% url application.name|add:":match" division=division.slug match=match.pk as url3 %}
									<a href="{{ url1|default:url2|default:url3 }}">{% trans "Detail" %}</a>
								</td>
							</tr>
						{% endfor %}
					</tbody>
				</table>
			{% endif %}
		{% endfor %}
	{% endfor %}
{% endblock %}
