@model CartWrapperDto
@{
    if(Model != null && Model.CartDto != null && Model.CartDto.CartHeader != null)
    {
        var userId = Model.CartDto!.CartHeader!.UserId;
<form method="post">
    <br />
    <input asp-for="CartDto!.CartHeader!.UserId" hidden />
    <input asp-for="CartDto!.CartHeader!.CartHeaderId" hidden />
    
    <div class="">
        <div class="card border mt-4 container">
            <div class="card-header bg-dark text-light ml-0 row ">
                <div class="col-6">
                    <h3 class="text-success"><i class="bi bi-cart"></i> &nbsp; Shopping Cart</h3>
                </div>
                <div class="col-6 text-end">
                    <a action="Index" asp-controller="Home" class="btn btn-outline-warning mt-2 btn-sm">Continue Shopping</a>
                </div>
            </div>
            <div class="card-body">
                <div class=" d-none d-lg-block">
                    <div class="row text-info">
                        <div class="col-lg-2">
                        </div>
                        <div class="col-lg-5">
                            Product Details
                        </div>
                        <div class="col-lg-2">
                            Price
                        </div>
                        <div class="col-lg-2">
                            Count
                        </div>
                        <div class="col-lg-1">
                        </div>
                    </div>
                </div>
                <hr />

                @foreach (var cart in Model.CartDto!.CartDetails!)
                {

                    <div class="row h-100">
                        <div class="col-4 col-md-2 text-center py-2">
                            <img src="@cart.ProductDto!.ImageLocalPath" class="rounded" width="100" />
                        </div>
                        <div class="col-8 col-md-5">
                            <h5>@cart.ProductDto!.Name</h5>
                            <div style="font-size:11px;">@Html.Raw(cart.ProductDto.Description)</div>
                        </div>
                        <div class="col-3 col-md-2 pt-md-4" style="font-size:11px;">
                            <span style="font-size:17px;">@string.Format("{0:c}", cart.ProductDto.Price)</span>
                        </div>
                        <div class="col-3 col-md-2 pt-md-4" style="font-size:11px;">
                            <span style="font-size:17px;"> @cart.Count</span>
                        </div>
                        <div class="col-2 col-lg-1 p-0 pt-lg-4 text-center">
                            <a asp-action="RemoveCart" asp-route-cartDetailsId="@cart.CartDetailsId" class="btn btn-sm btn-danger">
                                <i class="bi bi-trash-fill"></i>
                            </a>
                        </div>
                    </div>
                    <hr />
                }

                <div class="row">
                    @if (string.IsNullOrWhiteSpace(Model.CartDto!.CartHeader!.CouponCode))
                    {

                        <div class="col-6">
                            <span>Coupon:</span>
                            <input asp-for="CartDto!.CartHeader!.CouponCode" />
                            <button type="submit" asp-route-userId="@userId" asp-action="ApplyCouponCode" class="btn btn-sm btn-success"> Apply </button>
                        </div>
                    }
                    else
                    {
                        <div class="col-6">
                            <span>Coupon:</span>
                            <input asp-for="CartDto!.CartHeader!.CouponCode" disabled />
                            <button type="submit" asp-route-userId="@userId" asp-action="RemoveCoupon" class="btn btn-sm btn-danger"> Remove </button>
                        </div>
                    }
                    <div class="col-6 text-end">
                        <span class="text-danger" style="font-size:21px;">  Order Total : @string.Format("{0:c}", Model.CartDto!.CartHeader!.CartTotal) <br /></span>
                        @if (Model.CartDto!.CartHeader.Discount > 0)
                        {
                            <span class="text-success"> Order Discount :  @string.Format("{0:c}", Model.CartDto!.CartHeader!.Discount)</span>
                        }
                    </div>
                </div>
            </div>
            <div class="card-footer row">
                <div class="col-6 col-md-3 ">
                    <!--similar to registration process here-->
                    <button type="submit" class="btn btn-outline-danger form-control">Email Cart</button>
                </div>
                <div class="col-6 col-md-3 offset-md-6">
                    <button disabled class="btn btn-success form-control ">"Checkout (Comming Soon!)" </button>
                </div>
            </div>
        </div>
    </div>
        </form>

    }
    else
    {
        <div>
            <p>The cart is empty right now</p>
        </div>
    }

}