{% extends 'core/base.html' %}
{% block content %}
<div class="container mt-4">
  <h2>Your Submissions</h2>

  <!-- Filter dropdown -->
  <form method="GET" class="row g-2 align-items-center mb-3">
    <div class="col-auto">
      <label for="filter_type" class="form-label">Filter by Type:</label>
    </div>
    <div class="col-auto">
      <select id="filter_type" name="type" class="form-select" onchange="this.form.submit()">
        {% for val, label in all_types %}
          <option value="{{ val }}" {% if selected_type == val %}selected{% endif %}>
            {{ label }}
          </option>
        {% endfor %}
      </select>
    </div>
    <div class="col-auto">
      <noscript><button type="submit" class="btn btn-primary">Apply</button></noscript>
    </div>
  </form>

  {% if submissions %}
    <ul class="list-group">
      {% for sub in submissions %}
        <li class="list-group-item d-flex justify-content-between align-items-center">
          <div>
            <strong>{{ sub.submission_type.replace('_', ' ').title() }}</strong>
            &mdash; {{ sub.plant_name or '--' }}
            {% if sub.submission_type == 'market_price' and sub.price is not none %}
              &middot; ${{ '%.2f' % sub.price }}
            {% elif sub.submission_type == 'vendor_rating' and sub.vendor_name %}
              &middot; Rated “{{ sub.vendor_name }}” ({{ sub.rating }}/5)
            {% elif sub.submission_type == 'vendor_alias' and sub.old_vendor %}
              &middot; Alias: “{{ sub.old_vendor }}” → “{{ sub.new_vendor }}”
            {% endif %}
            <br>
            <small class="text-muted">Submitted {{ sub.submitted_at.strftime('%Y-%m-%d %H:%M') }}</small>
          </div>
          <a href="{{ url_for('submission.view_submission', submission_id=sub.id) }}"
             class="btn btn-outline-primary btn-sm">View</a>
        </li>
      {% endfor %}
    </ul>
  {% else %}
    <p>You have no submissions that match this filter.</p>
  {% endif %}

  <div class="mt-3">
    <a href="{{ url_for('submission.new_submission') }}" class="btn btn-primary">New Submission</a>
  </div>
</div>
{% endblock %}
