{% extends 'main.html' %}
{% block title %} | Legacy CARES Import{% endblock %}

{% block content %}
<div class="container mt-3">

  <div class="row mb-2">
    <div class="col">
      <h4>
        <i class="bi bi-upload"></i>
        Legacy CARES Registration Import
        <span class="badge bg-warning text-dark ms-2">Staff Only</span>
        <span class="badge bg-secondary ms-1">Legacy Tool</span>
      </h4>
      <p class="text-muted mb-1">
        One-time import of historical CARES registration data.
        This tool operates independently of the standard Site 1 / Site 2 import routines
        and applies minimal validation by design.
      </p>
    </div>
  </div>

  <!-- Format reference card -->
  <div class="card border-info mb-4">
    <div class="card-header bg-info bg-opacity-10 fw-semibold">
      <i class="bi bi-info-circle"></i> Expected CSV Format
    </div>
    <div class="card-body">
      <p class="mb-1"><strong>Required header (exact column names):</strong></p>
      <code class="d-block mb-3 p-2 bg-light rounded">
        cares_member, cares_species, verified, source, breeding_group,
        acquisition_date, registration_date, email_address, club, last_update, notes
      </code>

      <p class="mb-1"><strong>Example data row:</strong></p>
      <code class="d-block mb-3 p-2 bg-light rounded" style="word-break:break-all;">
        Craig Storms, Melanotaenia parva, Y, Norwalk Aquarium Society auction,
        Y, 2025-01-01, 2025-06-18, craig_storms@yahoo.com, NECA, 2026-01-31,
      </code>

      <div class="row mt-2">
        <div class="col-md-6">
          <ul class="mb-0 small">
            <li><strong>Dates</strong> — <code>yyyy-mm-dd</code> (acquisition_date, registration_date, last_update)</li>
            <li><strong>verified</strong> — determines Approved vs Open status</li>
            <li><strong>breeding_group</strong> — truthy: <code>Y, y, Yes, yes, T, t, True, true</code></li>
          </ul>
        </div>
        <div class="col-md-6">
          <ul class="mb-0 small">
            <li><strong>club</strong> — matched by club acronym (case-insensitive)</li>
            <li><strong>cares_species</strong> — matched by exact species name (case-insensitive)</li>
            <li><strong>notes</strong> — accepted but not imported</li>
          </ul>
        </div>
      </div>

      <div class="alert alert-warning mt-3 mb-0 py-2 small">
        <i class="bi bi-exclamation-triangle-fill me-1"></i>
        <strong>All fields are required except <code>notes</code>.</strong>
        Rows with missing required fields, unresolved species names, or unrecognised club
        acronyms will be skipped and reported in the results.
      </div>
    </div>
  </div>

  <!-- Upload form -->
  <div class="card">
    <div class="card-header fw-semibold">
      <i class="bi bi-file-earmark-arrow-up"></i> Select CSV File
    </div>
    <div class="card-body">
      <form method="POST" enctype="multipart/form-data">
        {% csrf_token %}
        <div class="mb-3">
          {{ form.import_csv_file.label_tag }}
          {{ form.import_csv_file }}
          {% if form.import_csv_file.errors %}
            <div class="text-danger small mt-1">{{ form.import_csv_file.errors }}</div>
          {% endif %}
        </div>
        <button type="submit" class="btn btn-warning">
          <i class="bi bi-upload me-1"></i> Run Legacy Import
        </button>
        <a href="{% url 'tools2' %}" class="btn btn-outline-secondary ms-2">Cancel</a>
      </form>
    </div>
  </div>

</div>
{% endblock %}