@using MileageTraker.Web.Utility
@model MileageTraker.Web.ViewModels.FuelLog.FuelLogResultsViewModel

@{
    ViewBag.Title = "Fuel Logs";
    var grid = new WebGrid(Model.FuelLogs, rowsPerPage: 45);
	var parameters = new {FiscalYear = Model.FiscalYear, Model.Month, Model.Unmatched};
}
@section Styles {
    <link href="@Url.Content("~/Content/VehicleColors.css")" rel="stylesheet" type="text/css" />
}
@section Scripts {
	<script type="text/javascript">
		var availableLogYearMonths = @Html.Raw(Json.Encode(Model.AvailableYearMonths));
		@if (Model.FiscalYear != null)
		{
			<text>var selectedYear = "@Model.FiscalYear";</text>
			<text>var selectedMonth = "@Model.Month";</text>
		}
	</script>
}

@Html.Partial("_StatusMessage")

<div class="btn-toolbar pull-right" style="width:400px">
	@using (Html.BeginForm("Index", "FuelLog", FormMethod.Get, new { id = "filter", @class = "form" }))
	{
			@Html.EditorForModel()
	}
</div>

<h2 id="fuellog-title"><i class="fa fa-tachometer"></i> @ViewBag.Title</h2>

<div class="btn-toolbar clearfix">
	@Html.ActionLink("Import", "ImportUpload", null, new { @class = "btn" })
	@Html.ActionLink("Export", "Export", parameters, new { @class = "btn" })
</div>

<div>
@grid.GetHtml(columns:
    grid.Columns(
            grid.Column("Date", format: item => item.Date.ToString("d")),
            grid.Column("DriverFullName", "Driver Name"),
            grid.Column("TagNumber", "Tag Number"),
            grid.Column("Odometer"),
            grid.Column("MPG"),
            grid.Column("GasPurchased", "Gas Purchased", @<text>@String.Format("{0:0.000}", item.GasPurchased)</text>),
            grid.Column("TotalPrice", "Total Price", @<text>@String.Format("{0:C}", item.TotalPrice)</text>),
			grid.Column("Log", "Matched Log", @<text>
					            @(item.LogId != null 
								? Html.ActionLink("View Match", "Match", new {id = item.FuelLogId}, new {@class = "btn btn-mini", target="_blank"})
								: Html.ActionLink("Match", "Match", new {id = item.FuelLogId}, new {@class = "btn btn-warning btn-mini", target="_blank"}))
				            </text>)), 
			htmlAttributes: new { @class = "table table-striped table-bordered table-hover table-condensed"},
        numericLinksCount: 20
	 )
	<div class="center-content webgrid-footer">
		Total Results: @Model.FuelLogs.Count()
	</div>
</div>
@if (!Model.FuelLogs.Any())
{
	<div>
		No results.
	</div>
}