<% content_for :title, "Edit Answer" %>

<h1><%= check_your_post_privilege(@answer, 'Edit') ? "Edit Answer" : "Suggest Edit for Answer" %></h1>
<% if @answer.errors.any? %>
  <div class="notice is-danger">
    <p>The following <%= "error".pluralize(@answer.errors.count) %> prevented the answer from being updated:</p>
    <ul>
      <% @answer.errors.full_messages.each do |e| %>
        <li><%= e %></li>
      <% end %>
    </ul>
  </div>
<% end %>

<%= render 'posts/markdown_script' %>
<%= render 'posts/image_upload' %>

<%= form_for @answer, url: { controller: :answers, action: :update } do |f| %>
  <%= render 'shared/body_field', f: f, field_name: :body_markdown, field_label: 'Body', post: @answer %>
  <div class="post-preview"></div>
  <div class="form-group">
    <%= label_tag :edit_comment, 'Edit comment', class: "form-element" %>
    <div class="form-caption">
      Describe—if necessary—what you are changing and why you are making this edit.
    </div>
    <%= text_field_tag :edit_comment, params[:edit_comment], class: 'form-element' %>
  </div>
  <div class="form-group">
    <%= f.submit (check_your_post_privilege(@answer, 'Edit') ? "Save changes" : "Suggest changes"), class: "button is-filled" %>
    <%= link_to 'Cancel', question_path(@answer.parent), class: 'button is-outlined is-muted' %>
  </div>
<% end %>

<h2>Question</h2>
<div class="has-padding-6 has-border-style-solid has-border-width-1 has-border-color-tertiary-050" style="max-height: 500px; overflow: auto;">
<%= render 'posts/expanded', post: @answer.parent %>
</div>

<% content_for :sidebar do %>
  <div class="widget has-margin-4">
    <h4 class="widget--header has-margin-0">Hints and Tips</h4>
    <div class="widget--body">
    <% guidance = @answer.category.answering_guidance_override || SiteSetting['AnsweringGuidance'] %>
      <%= raw(sanitize(render_markdown(guidance), scrubber: scrubber)) %>
    </div>
  </div>
<% end %>
