{{define "content"}}
<section class="hero">
  <p class="eyebrow">{{.Eyebrow}}</p>
  <h1>{{.Heading}}</h1>
  <p class="lede">{{.Description}}</p>
</section>

<section class="toolbar">
  <a class="button" href="/admin/api-keys/new">Create API key</a>
</section>

{{if .APIKeys}}
<section class="resource-grid">
  {{range .APIKeys}}
  <article class="resource-card">
    <div class="resource-header">
      <div>
        <h2><a href="/admin/api-keys/{{.APIKey.ID}}">{{.APIKey.Name}}</a></h2>
        <p class="resource-slug">{{.APIKey.KeyPrefix}}</p>
      </div>
      <span class="pill {{if .APIKey.IsActive}}pill-success{{else}}pill-muted{{end}}">
        {{if .APIKey.IsActive}}Active{{else}}Revoked{{end}}
      </span>
    </div>

    <p class="resource-description">{{if .APIKey.Description}}{{.APIKey.Description}}{{else}}No description yet.{{end}}</p>
    <p class="meta-line"><strong>Scope:</strong> <code>{{.APIKey.ScopeMode}}</code></p>
    <p class="meta-line"><strong>Rule rows:</strong> {{.ProjectRuleCount}} project, {{.TagRuleCount}} tag</p>
    <p class="meta-line"><strong>Permissions:</strong>
      {{if .APIKey.CanDownload}}download{{else}}no-download{{end}},
      {{if .APIKey.CanUpload}}upload{{else}}no-upload{{end}},
      {{if .APIKey.CanDelete}}delete{{else}}no-delete{{end}},
      {{if .APIKey.CanManageProjects}}manage-projects{{else}}no-manage-projects{{end}}
    </p>
    <p class="meta-line"><strong>Updated:</strong> {{.APIKey.UpdatedAt.Format "2006-01-02 15:04 UTC"}}</p>
    <p class="meta-line"><strong>Last used:</strong> {{if .APIKey.LastUsedAt}}{{.APIKey.LastUsedAt.Format "2006-01-02 15:04 UTC"}}{{else}}Never{{end}}</p>
    <p class="meta-line"><strong>Expires:</strong> {{if .APIKey.ExpiresAt}}{{.APIKey.ExpiresAt.Format "2006-01-02 15:04 UTC"}}{{else}}No expiry{{end}}</p>

    <a class="text-link" href="/admin/api-keys/{{.APIKey.ID}}">Open API key</a>
  </article>
  {{end}}
</section>
{{else}}
<section class="empty-state">
  <h2>No API keys yet</h2>
  <p>Create the first key to let client applications authenticate against the project, metadata, and download endpoints.</p>
</section>
{{end}}
{{end}}
