<%= render :partial => "stories/form_errors", :locals => { :f => f, :story => f.object } %>

<div class="box">
  <% unless defined?(suggesting) %>
    <div class="boxline">
    <% if f.object.url_is_editable_by_user?(@user) %>
      <%= f.label :url, "URL:", :class => "required" %>
      <%= f.text_field :url, :autocomplete => "off" %>
      <%= button_tag raw("Fetch&nbsp;Title"), :id => "story_fetch_title",
        :type => "button" %>
    <% elsif !f.object.new_record? && !f.object.url.blank? %>
      <%= f.label :url, "URL:", :class => "required" %>
      <div class="d">
      <a href="<%= f.object.url %>"><%= f.object.url %></a>
      </div>
    <% end %>
    </div>
  <% end %>

  <div class="boxline">
    <%= f.label :title, "Title:", :class => "required" %>
    <%= f.text_field :title, :maxlength => 100 %>
    <p class="actions title-reminder">
      Please remove extraneous components from titles such as the name of the site, blog, section, and author.
      <span class="title-reminder-thanks">
        Thanks!
      </span>
    </p>
  </div>

  <% if f.object.id && !defined?(suggesting) && f.object.suggested_title_times.any? %>
    <div class="boxline actions">
      Users have suggested setting this story's title to:
      <br>
      <% f.object.suggested_title_times.each do |st| %>
        <%= st.times %>: <%= st.title %><br>
      <% end %>
    </div>
  <% end %>

  <div class="boxline" style="margin-bottom: 2px;">
  <%= f.label :tags_a, "Tags:", :class => "required",
    :style => "line-height: 2.3em;" %>
  <%= f.select "tags_a", options_for_select(
    Tag.all_with_filtered_counts_for(@user).map{|t|
      html = "<strong>#{h(t.tag)}</strong> - #{h(t.description.to_s)}"

      if t.hotness_mod != 0
        html << " (hotness mod #{t.hotness_mod > 0 ? "+" : ""}#{t.hotness_mod})"
      end
      if t.filtered_count > 0
        html << " <em>#{t.filtered_count} user" <<
          (t.filtered_count == 1 ? "" : "s") << " filtering</em>"
      end

      [ "#{t.tag} - #{t.description}", t.tag, { "data-title" => raw(html), "data-tag-css" => t.css_class } ]},
    f.object.tags_a), {}, { :multiple => true } %>
  </div>

  <% if f.object.id && !defined?(suggesting) && f.object.suggested_tagging_times.any? %>
    <div class="boxline actions">
      Users have suggested setting this story's tags to:
      <br>
      <% f.object.suggested_tagging_times.includes(:tag).each do |st| %>
        <%= st.times %>: <%= tag_link(st.tag) %><br>
      <% end %>
    </div>
  <% end %>

  <% unless defined?(suggesting) %>
    <div class="boxline">
      <%= f.label :description, "Text:", :class => "required" %>
      <%= f.text_area :description, :rows => 8, :placeholder => "Use this for stories without a URL, to link additional context, or to paste abstracts from PDF papers.

Please don't use this to promote the story, summarize the post, or explain why you posted it.
See the guidelines below for more." %>
    </div>

    <%= tag.details class: "boxline actions", open: show_guidelines? ? true : nil do %>
      <summary>Story submission guidelines</summary>
      <ul>

        <li><p>
        Do not editorialize story titles, but when the original story's
        title has no context or is unclear, please change it.  <strong>Please
        remove extraneous components from titles such as the name of the
        site, blog, section, and author.</strong>
        </p></li>

        <li><p>
        When the story being submitted is more than a year or so old,
        please add the year the story was written to the post title in
        parentheses.
        </p></li>

        <li><p>
        When submitting a URL, the text field is optional and should only
        be used when additional context or explanation of the URL is
        needed.  Commentary or opinion should be reserved for a comment,
        so that it can be voted on separately from the story.
        </p></li>

        <li><p>
        If no <a href="/tags">tags</a> clearly apply to the story you are submitting, chances
        are it does not belong here.  Do not overreach with tags if they
        are not the primary focus of the story.
        </p></li>

        <li><p>
        To be able to easily submit a page you're viewing in your browser
        to <%= Rails.application.name %>, drag this bookmarklet to your
        bookmark bar:
        [<a href="javascript:{window.open(%22<%= Rails.application.root_url
        %>stories/new?url=%22+encodeURIComponent(document.location)+<%
        %>%22&title=%22+encodeURIComponent(document.title));%20void(0);}<%
        %>">Submit to <%= Rails.application.name %></a>].
        You'll be taken to this page with the viewed page's URL and title.
        (It can't recognize and remove blog/author names for you, though.)
        </p></li>

      </ul>
    <% end %>
  <% end %>
</div>
<% unless defined?(suggesting) %>
  <div class="box">
    <div class="boxline">
      <%= f.label :user_is_author, "Author:", :class => "required" %>
      <%= f.check_box :user_is_author %>
      <%= f.label :user_is_author,
        (f.object.id && f.object.user_id != @user.id ? "Submitter is" : "I am") +
        " the author of the story at this URL (or this text)",
        :class => "normal" %>
    </div>
    <div class="boxline">
      <%= f.label :user_is_following, "Follow:", :class => "required" %>
      <%= f.check_box :user_is_following %>
      <%= f.label :user_is_following,
        (f.object.id && f.object.user_id == @user.id ? 'Follow' : "Submitter is following") +
        " this story to receive replies via e-mail and Pushover",
        :class => "normal" %>
    </div>
  </div>
<% end %>
