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

{% block title %}Generate Articles - {{ config_data.name }} - Admin{% endblock %}

{% block admin_content %}
  <div style="max-width: 32rem; margin: 0 auto;">
    <a href="{{ url_for('admin.template_detail', slug=config_data.slug) }}" class="text-sm text-slate">&larr; Back to {{ config_data.name }}</a>
    <h1 class="text-2xl mt-4 mb-2">Generate Articles</h1>
    <p class="text-slate text-sm mb-6">
      {{ row_count }} data row{{ 's' if row_count != 1 }} available in
      <code>{{ config_data.data_table }}</code>
      &times; {{ config_data.languages | length }} language{{ 's' if config_data.languages | length != 1 }}
      = <strong>{{ row_count * config_data.languages | length }}</strong> articles.
    </p>

    {% if row_count == 0 %}
    <div class="card">
      <p class="text-slate text-sm">No data rows found. Run the data pipeline to populate <code>{{ config_data.data_table }}</code>.</p>
    </div>
    {% else %}
    <form method="post" class="card" hx-boost="true">
      <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">

      <div class="mb-4">
        <label class="form-label" for="start_date">Start Date</label>
        <input type="date" id="start_date" name="start_date" value="{{ today }}" class="form-input" required>
        <p class="form-hint">First batch of articles will be published on this date.</p>
      </div>

      <div class="mb-4">
        <label class="form-label" for="articles_per_day">Articles Per Day</label>
        <input type="number" id="articles_per_day" name="articles_per_day" value="3" min="1" max="50" class="form-input" required>
        <p class="form-hint">How many articles to publish per day. Remaining articles get staggered to following days.</p>
      </div>

      <div class="card" style="background: var(--color-soft-white); border: 1px dashed var(--color-mid-gray); margin-bottom: 1rem;">
        <p class="text-sm text-slate">
          This will generate up to <strong class="text-navy">{{ row_count * config_data.languages | length }}</strong> articles
          ({{ row_count }} rows &times; {{ config_data.languages | length }} languages).
          Existing articles with the same URL will be updated in-place.
          {% if config_data.priority_column %}
          Articles are ordered by <code>{{ config_data.priority_column }}</code> (highest first).
          {% endif %}
        </p>
      </div>

      <button type="submit" class="btn" style="width: 100%;"
              hx-confirm="Generate articles? Existing articles will be updated in-place.">
        Generate Articles
      </button>
    </form>
    {% endif %}
  </div>
{% endblock %}
