{% extends "base.html" %}
{% block body_class %}themed-bg{% endblock %}

{% block content %}
<div class="container">
  <h1 class="page-title">Scripture Normalizer — {{ applied|yesno:"Applied,Dry‑run" }}</h1>
  <p class="page-subtitle">
    {% if applied %}Changes have been written to the database.{% else %}Preview only — no data was changed.{% endif %}
    Changed entries: <strong>{{ changed }}</strong>. Warnings: <strong>{{ warnings_total }}</strong>.
  </p>

  <div class="card" style="padding:16px;">
    <div class="meta-label">Preview (first 100 changed rows)</div>
    <div class="small muted" style="margin:6px 0 10px;">Format: ID · old → new</div>
    <div style="display:grid; gap:10px;">
      {% for rid, old, new in preview %}
        <div style="padding:10px; border:1px solid var(--border); border-radius:12px; background:#fff;">
          <div class="small muted">ID {{ rid }}</div>
          <div><strong>Old:</strong> {{ old|default:"—" }}</div>
          <div><strong>New:</strong> {{ new|default:"—" }}</div>
        </div>
      {% empty %}
        <div class="muted">No changes detected for the selected scope.</div>
      {% endfor %}
    </div>

    <div style="margin-top:14px;">
      <a class="btn btn-secondary" href="{% url 'stats' %}">← Back to Statistics</a>
      {% if not applied and user.is_authenticated and user.is_staff %}
      <form method="post" action="{% url 'normalize_scripture' %}" style="display:inline;">
        {% csrf_token %}
        <button class="btn btn-danger" onclick="return confirm('Apply normalization to ALL entries now?');">Apply Now</button>
      </form>
      {% endif %}
    </div>
  </div>
</div>
{% endblock %}