@using Core.Entities
@model Tuple<Team[]>
@{
	ViewData["Title"] = "Teams";
}

<table>
	@foreach (var team in Model.Item1.Where(t => t.Event.Documentation.Contains("Port")))
	{
		<tr>
			<td>@team.Name @if (team.Event.Format is EventFormat.Individual)
				{
					<text>(ind)</text>
				}
			</td><td>@team.Event.Documentation</td>
			@foreach(var student in @team.Students.OrderByDescending(s => s.TsaYear + s.Grade))
			{
				<td>@student.FirstName</td>
			}
		</tr>
	}
	@foreach (var student in Model.Item1.SelectMany(t => t.Students).Distinct().Where(s => s.Teams.Any(t => t.Event.Name.Contains("Port"))))
	{
		<tr>
			<td>@student.FirstName</td>
		</tr>
	}
</table>

<table class="table-primary">
	<thead>
	<tr><td>Teams</td></tr>
	</thead>
	@{
		var ind = false;
	}
	@foreach (var team in Model.Item1.OrderByDescending(t => t.Event.Format is EventFormat.Team))
	{
		@if (!ind && team.Event.Format is EventFormat.Individual)
		{
			<tr>
				<td><hr/></td><td>Individual</td><td><hr/></td>
			</tr>
			ind = true;
		}
		<tr class="table-primary">
			<td class="table-primary"><strong>@team.Name</strong></td>
			<td colspan="1">
				@* @Html.Partial("EffortStarsPartial", team.Event.LevelOfEffort) *@
		@* 		@if (team.Event.RegionalEvent)
				{
					<text>(reg)</text>
				}

				@if (team.Event.OnSiteActivity)
				{
					<text>(act)</text>
				} *@
				@team.Event.TeamSize
			</td>
			@*<td style="nowrap">@evt.MaxTeamCountState</td>*@
			@foreach (var student in team.Students.OrderByDescending(s => (s.Grade + s.TsaYear) * (team.Captain == s ? 2 : 1)).ThenBy(s => s.FirstNameLastName))
			{
				<td>@student.FirstName @if (team.Captain == student) { <text>(Cpt.)</text>}</td>
			}
		</tr>
	}
</table>
@* 

<table class="table">
	<thead>
	<tr>
		<td>Event</td>
		<td>Pre-submission</td>
		<td>RegionalNotes</td>
		<td>Team Members</td>
		</tr>
	</thead>
	@foreach (var team in Model.Item1)
	{
		var students = team.Students;
		<tr>
			<td>
				@team.Name
			</td>

		</tr>

		 @foreach (var student in students.OrderByDescending(s => (s.Grade + s.TsaYear) * (team.Captain == s ? 2 : 1)).ThenBy(s => s.FirstNameLastName))
		{
			<td>@student.FirstNameLastName @if (team.Captain == student) { <text>(Cpt.)</text>}</td>
		}
		
 		<tr>
			<td class="event-desc" colspan="4">Team Size: @team.Event.TeamSize, Max Teams: @team.Event.MaxTeamCountState
				@{
	                 if (!team.Event.InterviewOrPresentation)
	                 {
	                     <span class="activity"> (a)</span>
	                 }
	                 if (team.Event.Format is EventFormat.Individual)
	                 {
	                     <span class="activity"> (i)</span>
	                 }
				}
				</td>
		</tr> 
	}
</table>
<p>
	(a) denotes an event that has activity other than interview or presentation at state
	<br />
	(i) denotes an individual event
</p>
 *@

@functions
{
	public void GetOrderClass(int pick)
	{
		@Html.Raw(LabelHelper.GetOrderClass(pick))
	}

	private void GetTeamClass(Team team)
	{
		// if (team.Event.RegionalEvent)
		// {
		// 	@Html.Raw("regional");
		// }
	}
}