@inherits ViewModelTemplate<OrderListViewModel>
@using Dynamicweb.Rendering
@using Dynamicweb.Frontend
@using Dynamicweb.Ecommerce.Frontend
@using System.Globalization

<div class="fs-3 fw-bold">@(Model?.TotalOrdersCount ?? 0)</div>

@if(Model?.Orders?.Count > 0)
{
    if(Model.Orders.Select(o => o.Price.CurrencyCode).Distinct().Count() == 1)
    {
        string FormatTotal(double value, string currencyCode)
        {
            return Dynamicweb.Ecommerce.Services.Currencies.Format(Dynamicweb.Ecommerce.Services.Currencies?.GetCurrency(currencyCode) ?? Dynamicweb.Ecommerce.Common.Context.Currency, value);
        }
        <div class="fs-8 text-muted text-price">@(FormatTotal(Model.Orders.Sum(o => o.Price.Price), Model.Orders.First().Price.CurrencyCode)) @Translate("total value")</div>
    }
    else 
    {
        <div class="fs-8 text-muted">@Translate("Cannot display total in multiple currencies")</div>
    }
}