@model MemberCenter.Web.Models.TenantNewsletters.TenantNewsletterManagementViewModel
@{
    ViewData["Title"] = L["Newsletter Management"];
}

<div class="tenant-newsletter-page">
  @if (Model.Tenants.Count > 1)
  {
    <form method="get" class="tenant-newsletter-filter">
      <label for="tenantId">@L["Tenant"]</label>
      <select id="tenantId" name="tenantId" onchange="this.form.submit()">
        <option value="">@L["All tenants"]</option>
        @foreach (var tenant in Model.Tenants)
        {
          if (Model.SelectedTenantId == tenant.Id)
          {
            <option value="@tenant.Id" selected>@tenant.Name</option>
          }
          else
          {
            <option value="@tenant.Id">@tenant.Name</option>
          }
        }
      </select>
    </form>
  }

  @if (!Model.Groups.Any())
  {
    <section class="tenant-newsletter-empty">
      <p>@L["No newsletters yet."]</p>
    </section>
  }
  else
  {
    <div class="tenant-newsletter-management-list">
      @foreach (var group in Model.Groups)
      {
        <section class="tenant-newsletter-management-group">
          @if (Model.Tenants.Count > 1 && !Model.SelectedTenantId.HasValue)
          {
            <h2>@group.TenantName</h2>
          }

          @foreach (var newsletter in group.Newsletters)
          {
            <a class="tenant-newsletter-management-row" asp-action="Details" asp-route-id="@newsletter.Id">
              <article class="tenant-newsletter-management-card">
                <h3>@newsletter.Name</h3>
                <p>@newsletter.TenantName</p>
              </article>

              <div class="tenant-newsletter-management-metrics" aria-label="@L["Newsletter metrics"]">
                <section class="tenant-newsletter-metric-card">
                  <span>@L["Subscriptions"]</span>
                  <strong>@newsletter.ActiveSubscriptionCount</strong>
                </section>
                <section class="tenant-newsletter-metric-card">
                  <span>@L["Unsubscribed"]</span>
                  <strong>@newsletter.UnsubscribedCount</strong>
                </section>
              </div>
            </a>
          }
        </section>
      }
    </div>
  }
</div>
