{# plugins/submission/templates/submission/view.html #}
{% extends 'core/base.html' %}

{% block content %}
<div class="container mt-4">
  <h2>Submission Details</h2>
  <dl class="row">
    <dt class="col-sm-3">Type:</dt>
    <dd class="col-sm-9">
      {{ submission.submission_type.replace('_', ' ').title() }}
    </dd>

    <dt class="col-sm-3">Common Name:</dt>
    <dd class="col-sm-9">
      {% if submission.plant_name %}
        {{ submission.plant_name }}
      {% else %}
        &mdash;
      {% endif %}
    </dd>

    <dt class="col-sm-3">Scientific Name:</dt>
    <dd class="col-sm-9">
      {% if submission.scientific_name %}
        {{ submission.scientific_name }}
      {% else %}
        &mdash;
      {% endif %}
    </dd>

    {% if submission.submission_type == 'market_price' %}
      <dt class="col-sm-3">Price:</dt>
      <dd class="col-sm-9">${{ '%.2f' % submission.price }}</dd>
      <dt class="col-sm-3">Source:</dt>
      <dd class="col-sm-9">{{ submission.source or '&mdash;' }}</dd>
    {% endif %}

    {% if submission.submission_type == 'vendor_rating' %}
      <dt class="col-sm-3">Vendor Name:</dt>
      <dd class="col-sm-9">{{ submission.vendor_name }}</dd>
      <dt class="col-sm-3">Rating:</dt>
      <dd class="col-sm-9">{{ submission.rating }} / 5</dd>
    {% endif %}

    {% if submission.submission_type == 'vendor_alias' %}
      <dt class="col-sm-3">Old Vendor:</dt>
      <dd class="col-sm-9">{{ submission.old_vendor }}</dd>
      <dt class="col-sm-3">New Vendor Alias:</dt>
      <dd class="col-sm-9">{{ submission.new_vendor }}</dd>
      <dt class="col-sm-3">Alias Reason:</dt>
      <dd class="col-sm-9">{{ submission.alias_reason or '&mdash;' }}</dd>
    {% endif %}

    <dt class="col-sm-3">Notes:</dt>
    <dd class="col-sm-9">{{ submission.notes or '&mdash;' }}</dd>

    <dt class="col-sm-3">Submitted At:</dt>
    <dd class="col-sm-9">
      {{ submission.submitted_at.strftime('%Y-%m-%d %H:%M') }}
    </dd>

    <dt class="col-sm-3">Status:</dt>
    <dd class="col-sm-9">
      {% if submission.approved is none %}
        <span class="badge bg-warning">Pending</span>
      {% elif submission.approved %}
        <span class="badge bg-success">Approved</span>
      {% else %}
        <span class="badge bg-danger">Rejected</span>
      {% endif %}
    </dd>
  </dl>

  <h4>Images</h4>
  <div class="row">
    {% if images %}
      {% for img in images %}
        <div class="col-md-3 mb-3">
          <div class="card shadow-sm">
            <a href="{{ generate_image_url(img) }}" target="_blank">
              <img
                src="{{ generate_image_url(img) }}"
                class="card-img-top"
                alt="Submission Image"
              >
            </a>
            <div class="card-body p-2">
              <p class="card-text text-center">
                <small class="text-muted">{{ img.uploaded_at.strftime('%Y-%m-%d') }}</small>
              </p>
            </div>
          </div>
        </div>
      {% endfor %}
    {% else %}
      <p>No images uploaded.</p>
    {% endif %}
  </div>

  <div class="mt-3">
    <a href="{{ url_for('submission.list_submissions') }}" class="btn btn-secondary">Back to List</a>
  </div>
</div>
{% endblock %}
