@using MileageTraker.Web.ViewModels.FuelLog
@model MatchViewModel

@{
    ViewBag.Title = "Match Fuel Log";
	var fuelLog = Model.FuelLog;
	var matchedLogs = Model.MatchedLogs;
	var currentlyMatchedLog = Model.CurrentlyMatchedLog;
	var logViewModel = fuelLog.GetLogViewModel();
}

@Html.Partial("_StatusMessage")

<h2><i class="fa fa-tachometer"></i> @ViewBag.Title</h2>
	
<h4>Fuel Log</h4>

<table id="fuellog" class="table table-striped table-bordered table-hover table-condensed">
	<thead>
		<tr>
			<th>Date</th>
			<th>Driver</th>
			<th>Tag Number</th>
			<th>Odometer</th>
			<th>Gas Purchased</th>
			<th></th>
		</tr>
	</thead>
	<tbody>
		<tr>
			<td>@Html.ValueFor(x => fuelLog.Date, "{0:d}")</td>
			<td>@Html.ValueFor(x => fuelLog.DriverFullName)</td>
			<td>@Html.ValueFor(x => fuelLog.TagNumber) @if(string.IsNullOrEmpty(fuelLog.VehicleId)) { <span class="label label-warning"><i class="icon-warning-sign warning"></i> No Matching Vehicle</span>} </td>
			<td>@Html.ValueFor(x => fuelLog.Odometer)</td>
			<td>@Html.ValueFor(x => fuelLog.GasPurchased, "{0:0.000}")</td>
			<td></td>
		</tr>
	</tbody>
</table>


<h4>Currently Matched Mileage Log</h4>

<table id="currentlymatchedlog" class="table table-striped table-bordered table-hover table-condensed">
	<thead>
		<tr>
			<th>Date</th>
			<th>Driver</th>
			<th>Tag Number</th>
			<th>Odometer</th>
			<th>Gas Purchased</th>
			<th></th>
		</tr>
	</thead>
	<tbody>
		@if (currentlyMatchedLog == null) {
			<tr><td colspan="6"><span class="label label-important">Not Currently Matched</span></td></tr>
		}
		else {
			<tr>
				<td class="@if (!currentlyMatchedLog.DateMatch)
					        {<text>nomatch</text>}else{<text>match</text>}">@Html.ValueFor(x => currentlyMatchedLog.Date, "{0:d}")</td>
				<td class="@if (!currentlyMatchedLog.UserFullNameMatch)
					        {<text>nomatch</text>}else{<text>match</text>}">@Html.ValueFor(x => currentlyMatchedLog.UserFullName)</td>
				<td class="@if (!currentlyMatchedLog.VehicleTagMatch)
					        {<text>nomatch</text>}else{<text>match</text>}">@Html.ValueFor(x => currentlyMatchedLog.VehicleTagNumber)</td>
				<td class="@if (!currentlyMatchedLog.OdometerMatch)
					        {<text>nomatch</text>}else{<text>match</text>}">@Html.ValueFor(x => currentlyMatchedLog.EndOdometer)</td>
				<td class="@if (!currentlyMatchedLog.GasPurchasedMatch)
					        {<text>nomatch</text>}else{<text>match</text>}">@Html.ValueFor(x => currentlyMatchedLog.GasPurchased, "{0:0.000}")</td>
				<td>@Html.ActionLink("Details", "Details", "Log", new { id = currentlyMatchedLog.LogId }, new { @class = "btn btn-mini", target="_blank" })</td>
			</tr>
			}
	</tbody>
</table>
<hr/>
<h4>Similiar Mileage Log entries</h4>

<table id="matchedlogs" class="table table-striped table-bordered table-hover table-condensed">
	<thead>
		<tr>
			<th>Date</th>
			<th>Driver</th>
			<th>Tag Number</th>
			<th>Odometer</th>
			<th>Gas Purchased</th>
			<th>Match</th>
		</tr>
	</thead>
	<tbody>
		@if (!matchedLogs.Any())
		{
			<tr>
				<td colspan="6"><span class="label @if (currentlyMatchedLog == null){<text>label-important</text>}">No Results</span></td>
			</tr>
		}
		else {
			foreach (var matchedLog in matchedLogs)
			{
				<tr>
					<td class="@if (!matchedLog.DateMatch)
								{<text>nomatch</text>}else{<text>match</text>}">@Html.ValueFor(x => matchedLog.Date, "{0:d}")</td>
					<td class="@if (!matchedLog.UserFullNameMatch)
								{<text>nomatch</text>}else{<text>match</text>}">@Html.ValueFor(x => matchedLog.UserFullName)</td>
					<td class="@if (!matchedLog.VehicleTagMatch)
								{<text>nomatch</text>}else{<text>match</text>}">@Html.ValueFor(x => matchedLog.VehicleTagNumber)</td>
					<td class="@if (!matchedLog.OdometerMatch)
								{<text>nomatch</text>}else{<text>match</text>}">@Html.ValueFor(x => matchedLog.EndOdometer)</td>
					<td class="@if (!matchedLog.GasPurchasedMatch)
								{<text>nomatch</text>}else{<text>match</text>}">@Html.ValueFor(x => matchedLog.GasPurchased, "{0:0.000}")</td>
					<td>@using (Html.BeginForm("Match", "FuelLog", FormMethod.Post))
						{
							<input type="hidden" name="fuelLogId" value="@fuelLog.FuelLogId"/>
							<input type="hidden" name="logId" value="@matchedLog.LogId"/>
							<input type="submit" class="btn btn-mini" value="Match"/>
						}
					</td>
				</tr>
			}
		}
	</tbody>
</table>
@Html.Partial("MatchLogViewModelPartial", logViewModel)
