{% extends "admin/base_admin.html" %}
{% set admin_page = "templates" %}

{% block title %}Content Templates - Admin - {{ config.APP_NAME }}{% endblock %}

{% block admin_content %}
  <header class="flex justify-between items-center mb-8">
    <div>
      <h1 class="text-2xl">Content Templates</h1>
      <p class="text-slate text-sm">{{ templates | length }} template{{ 's' if templates | length != 1 }} (scanned from git)</p>
    </div>
    <a href="{{ url_for('admin.index') }}" class="btn-outline">Back</a>
  </header>

  <div class="card">
    {% if templates %}
    <table class="table">
      <thead>
        <tr>
          <th>Name</th>
          <th>Slug</th>
          <th>Type</th>
          <th>Data Table</th>
          <th>Data Rows</th>
          <th>Generated</th>
          <th>Languages</th>
          <th></th>
        </tr>
      </thead>
      <tbody>
        {% for t in templates %}
        <tr>
          <td><a href="{{ url_for('admin.template_detail', slug=t.slug) }}">{{ t.name }}</a></td>
          <td class="mono text-sm">{{ t.slug }}</td>
          <td><span class="badge">{{ t.content_type }}</span></td>
          <td class="mono text-sm">{{ t.data_table }}</td>
          <td class="mono">{{ t.data_count }}</td>
          <td class="mono">{{ t.generated_count }}</td>
          <td class="text-sm">{{ t.languages | join(', ') }}</td>
          <td class="text-right">
            <a href="{{ url_for('admin.template_generate', slug=t.slug) }}" class="btn btn-sm">Generate</a>
          </td>
        </tr>
        {% endfor %}
      </tbody>
    </table>
    {% else %}
    <p class="text-slate text-sm">No templates found. Add <code>.md.jinja</code> files to <code>content/templates/</code> in the repo.</p>
    {% endif %}
  </div>
{% endblock %}
