@using MrCMS.Helpers
@using MrCMS.Paging
@using MrCMS.Web.Apps.Ecommerce.Pages
@model MrCMS.Web.Apps.Ecommerce.Areas.Admin.Models.ProductAdminSearchQuery
@{
    ViewBag.Title = "Products";
    var products = ViewData["results"] as IPagedList<Product> ?? PagedList<Product>.Empty;
    var publishStatusOptions = ViewData["publish-status"] as List<SelectListItem> ?? new List<SelectListItem>();
    var productContainerId = ViewData["product-containerId"] is int ? (int)ViewData["product-containerId"] : 0;
}

@if (Model != null)
{
    <form>
        <fieldset>
            <legend>
                Products
                <span class="btn-group  display-inline  pull-right">
                    <a href="@Url.Action("Add", "Webpage", new { id = productContainerId })" class="btn btn-primary">Add Product</a>
                </span>
            </legend>

            @using (Html.BeginForm("Index", "Product", FormMethod.Get))
            {
                <div class="row">
                    <div class="col-xs-6">
                        @Html.LabelFor(query => query.Name)
                        <div class="form-group">
                            @Html.TextBoxFor(query => query.Name, new {@class = "form-control"})
                        </div>
                    </div>
                    <div class="col-xs-2">
                        @Html.LabelFor(query => query.SKU)
                        <div class="form-group">
                            @Html.TextBoxFor(query => query.SKU, new { @class = "form-control" })
                        </div>
                    </div>
                    <div class="col-xs-2">
                        @Html.LabelFor(query => query.PublishStatus)
                        <div class="form-group">
                            @Html.DropDownListFor(query => query.PublishStatus, publishStatusOptions, new {@class = "form-control"})
                        </div>
                    </div>
                    <div class="col-xs-2">
                        @Html.LabelFor(query => query.Brand)
                        <div class="form-group">
                            @Html.TextBoxFor(query => query.Brand, new {@class = "form-control"})
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-xs-6">
                        @Html.LabelFor(query => query.CategoryName)
                        <div class="form-group">
                            @Html.TextBoxFor(query => query.CategoryName, new { @class = "form-control" })
                        </div>
                    </div>
                    <div class="col-xs-3">
                        @Html.LabelFor(query => query.PriceFrom)
                        <div class="form-group">
                            @Html.TextBoxFor(query => query.PriceFrom, new { @class = "form-control" })
                        </div>
                    </div>
                    <div class="col-xs-3">
                        @Html.LabelFor(query => query.PriceTo)
                        <div class="form-group">
                            @Html.TextBoxFor(query => query.PriceTo, new { @class = "form-control" })
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-xs-6">
                        <input type="submit" class="btn btn-primary btn-success" value="Search" />
                    </div>
                </div>
            }

            <br />

            @if (products.Any())
            {
                Html.RenderPartial("ProductList", products.ToList());
                @Html.Pager(products, "Index", page => new { page })
            }
            else
            {
                <p>
                    There are currently no products that match your search criteria.
                </p>
            }
        </fieldset>
    </form>
}
else
{
    <h2>Products</h2>
    <p>Before you can add products, you need to add a Product Search to the navigation tree (Right-click on the Root item)</p>
}