{% extends "portal_base.html" %}

{% block title %}Project Dashboard{% endblock %}
{% block portal_title %}Welcome back{% if user.first_name %}, {{ user.first_name }}{% endif %}.{% endblock %}
{% block portal_subtitle %}Manage your research and technology projects from one focused workspace.{% endblock %}
{% block portal_actions %}<a href="{% url 'projects:create' %}" class="btn-primary">Start a new brief <span aria-hidden="true">→</span></a>{% endblock %}

{% block portal_content %}
<section class="dashboard-metrics" aria-label="Workspace summary">
  <article class="metric-card">
    <div class="metric-card__top"><span class="metric-card__icon">P</span><span class="metric-card__trend">Portfolio</span></div>
    <strong>{{ page_obj.paginator.count|default:0 }}</strong>
    <span>Total project brief{{ page_obj.paginator.count|pluralize }}</span>
  </article>
  <article class="metric-card">
    <div class="metric-card__top"><span class="metric-card__icon metric-card__icon--gold">R</span><span class="metric-card__trend">Structured</span></div>
    <strong>4 steps</strong>
    <span>From scientific scope to delivery</span>
  </article>
  <article class="metric-card">
    <div class="metric-card__top"><span class="metric-card__icon metric-card__icon--green">✓</span><span class="metric-card__trend">Private</span></div>
    <strong>Secure</strong>
    <span>Visible only to you and Tecvico</span>
  </article>
</section>

<section class="dashboard-panel" id="project-briefs" aria-labelledby="recent-projects-title">
  <div class="dashboard-panel__header">
    <div><h2 id="recent-projects-title">Your project briefs</h2><p>Track submissions, quotes, and delivery progress.</p></div>
    {% if briefs %}<span class="dashboard-panel__count">{{ page_obj.paginator.count }} total</span>{% endif %}
  </div>
  {% if briefs %}
  <div class="portal-table-wrap">
    <table class="portal-table">
      <thead><tr><th>Project</th><th>Field</th><th>Status</th><th>Budget</th><th>Submitted</th><th><span class="sr-only">Actions</span></th></tr></thead>
      <tbody>
        {% for brief in briefs %}
        <tr>
          <td><a class="project-title-link" href="{% url 'projects:detail' pk=brief.pk %}">{{ brief.title }}</a></td>
          <td>{% if brief.category %}{{ brief.get_category_display }}{% else %}<span class="table-muted">Not set</span>{% endif %}</td>
          <td><span class="status-pill status-pill--{{ brief.status }}">{{ brief.get_status_display }}</span></td>
          <td>{% if brief.budget_range %}{{ brief.get_budget_range_display }}{% else %}<span class="table-muted">Not set</span>{% endif %}</td>
          <td>{{ brief.submitted_at|date:"M j, Y" }}</td>
          <td><a href="{% url 'projects:detail' pk=brief.pk %}" class="table-action" aria-label="View {{ brief.title }}">View <span aria-hidden="true">→</span></a></td>
        </tr>
        {% endfor %}
      </tbody>
    </table>
  </div>
  {% if page_obj.has_other_pages %}<div class="portal-pagination">{% if page_obj.has_previous %}<a href="?page={{ page_obj.previous_page_number }}" class="portal-link">Previous</a>{% endif %}<span>Page {{ page_obj.number }} of {{ page_obj.paginator.num_pages }}</span>{% if page_obj.has_next %}<a href="?page={{ page_obj.next_page_number }}" class="portal-link">Next</a>{% endif %}</div>{% endif %}
  {% else %}
  <div class="portal-empty">
    <div class="portal-empty__symbol" aria-hidden="true">+</div>
    <h3>Create your first project brief</h3>
    <p>Define the scientific challenge, goals, timeline, and supporting materials. You can review everything before submitting.</p>
    <a href="{% url 'projects:create' %}" class="btn-primary">Create project brief</a>
  </div>
  {% endif %}
</section>
{% endblock %}
