@using MrCMS.Helpers
@using MrCMS.Web.Apps.Amazon.Models
@using MrCMS.Web.Apps.Ecommerce.Helpers
@model MrCMS.Paging.IPagedList<MrCMS.Web.Apps.Amazon.Entities.Listings.AmazonListing>

@{
    var amazonProductDetailsUrl=ViewData["AmazonProductDetailsUrl"] as string;
}

<div data-paging-type="async" id="listings">
    
    @if (!Model.Any())
    {
        @:No listings in this group.
    }
    else
    {
        <table class="table table-striped table-condensed" style="overflow: scroll">
            <thead>
                <tr>
                    <th>
                        SKU
                    </th>
                     <th>
                        ASIN
                    </th>
                    <th>
                        Title
                    </th>
                    <th>
                        Status
                    </th>
                    <th>Actions
                    </th>
                </tr>
            </thead>
            <tbody>
                @foreach (var item in Model)
                {
                    <tr>
                        <td>
                            @item.SellerSKU
                        </td>
                        <td>
                            @if (!String.IsNullOrWhiteSpace(amazonProductDetailsUrl))
                            {
                                <a href='@(amazonProductDetailsUrl + item.ASIN)' target="_blank">
                                    @item.ASIN
                                </a>
                            }
                            else
                            {
                                @item.ASIN
                            }
                        </td>
                        <td>
                            @item.Title
                        </td>
                        <td>
                            @item.Status.GetDescription()
                        </td>
                        <td>
                             <div class="btn-group">
                            @Html.ActionLink("Details", "Details", "Listing", new {id = item.Id}, new { @class="btn btn-xs btn-default"})
                            @Html.ActionLink("Sync", "SyncOne", "Listing", new {id = item.Id}, new {@class = "btn btn-xs btn-success"})
                            @(item.Status == AmazonListingStatus.Active ? Html.ActionLink("Close", "CloseOne", "Listing", new {id = item.Id}, new {@class = "btn btn-xs btn-warning"}) : Html.ActionLink("Delete", "Delete", "Listing", new {id = item.Id}, new {@class = "btn btn-xs btn-danger", data_toggle = "fb-modal"}))
                             </div>
                        </td>
                    </tr>
                }
            </tbody>
        </table>
    }

    @Html.Pager(Model, "Listings", i => new { page = i })

</div>
@{ Html.IncludeScript("~/Apps/Amazon/Areas/Admin/Content/Scripts/custom/async-paging.js"); }
