{% extends "admin/base.html" %}

{% block stylesheets %}
{% endblock %}

{% block content %}
<div class="jumbotron">
	<div class="container">
		<h1>Teams
			<span class="create-team" role="button" data-toggle="tooltip" title="Create Team">
				<a href="{{ url_for('admin.teams_new') }}" style="color: inherit;">
					<i class="btn-fa fas fa-plus-circle"></i>
				</a>
			</span>
		</h1>
	</div>
</div>

<div class="container">
	<div class="row">
		<div class="col-md-12">
			{% if q and field%}
			<h4 class="text-center">Searching for teams with {{field}} matching {{q}}</h4>
			{% endif %}

			<form method="GET" class="form-inline">
					<div class="form-group col-md-2">
						<label for="sel1" class="sr-only" >Search Field</label>
						<select class="form-control custom-select w-100" id="sel1" name="field">
							<option value="name" {% if field == 'name' %}selected{% endif %}>Name</option>
							<option value="id" {% if field == 'id' %}selected{% endif %}>ID</option>
							<option value="email" {% if field == 'email' %}selected{% endif %}>Email</option>
							<option value="affiliation" {% if field == 'affiliation' %}selected{% endif %}>Affiliation</option>
					  </select>
					</div>
					<div class="form-group col-md-8">
						<label for="team-name-search" class="sr-only">Parameter</label>
						<input type="text" class="form-control w-100" id="team-name-search" name="q" placeholder="Search for matching team names" {% if q %}value="{{q}}"{% endif %}>
					</div>
					<div class="form-group col-md-2">
						<label for="team-name-search" class="sr-only">Search</label>
						<button type="submit" class="btn btn-primary w-100"><i class="fas fa-search" aria-hidden="true"></i></button>
					</div>
			</form>

			<br>

			<table id="teamsboard" class="table table-striped">
				<thead>
					<tr>
						<td width="10px" class="text-center"><b>ID</b>
						</td>
						<td class="text-left"><b>Team</b>
						</td>
						<td class="text-center"><b>Website</b>
						</td>
						<td class="text-center"><b>Country</b>
						</td>
						<td class="text-center"><b>Hidden</b>
						</td>
						<td class="text-center"><b>Banned</b>
						</td>
					</tr>
				</thead>
				<tbody>
					{% for team in teams %}
					<tr name="{{ team.id }}" data-href="{{ url_for('admin.teams_detail', team_id=team.id) }}">
						<td class="team-id" value="{{ team.id }}">{{ team.id }}</td>
						<td class="team-name" value="{{ team.name }}">
							<a href="{{ url_for('admin.teams_detail', team_id=team.id) }}">
								{{ team.name | truncate(32) }}
							</a>
							{% if team.oauth_id %}
								<a href="https://majorleaguecyber.org/t/{{ team.name }}">
									<span class="badge badge-primary">Official</span>
								</a>
							{% endif %}
							<span class="d-block text-muted">
								<small>
									{% if team.affiliation %}
										{{ team.affiliation | truncate(20) }}
									{% endif %}
								</small>
							</span>
						</td>

						<td class="team-website text-center">
							{% if team.website %}
								<a href="{{ team.website }}" target="_blank">
									<i class="btn-fa fas fa-external-link-alt" data-toggle="tooltip" data-placement="top"
									   title="{{ team.website }}" aria-hidden="true"></i>
								</a>
							{% endif %}
						</td>
						<td class="team-country text-center" value="{{ team.country if team.country is not none }}">
							<span>
								{% if team.country %}
									<i class="flag-{{ team.country.lower() }}"></i>
									{{ lookup_country_code(team.country) }}
								{% endif %}
							</span>
						</td>

						<td class="team-hidden d-md-table-cell d-lg-table-cell text-center" value="{{ team.hidden }}">
							{% if team.hidden %}
								<span class="badge badge-danger">hidden</span>
							{% endif %}
						</td>

						<td class="team-banned d-md-table-cell d-lg-table-cell text-center" value="{{ team.banned }}">
							{% if team.banned %}
								<span class="badge badge-danger">banned</span>
							{% endif %}
						</td>
					</tr>
					{% endfor %}
				</tbody>
			</table>
			{% if pages > 1 %}
			<div class="text-center">Page
				<br>
				{% if curr_page != 1 %}<a href="{{ url_for('admin.teams_listing', page=curr_page - 1) }}">&lt;&lt;&lt;</a>{% endif %}
				{% for page in range(1, pages + 1) %}
					{% if curr_page != page %}
						<a href="{{ url_for('admin.teams_listing', page=page) }}">{{ page }}</a>
					{% else %}
						<b>{{ page }}</b>
					{% endif %}
				{% endfor %}
				{% if curr_page != pages %}<a href="{{ url_for('admin.teams_listing', page=curr_page + 1) }}">&gt;&gt;&gt;</a>{% endif %}
			</div>
			{% endif %}
		</div>
	</div>
</div>
{% endblock %}

{% block scripts %}
{% endblock %}
