@using MrCMS.Helpers
@using MrCMS.Web.Apps.Amazon.Models
@using MrCMS.Web.Apps.Ecommerce.Helpers
@using MrCMS.Web.Apps.Ecommerce.Models
@model AmazonOrderSearchModel
@{
    var amazonOrderDetailsUrl = ViewData["AmazonOrderDetailsUrl"] as string;
}

<div data-paging-type="async" id="orders">

    @if (Model != null && Model.Results.Any())
    {
        <table class="table table-striped table-condensed" style="overflow: scroll">
            <thead>
                <tr>
                    <th>
                        MrCMS Order
                    </th>
                    <th>
                        Amazon Order #
                    </th>
                    <th>
                        Buyer Name
                    </th>
                    <th>
                        Order Status
                    </th>
                    <th>
                        Amount
                    </th>
                    <th>
                        Purchase Date
                    </th>
                    <th>
                        Actions
                    </th>
                </tr>
            </thead>
            <tbody>
                @foreach (var item in Model.Results)
                {
                    var status = "warning";
                    if (item.Status.GetDescription().Equals("Shipped"))
                    {
                        status = "success";
                    }

                    <tr class="@status">
                        <td>
                            @Html.ActionLink("Details", "Edit", "Order", new { id = item.Order.Id }, null)
                        </td>
                        <td>
                            @if (!String.IsNullOrWhiteSpace(amazonOrderDetailsUrl))
                            {
                                <a href='@(amazonOrderDetailsUrl + item.AmazonOrderId)' target="_blank">
                                    @item.AmazonOrderId
                                </a>
                            }
                            else
                            {
                                @item.AmazonOrderId
                            }
                        </td>
                        <td>
                            @item.BuyerName
                        </td>
                        <td>
                            @item.Status.GetDescription()
                            @{
                    if (item.Order.ShippingStatus.Equals(ShippingStatus.Shipped) && !item.Status.GetDescription().Equals("Shipped"))
                    {
                        @:<strong style="word-break: break-all">Shipped - Awaiting Sync</strong>
                    }
                            }
                        </td>
                        <td>
                            @item.OrderTotalAmount.ToCurrencyFormat()
                        </td>
                        <td>
                            @(item.PurchaseDate.HasValue ? item.PurchaseDate.Value.ToString("dd/MM/yyyy HH:mm") : String.Empty)
                        </td>
                        <td>
                            <div class="btn-group">
                                @Html.ActionLink("Details", "Details", "Orders", new { id = item.Id }, new { @class = "btn btn-xs btn-default" })
                            </div>
                        </td>
                    </tr>
                }
            </tbody>
        </table>

        @Html.Pager(Model.Results, "Orders", i => new { page = i })
    }
    else
    {
        @:No orders found.
    }

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