@using System.Globalization
@using MileageTraker.Web.Models
@model IEnumerable<Tuple<Log, Log>> 

<div class="report-calculation">
	<table class="table">
		<thead><tr><th>Date</th><th>City</th><th>End ODO</th><th>Start ODO</th><th>Miles</th></tr></thead>
		@foreach (var log in Model)
		{
			<tr>
				<td>
					@Html.Encode(log.Item2.Date.ToShortDateString())
				</td>
				<td>
					@Html.Encode(log.Item2.CityName)
				</td>
				<td>
					@Html.ActionLink(log.Item2.EndOdometer.ToString(CultureInfo.InvariantCulture), "Details", "Log", new {id = log.Item2.LogId}, null)
				</td>
                    
				@if (log.Item1 != null)
				{
					<td>
						@Html.ActionLink(log.Item1.EndOdometer.ToString(CultureInfo.InvariantCulture), "Details", "Log", new {id = log.Item1.LogId}, null)
					</td>
					<td>
						@(log.Item2.EndOdometer - log.Item1.EndOdometer)
					</td>
				}
				else
				{
					<td colspan="2">
						<span class="label label-warning">?</span>
					</td>
				}
			</tr>
		}
		<tfoot>
			<tr>
				<td colspan="4">
					Total:</td>
				<td>
					@Model.Sum(log => log.Item1 != null ? log.Item2.EndOdometer - log.Item1.EndOdometer : 0)
				</td>
			</tr>
		</tfoot>
	</table>
</div>