<%= render 'posts/markdown_script' %>

<% if @article.errors.any? %>
  <div class="notice is-danger is-filled">
    The following errors prevented this post from being saved:
    <ul>
      <% @article.errors.full_messages.each do |msg| %>
        <li><%= msg %></li>
      <% end %>
    </ul>
  </div>
<% end %>

<%= render 'posts/image_upload' %>

<%= form_for @article, url: edit_article_path(@article) do |f| %>
  <div class="form-group">
    <%= f.label :title, "Title your post:", class: "form-element" %>
    <%= f.text_field :title, class: "form-element" %>
  </div>

  <%= render 'shared/body_field', f: f, field_name: :body_markdown, field_label: 'Body', post: @article %>

  <div class="post-preview"></div>

  <div class="form-group">
    <%= f.label :tags_cache, "Tags", class: "form-element" %>
    <div class="form-caption">
      Tags help to categorize posts. Separate them by space. Use hyphens for multiple-word tags.
    </div>
    <%= f.select :tags_cache, options_for_select(@article.tags_cache.map { |t| [t, t] }, selected: @article.tags_cache),
                 { include_blank: true }, multiple: true, class: "form-element js-tag-select",
                 data: { tag_set: @article.category.tag_set.id } %>
  </div>

  <div class="form-group">
    <%= label_tag :edit_comment, 'Edit comment', class: "form-element" %>
    <div class="form-caption">
      Describe&mdash;if necessary&mdash;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(@article, 'Edit') ? "Save changes" : "Suggest changes", class: "button is-filled" %>
    <%= link_to 'Cancel', article_path(@article), class: 'button is-outlined is-muted' %>
  </div>
<% end %>
