@model CustomerAuctionsModel
@using Grand.Web.Models.Customer;
@inject IPageHeadBuilder pagebuilder
@{
    Layout = "_TwoColumns";
    //title
    pagebuilder.AddTitleParts(Loc["Title.Auctions"]);
}
@section left
{
    @await Component.InvokeAsync("CustomerNavigation", new { selectedTabId = AccountNavigationEnum.Auctions })
}

<div class="page account-page auction-list-page pl-lg-3 pt-3 pt-lg-0">
    <h1 class="h2 generalTitle">@Loc["Account.CustomerAuctions"]</h1>
    @if (Model.ProductBidList.Any())
    {
        <div>
            <b-tabs content-class="mt-3">
                <b-tab title="@Loc["Account.Auctions.Tab.Ongoing"]" active>
                    @if (Model.ProductBidList.Where(x => !x.Ended).Any())
                    {
                        <div id="auction-table-ongoing" class="table-responsive">
                            <table class="table">
                                <thead role="rowgroup">
                                    <tr role="row">
                                        <th role="columnheader"><div>@Loc["Account.CustomerAuctions.ProductName"]</div></th>
                                        <th role="columnheader"><div>@Loc["Account.CustomerAuctions.Status"]</div></th>
                                        <th role="columnheader"><div>@Loc["Account.CustomerAuctions.Highestbid"]</div></th>
                                        <th role="columnheader"><div>@Loc["Account.CustomerAuctions.AuctionEndTime"]</div></th>
                                    </tr>
                                </thead>
                                <tbody role="rowgroup">
                                    @{
                                        var ongoing = Model.ProductBidList.Where(x => !x.Ended);
                                    }
                                    @foreach (var item in ongoing)
                                    {
                                        <tr role="row">
                                            <td>
                                                <div><a href="@Url.RouteUrl("Product", new { SeName = item.ProductSeName })">@item.ProductName</a></div>
                                            </td>
                                            @if (item.HighestBidder)
                                            {
                                                <td>
                                                    <div>
                                                        <span class="text-success">@Loc["Account.CustomerAuctions.Status.HighestBidder"]</span>
                                                    </div>
                                                </td>
                                            }
                                            else
                                            {
                                                <td>
                                                    <div>
                                                        <span class="text-danger">@Loc["Account.CustomerAuctions.Status.Outbid"]</span>
                                                    </div>
                                                </td>
                                            }
                                            <td>
                                                <div>
                                                    @item.CurrentBidAmount @if (item.CurrentBidAmountValue > item.BidAmountValue)
                                                    {<small>(@item.BidAmount)</small>}
                                                </div>
                                            </td>
                                            <td>
                                                <div>@item.EndBidDate</div>
                                            </td>
                                        </tr>
                                     }
                                    </tbody>
                            </table>
                        </div>
                    }
                    else
                    {
                        <div class="no-data alert alert-info">
                            @Loc["Account.Auctions.NoOngoingAuctions"]
                        </div>
                    }
                </b-tab>
                <b-tab title="@Loc["Account.Auctions.Tab.Ended"]">
                    @if (Model.ProductBidList.Where(x => x.Ended).Any())
                    {

                        <div id="auction-table-ended" class="table-responsive">
                            <table class="table">
                                <thead role="rowgroup">
                                    <tr role="row">
                                        <th role="columnheader"><div>@Loc["Account.CustomerAuctions.ProductName"]</div></th>
                                        <th role="columnheader"><div>@Loc["Account.CustomerAuctions.Status"]</div></th>
                                        <th role="columnheader"><div>@Loc["Account.CustomerAuctions.Highestbid"]</div></th>
                                        <th role="columnheader"><div>@Loc["Account.CustomerAuctions.AuctionEndTime"]</div></th>
                                    </tr>
                                </thead>
                                <tbody role="rowgroup">
                                        @{
                                            var ended = Model.ProductBidList.Where(x => x.Ended);
                                        }

                                        @foreach (var item in ended)
                                        {
                                            <tr role="row">
                                                <td>
                                                    <div><a href="@Url.RouteUrl("Product", new { SeName = item.ProductSeName })">@item.ProductName</a></div>
                                                </td>
                                                @if (item.HighestBidder)
                                                {
                                                    <td>
                                                        <div>
                                                            <span class="text-success">@Loc["Account.CustomerAuctions.Status.HighestBidder"]</span>
                                                        </div>
                                                    </td>
                                                }
                                                else
                                                {
                                                    <td>
                                                        <div>
                                                            <span class="text-danger">@Loc["Account.CustomerAuctions.Status.Outbid"]</span>
                                                        </div>
                                                    </td>
                                                }
                                                <td>
                                                    <div>
                                                        @item.CurrentBidAmount @if (item.CurrentBidAmountValue > item.BidAmountValue)
                                                        {<small>(@item.BidAmount)</small>}
                                                    </div>
                                                </td>
                                                <td>
                                                    <div>@item.EndBidDate</div>
                                                </td>
                                            </tr>
                                        }
                                </tbody>
                            </table>
                        </div>
                    }
                    else
                    {
                        <div class="no-data alert alert-info">
                            @Loc["Account.Auctions.NoOngoingAuctions"]
                        </div>
                    }
                </b-tab>
            </b-tabs>
        </div>
    }
    else
    {
        <div class="no-data alert alert-info">
            @Loc["Account.Auctions.NoAuctions"]
        </div>
    }
</div>