@model MileageTraker.Web.ViewModels.VehicleService.VehicleServiceResultsViewModel

@{
	ViewBag.Title = "Vehicle Service";
	var grid = new WebGrid(Model.ServiceItems, rowsPerPage: 45);
	var queryParams = new { Model.Year, Model.Month, Model.MonthRange, Model.VehicleId };
	var serviceOverdueBadge = Model.UpcomingServiceReminders.Any(sr => sr.IsServiceOverdue) ? "badge-warning" : "";
}

@section Scripts {
	<script type="text/javascript">
		var availableLogYearMonths = @Html.Raw(Json.Encode(Model.AvailableYearMonths));
		@if (Model.Year != null)
		{
			<text>var selectedYear = "@Model.Year";</text>
			<text>var selectedMonth = "@Model.Month";</text>
		}
	</script>
}

@Html.Partial("_StatusMessage")

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

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

<div class="btn-toolbar pull-left">
    @Html.ActionLink("Add Service", "Create", null, new { @class = "btn" })
    @Html.ActionLink("Export", "Export", queryParams, new { @class = "btn" })
	<a class="qtip-show-next-div btn">Upcoming Services <span class="badge @serviceOverdueBadge">@Model.UpcomingServiceReminders.Count</span></a>
	<div class="hidden">
		@if (@Model.UpcomingServiceReminders.Count > 0)
		{
			@Html.Partial("UpcomingServiceReminders", Model.UpcomingServiceReminders)
		}
		else {
			<h5>No upcoming services currently scheduled</h5>
		}
	</div>
</div>

@grid.GetHtml(columns:
		grid.Columns(
				grid.Column("InvoiceDate", "Invoice Date", item => item.InvoiceDate.ToString("d")),
                grid.Column("VehicleId", "Vehicle ID", item => Html.ActionLink((string)item.VehicleId, "DetailsPartial", "Vehicle", new { id = item.VehicleId }, new { @class = "qtip-modal" })),
				grid.Column("ServiceCenterName", "Service Center Name"),
				grid.Column("Price", "Price", @<text>@String.Format("{0:C}", item.Price)</text>),
				grid.Column("Description", "Description"),
				grid.Column(format:
							@<div class='btn-group'>
                                @Html.ActionLink("Details", "Details", new { id = item.VehicleServiceId }, new { @class = "btn btn-mini" })
                                @Html.ActionLink("Delete", "Delete", new { id = item.VehicleServiceId }, new { @class = "btn btn-mini" })
                            </div>)
            ), 
            htmlAttributes: new { @class = "table table-striped table-bordered table-hover table-condensed"},
            numericLinksCount: 20
     )