@using Website.Client.Shared.Components.Products

@if (Cart != null && Cart.Seller != null)
{
    <div class="card mb-3">
        <div class="card-header">
            <div class="fs-6 d-flex align-items-center">
                <Avatar User="@Cart.Seller" Width="25" Height="25" />

                <div class="ms-1">
                    <a href="/users/@Cart.Seller.Id" class="text-decoration-none text-dark">@Cart.Seller.Name</a> Products
                </div>
            </div>
        </div>
        <div class="card-body">

            <table class="table table-striped mb-3">
                <thead>
                    <tr>    
                        <th scope="col">Product</th>
                        <th scope="col"></th>
                        <th scope="col">Price</th>
                        <th scope="col">Options</th>
                    </tr>
                </thead>
                <tbody>
                    @foreach (OrderItemParams item in Cart.Items)
                    {
                        <tr>
                            <td class="align-middle"><img src="/api/images/@item.Product.ImageId" width="40" height="40" /></td>
                            <td class="align-middle"><a href="/products/@item.ProductId">@item.Product.Name</a></td>
                            <td class="align-middle">
                                <div class="position-relative">
                                    @if (item.Product.Sale != null)
                                    {
                                        <div class="position-absolute ps-1 pe-1 bg-success bg-success text-white rounded" style="right: calc(100% + .25rem);" title="@item.Product.Sale.SaleName">-@(((1M - item.Product.Sale.SaleMultiplier) * 100).ToString("N0"))%</div>
                                        <s class="d-block">@item.Product.Price USD</s>
                                    }
                                    <span>@item.Product.DiscountedPrice().ToString("N2") USD</span>
                                </div></td>
                            <td class="align-middle">
                                <button class="btn btn-outline-danger" @onclick="() => RemoveFromCartAsync(item)">
                                    <i class="bi bi-trash-fill"></i>
                                </button>
                            </td>
                        </tr>
                    }
                    <tr>
                        <td></td>
                        <th class="align-middle fw-bold">Total</th>
                        <td class="align-middle fw-bold">@Cart.Items.Sum(x => x.Product.DiscountedPrice()) USD</td>
                        <td></td>
                    </tr>
                </tbody>
            </table>

            <AuthorizeView>
                <Authorized>
                    <div class="mb-2">
                        <a class="btn btn-primary" href="/checkout/@Cart.Seller.Id">
                            Procceed to checkout
                        </a>
                    </div>
                </Authorized>
                <NotAuthorized>
                    <div class="mb-3 fw-bold">
                        <a href="/signin" class="text-decoration-none">You have to sign in to continue</a>
                    </div>
                </NotAuthorized>
            </AuthorizeView>

        </div>
    </div>
}
