<h2>Your Answer</h2>
<% if answer.errors.any? %>
  <div class="notice is-danger">
    <p>The following <%= "error".pluralize(answer.errors.count) %> prevented the answer from being posted:</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: create_answer_path do |f| %>
  <%= render 'shared/body_field', f: f, field_name: :body_markdown, field_label: 'Body', post: answer %>

  <div class="form-group">
    <%= f.label :license_id, 'License', class: 'form-element' %>
    <% cat = defined?(@category) ? @category : @question.category %>
    <span class="form-caption">
      <% site_default = License.site_default %>
      <% category_default = cat.license %>
      <% if site_default.present? %>
        site default: <a href="javascript:void(0)" class="js-license-autofill" data-license-id="<%= site_default.id %>">
          <%= site_default.name %>
        </a>
      <% end %>
      <% if site_default.present? && category_default.present? %>
        &middot;
      <% end %>
      <% if category_default.present? %>
        category default: <a href="javascript:void(0)" class="js-license-autofill" data-license-id="<%= category_default.id %>">
          <%= category_default.name %>
        </a>
      <% end %>
    </span>
    <%= f.select :license_id, options_for_select(License.enabled.default_order(cat).map { |l| [l.name, l.id] }),
                 {}, class: 'form-element' %>
  </div>

  <div class="post-preview"></div>
  <div class="field">
    <%= f.submit "Post Answer", class: "button is-filled" %>
  </div>
<% end %>
