{% extends 'admin_frontend/base.html' %}
{% load tailwind_filters %}
{% block title %}Opportunities{% endblock %}
{% block content %}
<div class="flex items-center justify-between mb-4">
  <h1 class="text-2xl font-semibold">Opportunities</h1>
  <details class="relative">
    <summary class="cursor-pointer px-3 py-2 bg-blue-600 text-white rounded">New</summary>
    <div class="absolute right-0 mt-2 bg-white shadow rounded p-4 w-80">
      {% include 'admin_frontend/_form.html' with form=form submit_label='Create' %}
    </div>
  </details>
</div>

<div class="bg-white rounded shadow p-4 mb-4">
  {% load crispy_forms_tags %}
  <form method="get" class="space-y-3 flex gap-2">
    {{ filter.form|crispy }}
    <div class="flex items-center gap-2">
      <button class="px-3 py-2 bg-blue-600 text-white rounded">Filter</button>
      <a href="{% url 'admin_frontend:opportunities_list' %}" class="btn-outline">Reset</a>
    </div>
  </form>
  {% if filter.qs.count != page_obj.paginator.count %}
    <p class="text-sm text-gray-500 mt-2">Filtered results: {{ page_obj.paginator.count }} items</p>
  {% endif %}
</div>
<div class="bg-white rounded shadow overflow-hidden">
  <table class="min-w-full divide-y divide-gray-200">
    <thead class="bg-gray-50">
      <tr>
        <th class="px-4 py-2 text-left text-xs font-medium text-gray-500">Title</th>
        <th class="px-4 py-2 text-left text-xs font-medium text-gray-500">Description</th>
        <th class="px-4 py-2 text-left text-xs font-medium text-gray-500">Created</th>
      </tr>
    </thead>
    <tbody class="divide-y divide-gray-200">
      {% for o in opportunities %}
      <tr>
        <td class="px-4 py-2 font-medium">{{ o.title }}</td>
        <td class="px-4 py-2">{{ o.description }}</td>
        <td class="px-4 py-2 text-gray-500">{{ o.created_at }}</td>
      </tr>
      <tr>
        <td colspan="3" class="px-4 py-2">
          <div class="flex gap-2 justify-end">
            <a href="{% url 'admin_frontend:opportunity_edit' o.pk %}" class="btn-outline">Edit</a>
            <form method="post" action="{% url 'admin_frontend:opportunity_delete' o.pk %}" onsubmit="return confirm('Delete this opportunity?');">
              {% csrf_token %}
              <button class="btn-outline text-red-600">Delete</button>
            </form>
          </div>
        </td>
      </tr>
      {% empty %}
      <tr><td class="px-4 py-4 text-center text-gray-500" colspan="3">No opportunities yet.</td></tr>
      {% endfor %}
    </tbody>
  </table>
{% include 'admin_frontend/_pagination.html' %}
</div>
{% endblock %}
