@using MrCMS.Helpers
@using MrCMS.Web.Apps.Ecommerce.Entities.Cart
@using MrCMS.Web.Apps.Ecommerce.Entities.GiftCards
@using MrCMS.Web.Apps.Ecommerce.Helpers
@using MrCMS.Web.Apps.Ecommerce.Helpers.Cart
@using MrCMS.Web.Apps.Ecommerce.Pages
@using MrCMS.Web.Apps.Ecommerce.Settings
@model MrCMS.Web.Apps.Ecommerce.Models.CartModel
@{
    var ecommerceSettings = SiteSettings<EcommerceSettings>();
}
<div id="basic-details" class="margin-bottom-20">
    @if (Model.Items.Any())
    {
        <div class="sub-header border-top">
            @Resource("Checkout - Order Summary", "Order Summary")
        </div>
        <div class="grey-background padding-20 margin-bottom-20">
            <table class="table">
                <thead>
                    <tr>
                        <th>@Resource("Description")</th>
                        <th>@Resource("Amount")</th>
                    </tr>
                </thead>
                <tbody>
                    @foreach (var item in Model.Items)
                    {
                        <tr>
                            <td>
                                <ul class="media-list">
                                    <li>@item.Name</li>
                                    <li>@Resource("Item Price"): @item.UnitPrice.ToCurrencyFormat()</li>
                                    <li>@Resource("Quantity"): @item.Quantity</li>
                                </ul>
                            </td>
                            <td>@item.Price.ToCurrencyFormat()</td>
                        </tr>
                    }
                </tbody>
                <tfoot>
                    <tr>
                        <th>@Resource("Sub Total"):</th>
                        <td>@Model.Subtotal.ToCurrencyFormat()</td>
                    </tr>
                    @if (Model.ShippingTotalPreDiscount > decimal.Zero)
                    {
                        <tr>
                            <th>@Resource("Shipping"):</th>
                            <td>@Model.ShippingTotalPreDiscount.ToCurrencyFormat()</td>
                        </tr>
                    }
                    @if (Model.ShippingDiscount > decimal.Zero)
                    {
                        <tr>
                            <th>@Resource("Shipping Discount"):</th>
                            <td>@((-Model.ShippingDiscount).ToCurrencyFormat())</td>
                        </tr>
                    }
                    @if (Model.HasOrderTotalDiscount())
                    {
                        <tr>
                            <th>@Resource("Discount"): </th>
                            <td>@((-Model.OrderTotalDiscount).ToCurrencyFormat())</td>
                        </tr>
                    }
                    @if (SiteSettings<TaxSettings>().TaxesEnabled)
                    {
                        <tr>
                            <th>@Resource("Tax"): </th>
                            <td>@Model.Tax.ToCurrencyFormat()</td>
                        </tr>
                    }
                    <tr>
                        <th>@Resource("Total"):</th>
                        <td class="green"><strong>@Model.Total.ToCurrencyFormat()</strong></td>
                    </tr>
                    @foreach (GiftCard card in Model.AppliedGiftCards)
                    {
                        <tr>
                            <td>
                                @Resource("Gift Card") @card.Code
                            </td>
                            <td>
                                @card.AvailableAmount.ToCurrencyFormat()
                            </td>
                        </tr>
                    }
                    @if (ecommerceSettings.RewardPointsEnabled && Model.AvailablePoints > 0)
                    {
                        <tr>
                            <td>
                                <div style="line-height:30px">
                                    @Html.InlineCheckboxFor(x => x.UseRewardPoints, checkboxAttributes: new { @class = "checkbox", data_use_reward_points = true })
                                </div>

                                @if (!Model.UseRewardPoints)
                                {
                                    <span>
                                        <strong>@Resource("Available balance"):</strong> @Model.AvailablePoints (@Model.AvailablePointsValue.ToCurrencyFormat())
                                    </span>
                                }
                                @if (Model.AppliedRewardPoints > 0)
                                {
                                    <span>
                                        <strong>@Resource("Reward points applied"):</strong> (@Model.AppliedRewardPoints)
                                    </span>
                                }
                            </td>
                            <td style="vertical-align: bottom">
                                @if (Model.AppliedRewardPoints > 0)
                                {
                                    @((-Model.AppliedRewardPointsAmount).ToCurrencyFormat())
                                }
                            </td>
                        </tr>
                    }
                    @if (Model.AppliedGiftCards.Any() || Model.AppliedRewardPoints > 0)
                    {
                        <tr>
                            <th>@Resource("Total to pay"):</th>
                            <td><strong>@Model.TotalToPay.ToCurrencyFormat()</strong></td>
                        </tr>
                    }
                </tfoot>
            </table>
            <a class="btn btn-default margin-bottom-20" id="edit" href="@(UniquePageHelper.GetUrl<Cart>())">@Resource("Edit")</a>
        </div>
    }

    @if (ecommerceSettings.GiftMessageEnabled)
    {
        <div class="grey-background padding-20 margin-bottom-20">
            <p><strong>@Resource("Checkout - Gift Message", "Gift Message")</strong></p>
            <div data-message-container="@ecommerceSettings.GiftMessageMaxLength" data-error-message="@string.Format(Resource("Your gift message is more than {0} characters"), ecommerceSettings.GiftMessageMaxLength)">
                <div class="row margin-bottom-10">
                    <div class="col-xs-12">
                        <div class="form-group">
                            <textarea data-gift-message id="summary-gift-message" class="form-control">@Model.GiftMessage</textarea>
                        </div>
                        <span id="message-character-count" data-gift-message-remaining="summary-gift-message">
                            <span></span>
                        </span>
                    </div>
                </div>
            </div>
        </div>
    }

    @if (ecommerceSettings.GiftCardsEnabled)
    {
        <div class="grey-background padding-20 margin-bottom-20">
            @{ Html.RenderAction("GiftCards", "Cart"); }
        </div>
    }

    <div class="grey-background padding-20 margin-bottom-20">
        @{ Html.RenderAction("Discounts", "Cart"); }
    </div>

</div>