@model IReadOnlyList<MemberCenter.Web.Areas.Admin.Models.NewsletterListIndexRowViewModel>

<div class="admin-page-title">
  <h1>@L["Newsletter Lists"]</h1>
@if (await AdminPermissionChecker.HasPermissionAsync(User, AdminPermissions.NewsletterListsCreate))
{
  <a class="account-action-button" href="/admin/newsletter-lists/create">@L["Add Newsletter"]</a>
}
</div>

<div class="data-table-shell">
  <table class="data-table">
    <thead>
      <tr>
        <th class="data-table-index">#</th>
        <th>@L["List ID"]</th>
        <th>@L["Newsletter name"]</th>
        <th>@L["Tenant"]</th>
        <th>@L["Active"]</th>
        <th>@L["Subscriptions"]</th>
        <th>@L["Action"]</th>
      </tr>
    </thead>
    <tbody>
    @if (!Model.Any())
    {
      <tr>
        <td colspan="7" class="data-table-empty">@L["No newsletter records."]</td>
      </tr>
    }
    else
    {
      var rowNumber = 1;
      foreach (var item in Model)
      {
        var list = item.NewsletterList;
        <tr>
          <td class="data-table-index">@rowNumber.ToString("000")</td>
          <td>@list.Id</td>
          <td>@list.Name</td>
          <td>@(string.IsNullOrWhiteSpace(list.TenantName) ? list.TenantId.ToString() : list.TenantName)</td>
          <td>@(list.Status.Equals("active", StringComparison.OrdinalIgnoreCase) ? "ON" : "OFF")</td>
          <td>@item.ActiveSubscriptionCount</td>
          <td>
            <div class="data-table-actions">
              <a class="data-table-pill-button" asp-action="Details" asp-route-id="@list.Id">@L["Detail"]</a>
              @if (await AdminPermissionChecker.HasPermissionAsync(User, AdminPermissions.NewsletterListsEdit))
              {
                <a class="data-table-pill-button" href="/admin/newsletter-lists/edit/@list.Id">@L["Edit"]</a>
              }
              @if (await AdminPermissionChecker.HasPermissionAsync(User, AdminPermissions.NewsletterListsDelete))
              {
                <form method="post" action="/admin/newsletter-lists/delete/@list.Id" class="data-table-action-form">
                  @Html.AntiForgeryToken()
                  <button type="submit" class="data-table-pill-button">@L["Delete"]</button>
                </form>
              }
            </div>
          </td>
        </tr>
        rowNumber++;
      }
    }
    </tbody>
  </table>
</div>
