@using MrCMS.Helpers
@model MrCMS.Web.Apps.Ecommerce.Models.CategoryPagedList
@{
    ViewBag.Title = "Categories";
}

@if (Model != null)
{

    <form>
        <fieldset>
            <legend>Categories
                <span class="btn-group  display-inline  pull-right">
                    <a href="@Url.Action("Add", "Webpage", new { id = Model.CategoryContainerId })" class="btn btn-primary">Add Root Category</a>
                </span>
            </legend>
            @{
    if (Model.Any())
    {
                <table class="table table-condensed table-striped">
                    <thead>
                        <tr>
                            <th>Name
                            </th>
                            <th>Published
                            </th>
                            <th>Actions
                            </th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach (var category in Model)
                        {
                            <tr>
                                <td>
                                    @category.NestedName
                                </td>
                                <td>
                                    @category.Published
                                </td>
                                <td>
                                    <div class="btn-group">
                                        <a href="@Url.Action("Add", "Webpage", new { id = category.Id })" class="btn btn-xs btn-success">Add Child Category</a>
                                        <a href="@Url.Action("Edit", "Webpage", new { id = category.Id })" class="btn btn-xs btn-default">Edit</a>
                                        <a href="@Url.Action("Sort", "CategoryProducts", new { id = category.Id })" class="btn btn-xs btn-default">Set Product Display Order</a>
                                        <a href="@Url.Action("Delete", "Webpage", new { id = category.Id })" class="btn btn-xs btn-danger" data-toggle="fb-modal">Delete</a>
                                    </div>
                                </td>
                            </tr>
                        }
                    </tbody>
                </table>
                @Html.Pager(Model, "Index", p => new { p }, PagedListRenderOptions.PageNumbersOnly)
    }
    else
    {
                @:No categories added.
    }
            }

        </fieldset>
    </form>
}
else
{
    <h2>Categories</h2>
    <p>Before you can add categories, you need to add a Category Container to the navigation tree</p>    
}