@using MrCMS.Helpers
@using MrCMS.Web.Apps.Ecommerce.Helpers
@using MrCMS.Web.Apps.Ecommerce.Models
@model MrCMS.Web.Apps.Ecommerce.Pages.PaymentDetails
@{ var cart = ViewData["cart"] as CartModel;}
@{ var settingBillingAddress = ViewData["setting-billing-address"] is bool && (bool)ViewData["setting-billing-address"];}

<div class="padding-top-bottom-20">
    <div class="row">
        <div class="col-sm-8">
            <div class="border-all margin-bottom-20">
                <div class="sub-header grey-background">
                    @Resource("Billing Address")
                </div>
                <div class="padding-20">
                    @if (cart.RequiresShipping && cart.BillingAddressSameAsShippingAddress)
                    {
                        using (Html.BeginForm("BillingAddressSameAsShippingAddress", "PaymentDetails", FormMethod.Post, new { @class = "form-horizontal" }))
                        {
                            <div class="checkbox">
                                <label>
                                    @Html.CheckBox("SameAsShipping", cart.BillingAddressSameAsShippingAddress) @Resource("Use Delivery Address")
                                </label>
                                <div class="">
                                    @cart.ShippingAddress.GetDescription()
                                </div>
                            </div>
                        }
                    }

                    @if (settingBillingAddress)
                    {
                        Html.RenderAction("SetBillingAddress", "PaymentDetails");
                    }
                    else if (!cart.BillingAddressSameAsShippingAddress && cart.BillingAddress != null)
                    {
                        <div class="margin-bottom-10">
                            <label>
                                @Resource("Billing Address") :
                            </label>
                            @cart.BillingAddress.GetDescription()
                        </div>

                        using (Html.BeginForm("UpdateBillingAddress", "PaymentDetails", FormMethod.Post, new { @class = "form-horizontal" }))
                        {
                            <div class="control-group">
                                <div class="controls">
                                    <input class="btn btn-default" value="Edit" type="submit" />
                                </div>
                            </div>
                        }
                    }
                </div>
            </div>


            @if (cart.TermsAndConditionsRequired)
            {
                <div class="border-all margin-bottom-20">
                    <div class="sub-header grey-background">
                        @Resource("Payment Details Page - Terms and Conditions", "Terms and Conditions")
                    </div>
                    <div class="padding-20">
                        <div class="checkbox">
                            <label>
                                @Html.CheckBox("TermsAndConditionsAccepted", cart.TermsAndConditionsAccepted) @Html.Raw(Resource("I accept the terms and conditions"))
                            </label>
                        </div>
                    </div>
                </div>
            }

            <div class="border-all margin-bottom-20">
                <div class="sub-header grey-background">
                    @Resource("Payment Details")
                </div>
                <div class="padding-20">
                    @if (!settingBillingAddress)
                    {
                        Html.RenderAction("Methods", "PaymentDetails", cart);
                        <div data-please-accept="true">
                            @Resource("Please accept the terms and conditions to proceed to payment")
                        </div>
                    }
                    else
                    {
                        <p>@Resource("Select after updating billing address")...</p>
                    }
                </div>
            </div>
        </div>
        <div class="col-sm-4">
            @{Html.RenderAction("Summary", "Checkout");}
            @{Html.RenderAction("OrderEmail", "Checkout");}
            @if (cart.RequiresShipping)
            {
                Html.RenderAction("DeliveryDetails", "Checkout");
            }
        </div>
    </div>
</div>
@{
    Html.IncludeScript("~/Apps/Ecommerce/Content/Scripts/custom/payment-details.js");
    Html.IncludeScript("https://js.braintreegateway.com/v2/braintree.js");
}