{% extends "ui/templates/base/layout.html" %}
{% block content %}
<div class="space-y-5">
  <div class="flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between">
    <div><h1 class="text-2xl font-semibold">Marketplace Leads</h1><p class="text-sm text-slate-500">Manage public leads and lead assignments.</p></div>
    {% if can_create %}<a href="/marketplace/leads/new" class="rounded-xl bg-brand-600 px-4 py-2 text-sm font-semibold text-white shadow-soft">New Lead</a>{% endif %}
  </div>
  <form method="get" class="flex flex-wrap gap-2 rounded-2xl border border-slate-200 bg-white p-4 shadow-soft">
    <input name="q" value="{{ q }}" placeholder="Search lead, contact, service" class="min-w-64 rounded-xl border border-slate-300 px-3 py-2 text-sm">
    <select name="status" class="rounded-xl border border-slate-300 px-3 py-2 text-sm"><option value="">All Status</option>{% for s in lead_statuses %}<option value="{{ s }}" {% if selected_status == s %}selected{% endif %}>{{ s }}</option>{% endfor %}</select>
    <button class="rounded-xl border border-slate-300 px-4 py-2 text-sm font-medium">Filter</button>
  </form>
  <div class="overflow-x-auto rounded-2xl border border-slate-200 bg-white shadow-soft">
    <table class="min-w-full text-sm">
      <thead><tr class="border-b bg-slate-50 text-left text-slate-600"><th class="px-4 py-3">Lead No</th><th>Lead</th><th>Service</th><th>Status</th><th>Priority</th><th>Assigned Audit Firm ID</th><th></th></tr></thead>
      <tbody>
        {% for row in rows %}
        <tr class="border-b last:border-0"><td class="px-4 py-3 font-medium">{{ row.lead_no }}</td><td>{{ row.lead_name }}<div class="text-xs text-slate-500">{{ row.business_name or '' }}</div></td><td>{{ row.service_requested }}</td><td>{{ row.status }}</td><td>{{ row.priority }}</td><td>{{ row.assigned_tenant_id or '-' }}</td><td><a href="/marketplace/leads/{{ row.id }}" class="text-brand-700">Open</a></td></tr>
        {% else %}<tr><td colspan="7" class="px-4 py-8 text-center text-slate-500">No leads found.</td></tr>{% endfor %}
      </tbody>
    </table>
  </div>
</div>
{% endblock %}
