{% from "upload/attachments.html" import attachment %}
<div class="user-section">
  <div class="avatar{% if user == answer.creator %} self{% endif %}{% if question.creator == answer.creator %} owner{% endif %}">
    <a href="{{ profile_url(answer.creator) }}">
      <img src="{{ profile_avatar(answer.creator) }}" height="48" width="48" alt="{{ answer.creator }}"/>
      {% if user == answer.creator %}
        <span>{{ _('You') }}</span>
      {% elif question.creator == answer.creator %}
        <span>{{ _('Owner') }}</span>
      {% endif %}
    </a>
  </div>
  <div class="asked-by">
    <a href="{{ profile_url(answer.creator) }}">{{ answer.creator }}</a>
  </div>
  <div class="asked-on">
    {{ answer.created|timesince }}
  </div>
</div>
<div class="main-section">
  <div class="content">
    {{ answer.content_parsed|safe }}
    <div class="stem"></div>{# for the speech bubble arrow #}
  </div>
  <div class="ans-attachments attachments-list">
    {% for image in answer.images.all() %}
      {{ attachment(image, user) }}
    {% endfor %}
  </div>
  {% if answer.updated_by %}
    <p class="edited">
      {{ _('Modified {datetime} by {name}')|fe(name=answer.updated_by.username, datetime=datetimeformat(answer.updated, format='longdatetime')) }}
    </p>
  {% endif %}
  <div class="meta">
    {% if question.solution == answer %}
      <span class="solved">{{ _('Solution chosen by {author}')|f(author=question.creator) }}</span>
    {% endif %}
    {% if answer.num_votes != 0 %}
      <span class="helpful">
        {{ ngettext('{count} out of 1 person found this reply helpful',
                    '{count} out of {total} people found this reply helpful',
                    answer.num_votes)|f(count=answer.num_helpful_votes, total=answer.num_votes) }}
      </span>
    {% endif %}
    {% if answer.id and not question.is_locked %}
      <a class="reply" href="#question-reply">{{ _('Reply') }}</a>
    {% endif %}
  </div>
</div>
<div class="side-section">
  {% if answer.creator != question.creator %}
    {% if not question.is_locked %}
      {% if not question.solution and user == question.creator %}
        <h4>{{ _('Did this solve your problem?') }}</h4>
        <form class="helpful" action="{{ url('questions.solution', question_id=question.id, answer_id=answer.id) }}" method="post">
          {{ csrf() }}
          <input type="submit" class="btn" name="solution" value="{{ _('Solved It') }}" />
        </form>
      {% elif not answer.has_voted(request) and user != question.creator and user != answer.creator %}
        <h4>{{ _('Was this reply helpful?') }}</h4>
        <form class="helpful" action="{{ url('questions.answer_vote', question_id=question.id, answer_id=answer.id) }}" method="post">
          {{ csrf() }}
          <input type="submit" class="btn" name="helpful" value="{{ _('Helpful') }}" />
          <input type="submit" class="btn" name="not-helpful" value="{{ _('Not Helpful') }}" />
        </form>
      {% endif %}
    {% endif %}
  {% endif %}

  <ul class="actions">
    {% if answer.id and not question.is_locked and has_perm_or_owns('questions.change_answer', answer, answer) %}
      <li class="edit">
        <a href="{{ url('questions.edit_answer', question.id, answer.id) }}">{{ _('Edit this post') }}</a>
      </li>
    {% endif %}
    {% if answer.id and user.has_perm('questions.delete_answer') %}
      <li class="delete">
        <a href="{{ url('questions.delete_answer', question.id, answer.id) }}">{{ _('Delete this post') }}</a>
      </li>
    {% endif %}
  </ul>

  {% if user.is_authenticated() and user != answer.creator and not question.is_locked  %}
    <form class="report" action="{{ url('questions.answer_flag', question.id, answer.id) }}" method="post">
      {% include 'questions/includes/flag_form.html' %}
    </form>
  {% endif %}
</div>
