@using MrCMS.Entities.Documents.Web
@using MrCMS.Helpers
@using MrCMS.Web.Apps.Core.Pages
@using MrCMS.Web.Apps.Ecommerce.Entities.Orders
@using MrCMS.Web.Apps.Ecommerce.Helpers
@using MrCMS.Web.Apps.Ecommerce.Models
@using MrCMS.Web.Apps.Ecommerce.Pages
@using MrCMS.Website
@model MrCMS.Web.Apps.Ecommerce.Models.UserAccountOrdersModel
@{
    Webpage currentPage = CurrentRequestData.CurrentPage;
    if (currentPage is UserAccountPage)
    {
        <div class="container">
            <div data-paging-type="async">
                <div class="block-title">
                    <div class="h1style">
                        Your Orders
                    </div>
                </div>
                @if (Model != null && !Model.Items.Any())
                {
                    @:You have no orders yet.
                }
                else
                {
                    <div class="table-responsive">
                        <table class="table table-condensed table-striped">
                            <thead>
                                <tr>
                                    <th>
                                        Order Id
                                    </th>
                                    <th>
                                        Payment Status
                                    </th>
                                    <th>
                                        Shipping Status
                                    </th>
                                    <th>
                                        Amount
                                    </th>
                                    <th>
                                        Order Date
                                    </th>
                                    <th></th>
                                </tr>
                            </thead>
                            <tbody>
                                @foreach (Order order in Model.Items)
                                {
                                    string status = "warning";
                                    if (order.ShippingStatus.Equals(ShippingStatus.Shipped) && order.PaymentStatus.Equals(PaymentStatus.Paid))
                                    {
                                        status = "success";
                                    }
                                    else if (order.IsCancelled)
                                    {
                                        status = "error";
                                    }

                                    <tr class="@status">
                                        <td>
                                            @order.Id
                                        </td>
                                        <td>
                                            @((order.IsCancelled) ? "Cancelled" : order.PaymentStatus.ToString())
                                        </td>
                                        <td>
                                            @((order.IsCancelled) ? "Cancelled" : order.ShippingStatus.ToString())
                                        </td>
                                        <td>
                                            @order.Total.ToCurrencyFormat()
                                        </td>
                                        <td>
                                            @order.OrderDate.GetValueOrDefault(order.CreatedOn)
                                        </td>
                                        <td>
                                            <a href="@(UniquePageHelper.GetUrl<UserOrder>(new {id = order.Guid}))" class="btn btn-default btn-block">View Order Details</a>
                                        </td>
                                    </tr>
                                }
                            </tbody>
                        </table>
                    </div>

                    @Html.Pager(Model.Items, "UserAccountOrders", i => new {Model.Id, page = i})
                }
            </div>
        </div>
    }
}

@{ Html.IncludeScript("~/Apps/Ecommerce/Content/Scripts/custom/async-paging.js"); }