@using MileageTraker.Web.Utility
@model MileageTraker.Web.ViewModels.Log.LogResultsViewModel

@{
    ViewBag.Title = "Logs";
    var grid = new WebGrid(Model.Logs, rowsPerPage: 45);
	var queryParams = new {Model.Year, Model.Month, Model.LogType, Model.MonthRange, Model.VehicleId, Model.EmployeeName};
}
@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.Year != null)
		{
			<text>var selectedYear = "@Model.Year";</text>
			<text>var selectedMonth = "@Model.Month";</text>
		}
	</script>
}

@Html.Partial("_StatusMessage")

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

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

<div class="btn-toolbar clearfix">
    @Html.ActionLink("Add New Log", "Create", null, new { @class = "btn" })
	@Html.ActionLink("Import", "ImportUpload", null, new { @class = "btn"})
    @Html.ActionLink("Export", "Export", queryParams, new { @class = "btn" })
    
    <div class="btn-group">
        <a class="btn dropdown-toggle" data-toggle="dropdown" href="#">Report <i class="fa fa-caret-down"></i></a>
        <ul class="dropdown-menu">
            <li>
                @Html.ActionLink("Vehicle Mileage", "VehicleMileageReport", queryParams)
            </li>
            <li>
                @Html.ActionLink("Driver Mileage", "DriverMileageReport", queryParams)
            </li>
        </ul>
    </div>
</div>

<div>
    @grid.GetHtml(columns:
        grid.Columns(
                grid.Column("VehicleId", "Vehicle ID", item => Html.ActionLink((string)item.VehicleId, "DetailsPartial", "Vehicle", new { id = item.VehicleId }, new { @class = "qtip-modal" })),
                grid.Column("EndOdometer", "End ODO"),
                grid.Column("Miles", canSort: false, format: item =>
                                             	{
													if (item.PreviousLogId != null)
													{
														string miles = (item.Miles).ToString();
														return Html.ActionLink(miles, "DetailsPrevious", new { id = item.PreviousLogId }, new { @class = "qtip-modal" });
													}
                                                    return Html.Raw("<span class='miles-unknown'>?</span>");
												}),
                grid.Column("LogType", "Type", item => ((Enum)item.LogType).GetDisplayShortName()),
                grid.Column("GasPurchased", "Gas", item => item.GasPurchased > 0 ? String.Format("{0:0.000}", item.GasPurchased) : string.Empty),
                grid.Column("Date", format: item => item.Date.ToString("d")),
                grid.Column("CityName", "City Name"),
                grid.Column("PurposePurpose", "Purpose", item =>
                            {
                                if (item.Notes != null)
                                {
                                    return Html.Raw("<span title='" + Html.Encode(item.Notes) + "'>" + Html.Encode(item.PurposePurpose) + "</span>");
                                }
                                return item.PurposePurpose;
                            }),
                grid.Column("Driver Name", format: item => item.UserFullName),
                grid.Column("Total Results: " + Model.Logs.Count(), canSort:false, format: 
                            @<div class='btn-group'>
                                @Html.ActionLink("Edit", "Edit", new { id = item.LogId }, new { @class = "btn btn-mini" })
                                @Html.ActionLink("Details", "Details", new { id = item.LogId }, new { @class = "btn btn-mini" })
                                @Html.ActionLink("Delete", "Delete", new { id = item.LogId }, new { @class = "btn btn-mini" })
                            </div>)
            ), 
            htmlAttributes: new { @class = "table table-striped table-bordered table-hover table-condensed"},
            numericLinksCount: 20
     )
</div>
@if (!Model.Logs.Any())
{
	<div>
		No results.
	</div>
}