@using MrCMS.Web.Apps.Ecommerce.Helpers
@model MrCMS.Web.Apps.Ecommerce.Entities.Orders.Order
<hr />
<h4>Order Items</h4>
<div class="row">
    <div class="col-lg-12">
        @if (Model.OrderLines.Count == 0)
        {
            @:No lines.
            }
        else
        {
            <table class="table table-striped table-condensed">
                <thead>
                    <tr>
                        <th>
                            Product
                        </th>
                        <th>
                            SKU
                        </th>
                        <th>
                            Quantity
                        </th>
                        <th>
                            Unit Price
                        </th>
                        <th>
                            Subtotal
                        </th>
                        <th>
                            Tax
                        </th>
                        <th>
                            Discount
                        </th>
                        <th>
                            Weight
                        </th>
                        <th>
                            Requires shipping?
                        </th>
                        <th>
                        </th>
                    </tr>
                </thead>
                <tbody>
                    @foreach (var item in Model.OrderLines)
                    {
                        <tr>
                            <td>
                                @item.Name
                            </td>
                            <td>
                                @if (!String.IsNullOrWhiteSpace(item.SKU))
                                {
                                    @item.SKU
                                }
                                else if (item.ProductVariant != null)
                                {
                                    @item.ProductVariant.SKU
                                }
                            </td>
                            <td>
                                @item.Quantity
                            </td>
                            <td>
                                @item.UnitPrice.ToCurrencyFormat()
                            </td>
                            <td>
                                @item.Subtotal.ToCurrencyFormat()
                            </td>
                            <td>
                                @item.Tax.ToCurrencyFormat()
                            </td>
                            <td>
                                @item.Discount.ToCurrencyFormat()
                            </td>
                            <td>
                                @item.Weight.ToString("n2")
                            </td>
                            <td>
                                @item.RequiresShipping
                            </td>
                            <td>
                                @if (item.GiftCards.Any())
                                {
                                    @Html.ActionLink("View gift card", "Edit", "GiftCard", new { id = item.GiftCards.First().Id }, new { @class = "btn btn-default btn-xs" })
                                }
                            </td>
                        </tr>
                        if (item.IsDownloadable)
                        {
                            <tr>
                                <td></td>
                                <td colspan="8">
                                    <div class="row">
                                        <div class="col-lg-12">
                                            <h5 class="margin-bottom-5">This product is downloadable</h5>
                                            <table class="table table-condensed margin-bottom-5">
                                                <tr>
                                                    <td>Number of downloads</td>
                                                    <td>@item.NumberOfDownloads</td>
                                                </tr>
                                                <tr>
                                                    <td>Allowed of downloads</td>
                                                    <td>@item.AllowedNumberOfDownloads</td>
                                                </tr>
                                                <tr>
                                                    <td>Expires</td>
                                                    <td>@item.DownloadExpiresOn</td>
                                                </tr>
                                                <tr>
                                                    <td>Link</td>
                                                    <td>@item.DownloadMaskedLink</td>
                                                </tr>
                                                <tr>
                                                    <td colspan="2">@Html.ActionLink("Edit", "Edit", "OrderLine", new { id = item.Id }, new { @class = "btn btn-xs btn-default", data_toggle = "fb-modal" })</td>
                                                </tr>
                                            </table>
                                        </div>
                                    </div>
                                </td>
                            </tr>
                        }
                    }
                </tbody>
            </table>
        }
    </div>
</div>
