{% extends "base.html" %}
{% block title %}Projects · CalMiner{% endblock %}

{% block head_extra %}
  <link rel="stylesheet" href="/static/css/projects.css" />
{% endblock %}

{% block content %}
  <section class="page-header">
    <div>
      <h1>Projects</h1>
      <p class="text-muted">Manage mining projects and explore their scenarios.</p>
    </div>
    <div class="actions">
      <input
        type="search"
        class="form-control"
        placeholder="Filter projects..."
        data-project-filter
      />
      <a class="btn btn-primary" href="{{ url_for('projects.create_project_form') }}">New Project</a>
    </div>
  </section>

  {% if projects %}
    <table class="projects-table" data-project-table>
      <thead>
        <tr>
          <th>Name</th>
          <th>Location</th>
          <th>Type</th>
          <th>Scenarios</th>
          <th></th>
        </tr>
      </thead>
      <tbody>
        {% for project in projects %}
          <tr>
            <td class="table-cell-actions">
              {{ project.name }}
              <button
                class="btn btn-ghost"
                data-export-trigger
                data-export-target="projects"
                title="Export projects dataset"
              >
                <span aria-hidden="true">⇩</span>
                <span class="sr-only">Export</span>
              </button>
            </td>
            <td>{{ project.location or '—' }}</td>
            <td>{{ project.operation_type.value.replace('_', ' ') | title }}</td>
            <td>{{ project.scenario_count }}</td>
            <td class="text-right">
              <a class="btn btn-link" href="{{ url_for('projects.view_project', project_id=project.id) }}">View</a>
              <a class="btn btn-link" href="{{ url_for('projects.edit_project_form', project_id=project.id) }}">Edit</a>
            </td>
          </tr>
        {% endfor %}
      </tbody>
    </table>
  {% else %}
    <p>No projects yet. <a href="{{ url_for('projects.create_project_form') }}">Create your first project.</a></p>
  {% endif %}
{% endblock %}
