{% extends "base.html" %}

{% block content %}
  <section class="section">
    <div class="container">
      <h1 class="title is-4">Business Plan Editor</h1>
      <p class="subtitle is-6">{{ document.source_service }} · {{ document.source_channel_identifier }}</p>

      <article class="box">
        <form method="post">
          {% csrf_token %}
          <div class="columns">
            <div class="column is-8">
              <label class="label is-size-7">Title</label>
              <input class="input" name="title" value="{{ document.title }}">
            </div>
            <div class="column is-4">
              <label class="label is-size-7">Status</label>
              <div class="select is-fullwidth">
                <select name="status">
                  <option value="draft" {% if document.status == 'draft' %}selected{% endif %}>draft</option>
                  <option value="final" {% if document.status == 'final' %}selected{% endif %}>final</option>
                </select>
              </div>
            </div>
          </div>
          <label class="label is-size-7">Content (Markdown)</label>
          <textarea class="textarea" name="content_markdown" rows="18">{{ document.content_markdown }}</textarea>
          <div class="buttons" style="margin-top: 0.75rem;">
            <button class="button is-link" type="submit">Save Revision</button>
            <a class="button is-light" href="{% url 'business_plan_inbox' %}">Back To Inbox</a>
          </div>
        </form>
      </article>

      <article class="box">
        <h2 class="title is-6">Revisions</h2>
        <table class="table is-fullwidth is-striped is-size-7">
          <thead>
            <tr><th>Created</th><th>Editor</th><th>Excerpt</th></tr>
          </thead>
          <tbody>
            {% for row in revisions %}
              <tr>
                <td>{{ row.created_at }}</td>
                <td>{{ row.editor_user.username }}</td>
                <td>{{ row.content_markdown|truncatechars:180 }}</td>
              </tr>
            {% empty %}
              <tr><td colspan="3">No revisions yet.</td></tr>
            {% endfor %}
          </tbody>
        </table>
      </article>
    </div>
  </section>
{% endblock %}
