{% if programs %}
{% for prog in programs %}
<tr id="prog-{{ prog.id }}">
  <td style="font-weight:500">
    {% if prog.homepage_url %}
    <a href="{{ prog.homepage_url }}" target="_blank" rel="noopener" style="color:#0F172A;text-decoration:none">{{ prog.name }}</a>
    {% else %}
    {{ prog.name }}
    {% endif %}
  </td>
  <td class="mono text-slate">{{ prog.slug }}</td>
  <td class="mono text-slate">{{ prog.tracking_tag or '—' }}</td>
  <td class="mono text-right">
    {% if prog.commission_pct %}{{ "%.0f" | format(prog.commission_pct) }}%{% else %}—{% endif %}
  </td>
  <td class="mono text-right">{{ prog.product_count }}</td>
  <td>
    <span class="badge {% if prog.status == 'active' %}badge-success{% else %}badge{% endif %}">
      {{ prog.status }}
    </span>
  </td>
  <td class="text-right" style="white-space:nowrap">
    <a href="{{ url_for('admin.affiliate_program_edit', program_id=prog.id) }}" class="btn-outline btn-sm">Edit</a>
    <form method="post" action="{{ url_for('admin.affiliate_program_delete', program_id=prog.id) }}" style="display:inline" hx-boost="true">
      <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
      <button type="submit" class="btn-outline btn-sm"
              onclick="return confirm('Delete this program?')">Delete</button>
    </form>
  </td>
</tr>
{% endfor %}
{% else %}
<tr>
  <td colspan="7" class="text-slate" style="text-align:center;padding:2rem;">No programs found.</td>
</tr>
{% endif %}
