{% extends 'base.html' %}

{% set meta = poem %}

{% block extra_scripts %}
  {% script 'poem' %}
{% endblock extra_scripts %}

{% block content %}
{% include "includes/nav.html" %}
<article>
  {% if poem.titled %}
  <header class="poem--title">
    <h1>{{ poem.title }}</h1>
  </header>
  {% endif %}
  <section id="poem"
           class="poem{% if poem.nowrap %} nowrap{% endif %}{% if poem.justify %} justify{% endif %}{%if not poem.titled %} untitled{% endif %}"
           data-book-slug="{{ book.slug }}"
           data-poem-slug="{{ poem.slug }}">
    {% for stanza in poem.text|parsePoem -%}
    <p class="stanza">
    {% for line in stanza -%}
      <span class="line" {% if line.number %}data-line-number="{{ line.number }}"{% endif %}>{{ line.text|formatLine }}</span><br/>
    {% endfor %}
    </p>
    {% endfor %}
  </section>
</article>
{% endblock content %}

{% block footer -%}
<footer class="footer">
  <div class="break footer"></div>
  <p>This poem was first published{%if not poem.titled %} as “{{ poem.title }}”{% endif %} in “<a href="/book/{{ book.slug }}/">{{ book.title }}</a>.”
     {% if poem.previous_poem.slug or poem.next_poem.slug %}
     {% if poem.previous_poem.slug %}
        The previous poem is “<a href="/book/{{ book.slug }}/poem/{{ poem.previous_poem.slug }}/">{{ poem.previous_poem.title }}</a>.”
     {% endif %}
     {% if poem.next_poem.slug %}
        The next poem is “<a href="/book/{{ book.slug }}/poem/{{ poem.next_poem.slug }}/">{{ poem.next_poem.title }}</a>.”
     {% endif %}
     {% endif %}
  </p>
  <p>
     The text is also available in <a href="{{ poem.json_url }}">json</a> and <a href="{{ poem.txt_url }}">text</a> formats.
     Please <a href="https://github.com/ee-cummings-archive/cummings.ee/blob/master/CONTRIBUTING.md#reporting-an-error">report any errors</a>.
  </p>
  <p>
    <form id="nowrap-form">
        <label>Allow line wrapping:</label>
        <input id="radio-wrap-yes" type="radio" name="wrap" value="yes" {% if not poem.nowrap %}CHECKED{% endif %}> <label for="radio-wrap-yes">Yes</label>
        <input id="radio-wrap-no" type="radio" name="wrap" value="no" {% if poem.nowrap %}CHECKED{% endif %}> <label for="radio-wrap-no">No</label>
    </form>
  </p>
  <p>
   {{ footer.copy }}
  </p>
</footer>
{% endblock footer -%}
