{% extends "ui/templates/base/layout.html" %}
{% block content %}
<div class="space-y-6">
  <div class="flex items-start justify-between gap-4">
    <div>
      <h2 class="text-2xl font-semibold text-slate-900">Import Clients</h2>
      <p class="text-sm text-slate-500">Bulk upload clients for the active audit firm with partner validation.</p>
    </div>
    <a href="/clients/import/template" class="inline-flex rounded-xl border border-slate-300 px-4 py-2 text-sm font-medium text-slate-700 hover:bg-slate-50">Download Template</a>
  </div>

  <div class="rounded-2xl bg-white p-6 shadow-soft space-y-4">
    <div class="grid gap-4 md:grid-cols-2">
      <div class="rounded-xl border border-slate-200 bg-slate-50 p-4 text-sm text-slate-700">
        <div class="font-semibold text-slate-900">Active Audit Firm</div>
        <div class="mt-1">{{ current_tenant.name if current_tenant else scope.tenant_id }} (ID: {{ scope.tenant_id }})</div>
      </div>
      <div class="rounded-xl border border-slate-200 bg-slate-50 p-4 text-sm text-slate-700">
        <div class="font-semibold text-slate-900">Logged-in uploader</div>
        <div class="mt-1">{{ current_user.full_name or current_user.email }} — User ID {{ current_user.id }}</div>
      </div>
    </div>

    <div class="rounded-xl border border-sky-200 bg-sky-50 p-4 text-sm text-sky-900">
      Template includes <strong>uploader_user_id</strong>, <strong>firm_tenant_id</strong>, and <strong>partner_user_id</strong>.
      Validation checks that uploader_user_id matches the logged-in user, firm_tenant_id matches the active audit firm, and partner_user_id belongs to an active Partner in that same audit firm.
    </div>

    <div class="rounded-xl border border-slate-200 p-4">
      <div class="text-sm font-semibold text-slate-900">Partners available in this audit firm</div>
      <div class="mt-2 text-sm text-slate-600">
        {% for p in partners %}
          <div>{{ p.id }} — {{ p.full_name or p.email }}</div>
        {% else %}
          <div>No active partners found for this audit firm.</div>
        {% endfor %}
      </div>
    </div>

    {% if import_errors %}
    <div class="rounded-2xl border border-rose-200 bg-rose-50 px-4 py-3 text-sm text-rose-900">
      {% for err in import_errors %}<div>{{ err }}</div>{% endfor %}
    </div>
    {% endif %}

    <form method="post" action="/clients/import/preview" enctype="multipart/form-data" class="space-y-4">
      <input type="hidden" name="csrf_token" value="{{ csrf_token }}">
      <div>
        <label class="block text-sm font-medium text-slate-700">Excel file</label>
        <input type="file" name="excel_file" accept=".xlsx" class="mt-1 w-full rounded-xl border border-slate-300 px-4 py-2 text-sm" required>
      </div>
      <div class="flex justify-end gap-3">
        <a href="/clients" class="rounded-xl border border-slate-300 px-4 py-2 text-sm font-medium text-slate-700 hover:bg-slate-50">Back</a>
        <button class="rounded-xl bg-brand-600 px-4 py-2 text-sm font-medium text-white hover:bg-brand-700">Validate File</button>
      </div>
    </form>
  </div>
</div>
{% endblock %}
