@using MrCMS.Helpers
@using MrCMS.Web.Apps.Ecommerce.Pages
@model MrCMS.Paging.IPagedList<Category>
@{ 
    var product = ViewData["product"] as Product;
}

<div id="categories"  data-paging-type="async">
    <table class="table table-striped table-condensed margin-top-0" style="margin-bottom: 0;">
        <tbody>
                
            @foreach (var category in Model)
            {
                <tr>
                    <td>@category.NestedName</td>
                    <td>
                        <div class="pull-right">
                            <button class="btn btn-success add-category" data-category-id="@category.Id" 
                                data-product-id="@product.Id" data-page="@(Model.PageCount > 1 ? Model.PageNumber : Model.PageNumber - 1)">Add</button>
                        </div>
                    </td>
                </tr>
            }
                
        </tbody>
    </table>
    @if (Model.Count == 0)
    {
        <span>No categories to add to product.</span>
    }
    @Html.Pager(Model, "AddCategoryCategories", i => new { page = i, id = product.Id })
</div>