@model IReadOnlyList<MemberCenter.Application.Models.Admin.TenantDto>

<div class="admin-page-title">
  <h1>@L["Tenants"]</h1>
@if (await AdminPermissionChecker.HasPermissionAsync(User, AdminPermissions.TenantsCreate))
{
  <a class="account-action-button" href="/admin/tenants/create">@L["Add Tenant"]</a>
}
</div>

<div class="data-table-shell">
  <table class="data-table">
    <thead>
      <tr>
        <th class="data-table-index">#</th>
        <th>@L["Name"]</th>
        <th>@L["Tenant ID"]</th>
        <th>@L["Webhook Client ID"]</th>
        <th>@L["Domains"]</th>
        <th>@L["Status"]</th>
        <th>@L["Action"]</th>
      </tr>
    </thead>
    <tbody>
    @if (!Model.Any())
    {
      <tr>
        <td colspan="7" class="data-table-empty">@L["No tenant records."]</td>
      </tr>
    }
    else
    {
      var rowNumber = 1;
      foreach (var tenant in Model)
      {
        <tr>
          <td class="data-table-index">@rowNumber.ToString("000")</td>
          <td>@tenant.Name</td>
          <td>@tenant.Id</td>
          <td>@(tenant.SendEngineWebhookClientId?.ToString() ?? "-")</td>
          <td>@string.Join(", ", tenant.Domains)</td>
          <td>@tenant.Status</td>
          <td>
            <div class="data-table-actions">
              <a class="data-table-pill-button" asp-action="Details" asp-route-id="@tenant.Id">@L["Detail"]</a>
              @if (await AdminPermissionChecker.HasPermissionAsync(User, AdminPermissions.TenantsEdit))
              {
                <a class="data-table-pill-button" href="/admin/tenants/edit/@tenant.Id">@L["Edit"]</a>
              }
              @if (await AdminPermissionChecker.HasPermissionAsync(User, AdminPermissions.TenantsDelete))
              {
                <form method="post" action="/admin/tenants/delete/@tenant.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>
