@using System.Drawing
@using System.Linq
@using MrCMS.Web.Apps.Ecommerce.Entities.Products
@using MrCMS.Web.Apps.Ecommerce.Helpers
@using MrCMS.Web.Apps.Ecommerce.Models
@using MrCMS.Web.Apps.Ecommerce.Models.StockAvailability
@using MrCMS.Web.Apps.Ecommerce.Pages
@using MrCMS.Web.Apps.Ecommerce.Services.Pricing
@using MrCMS.Web.Apps.Ecommerce.Settings
@using MrCMS.Website
@model MrCMS.Web.Apps.Ecommerce.Entities.Products.ProductVariant
@{
    Product product = Model.Product;
    CanBuyStatus canBuy = ViewData["can-buy-status"] as CanBuyStatus ?? new CannotOrderQuantity(Model, 0);
    var productVariantOptions = ViewData["product-variant-options"] as List<SelectListItem> ?? new List<SelectListItem>();
    var mainCategory = product.Categories.OrderBy(x => x.DisplayOrder).FirstOrDefault();
    var pricingMethod = MrCMSApplication.Get<IProductPricingMethod>();
    var previousPrice = pricingMethod.GetDisplayPreviousPrice(Model);
}

<div class="margin-bottom-30 grey-border-top" id="variant-details">
    <div class="container">
        <div class="margin-top-bottom-30">
            <div class="row">
                <div class="col-sm-12">
                    <h1 itemprop="name">@Model.Product.Name</h1>
                </div>
            </div>
            <div class="row">
                <div class="col-sm-7">
                    @{ Html.RenderPartial("ProductImages", Model); }
                </div>
                <div class="col-sm-5">
                    <div class="price margin-bottom-10">
                        <span itemprop="offerDetails" itemscope itemtype="http://data-vocabulary.org/Offer">
                            <meta itemprop="priceCurrency" content="@(MrCMSApplication.Get<EcommerceSettings>().CurrencyCode())" />
                            <span itemprop="price">@pricingMethod.GetUnitPrice(Model).ToCurrencyFormat()</span>
                            @if (canBuy.OK)
                            {
                                <span class="instock" itemprop="availability" content="in_stock">@(!string.IsNullOrEmpty(Model.CustomStockInStockMessage) ? Model.CustomStockInStockMessage : Resource("In Stock"))</span>
                            }
                            @if (previousPrice != null)
                            {
                                <span class="previous-price">
                                    <span class="inner">@previousPrice.Value.ToCurrencyFormat()</span>
                                </span>
                            }
                        </span>
                    </div>

                    @if (!Model.SoldOut)
                    {
                        if (product.IsMultiVariant)
                        {
                            <div class="margin-bottom-10">
                                <div class="col-sm-3 col-xs-4 padding-left-0">
                                    <label class="line-height-30">Options :</label>
                                </div>
                                <div class="col-sm-9 col-xs-8 padding-right-0">
                                    @Html.DropDownList("variant", productVariantOptions, new { @class = "form-control" })
                                </div>
                                <div class="clearfix"></div>
                            </div>
                        }

                        if (canBuy.OK)
                        {
                            Html.RenderAction("Add", "AddToCart", new { model = new AddToCartModel { ProductVariant = Model, Quantity = 1 } });
                        }

                        Html.RenderAction("Add", "Wishlist", new { productVariant = Model });

                        Html.RenderPartial("ProductPricebreaks", Model);                        
                                                
                        if (canBuy is OutOfStock)
                        {
                            <span itemprop="availability" content="out_of_stock" class="bg-warning">@(!string.IsNullOrEmpty(Model.CustomStockOutOfStockMessage) ? Model.CustomStockOutOfStockMessage : Resource("Out of stock"))</span> <br />
                            Html.RenderAction("BackInStockForm", "Product", new { id = Model.Id });
                        }
                        if (canBuy is CannotOrderQuantity)
                        {
                            <p class="text-center">
                                @canBuy.Message;
                            </p>
                        }
                        if (canBuy is NoShippingMethodWouldBeAvailable)
                        {
                            <p class="text-center">
                                @canBuy.Message
                            </p>
                        }
                        <table class="table table-condensed">
                            <tr>
                                <th colspan="2">Product Information</th>
                            </tr>
                            @if (!string.IsNullOrWhiteSpace(Model.SKU))
                            {
                                <tr>
                                    <td width="20%">@Resource("Product Details SKU", "SKU")</td>
                                    <td><span itemprop="identifier" content="sku:@Model.SKU">@Model.SKU</span></td>
                                </tr>
                            }
                            @if (product.BrandPage != null)
                            {
                                <tr>
                                    <td>@Resource("Product Details Brand", "Brand")</td>
                                    <td><a href="/@product.BrandPage.LiveUrlSegment"><span itemprop="brand">@product.BrandPage.Name</span></a></td>
                                </tr>
                            }
                            @if (mainCategory != null)
                            {
                                <tr>
                                    <td>@Resource("Product Details Category", "Category")</td>
                                    <td>
                                        <span itemprop="category" content="@mainCategory.NestedName"><a href="/@mainCategory.UrlSegment">@mainCategory.Name</a></span>
                                    </td>
                                </tr>
                            }
                        </table>


                    }
                    else
                    {
                        @Html.Raw(Model.SoldOutMessage)
                    }

                    @if (!string.IsNullOrWhiteSpace(product.ProductAbstract))
                    {
                        <div class="padding-bottom-10" itemprop="description">
                            @Editable(product, p => p.ProductAbstract, false)
                        </div>
                    }


                    @if (!string.IsNullOrWhiteSpace(Model.Product.BodyContent))
                    {
                        <div class="padding-bottom-10" id="readFullDescription">
                            <p class="hidden-xs">
                                <a href="#fulldescription" title="Read full description">Read full description</a>
                            </p>
                        </div>
                    }
                    @{ Html.RenderPartial("SocialLinks"); }


                    @{RenderZone("Below Product Price");}
                </div>
            </div>
        </div>
    </div>
</div>
@{ RenderZone("Below Add to cart"); }