{% extends "ui/templates/base/layout.html" %}
{% block content %}
<div class="space-y-6">
  <div class="flex flex-wrap items-center justify-between gap-3">
    <div>
      <h2 class="text-xl font-semibold text-slate-900">Consultants</h2>
      <p class="text-sm text-slate-500">Portal-enabled consultants, franchise partners, and external ecosystem collaborators.</p>
    </div>
    <div class="flex flex-wrap gap-2">
      {% if can_manage_consultant_service_requests(current_user, current_user_permissions, current_user_roles) %}
      <a href="/consultants/service-requests" class="inline-flex rounded-xl border border-slate-300 px-4 py-2 text-sm font-semibold text-slate-700 hover:bg-slate-50">Service Requests</a>
      {% endif %}
      {% if can_manage_consultant_conversions(current_user, current_user_permissions, current_user_roles) %}
      <a href="/consultants/conversion-requests" class="inline-flex rounded-xl border border-slate-300 px-4 py-2 text-sm font-semibold text-slate-700 hover:bg-slate-50">Conversions</a>
      {% endif %}
      {% if can_manage %}
      <a href="/consultants/new" class="inline-flex rounded-xl bg-brand-600 px-4 py-2 text-sm font-semibold text-white shadow-soft hover:bg-brand-700">Add Consultant</a>
      {% endif %}
    </div>
  </div>

  <form method="get" class="rounded-2xl border border-slate-200 bg-white p-4 shadow-soft">
    <div class="grid gap-3 md:grid-cols-[1fr_auto_auto]">
      <input name="q" value="{{ q or '' }}" placeholder="Search by name, firm, email, mobile, specialisation" class="rounded-xl border border-slate-300 px-3 py-2 text-sm">
      <label class="inline-flex items-center gap-2 rounded-xl border border-slate-300 px-3 py-2 text-sm text-slate-700">
        <input type="checkbox" name="include_inactive" value="1" {% if include_inactive %}checked{% endif %}> Include inactive
      </label>
      <button class="rounded-xl border border-slate-300 px-4 py-2 text-sm font-semibold text-slate-700 hover:bg-slate-50">Filter</button>
    </div>
  </form>

  <div class="overflow-hidden rounded-2xl border border-slate-200 bg-white shadow-soft">
    <table class="min-w-full divide-y divide-slate-200 text-sm">
      <thead class="bg-slate-50 text-left text-xs font-semibold uppercase tracking-wide text-slate-500">
        <tr>
          <th class="px-4 py-3">Consultant</th>
          <th class="px-4 py-3">Contact</th>
          <th class="px-4 py-3">Type</th>
          <th class="px-4 py-3">Specialisation</th>
          <th class="px-4 py-3">Status</th>
          <th class="px-4 py-3 text-right">Action</th>
        </tr>
      </thead>
      <tbody class="divide-y divide-slate-100">
        {% for row in rows %}
        <tr class="hover:bg-slate-50">
          <td class="px-4 py-3">
            <div class="font-semibold text-slate-900">{{ row.contact_person }}</div>
            <div class="text-xs text-slate-500">{{ row.firm_name or 'Individual consultant' }}</div>
          </td>
          <td class="px-4 py-3 text-slate-600">
            <div>{{ row.email or '-' }}</div>
            <div class="text-xs">{{ row.mobile or '-' }}</div>
          </td>
          <td class="px-4 py-3 text-slate-600">{{ row.consultant_type.replace('_', ' ').title() }}</td>
          <td class="px-4 py-3 text-slate-600">{{ row.specialisation or '-' }}</td>
          <td class="px-4 py-3">
            <span class="rounded-full px-2 py-1 text-xs font-semibold {% if row.is_active %}bg-emerald-50 text-emerald-700{% else %}bg-slate-100 text-slate-500{% endif %}">{{ row.status }}</span>
          </td>
          <td class="px-4 py-3 text-right">
            <a href="/consultants/{{ row.id }}" class="rounded-lg border border-slate-300 px-3 py-1.5 text-xs font-semibold text-slate-700 hover:bg-slate-50">Open</a>
          </td>
        </tr>
        {% else %}
        <tr><td colspan="6" class="px-4 py-8 text-center text-slate-500">No consultants found.</td></tr>
        {% endfor %}
      </tbody>
    </table>
  </div>
</div>
{% endblock %}
