<% # expects "work" %>

<% if work.unrevealed? && !is_author_of?(work) %>
  <%= render "works/mystery_blurb", item: work %>
<% else %>
  <!--title, author, fandom-->
  <div class="header module">
    <!-- updated_at=<%= work.updated_at.to_i.to_s %> -->
    <h4 class="heading">
      <% if (work.unrevealed? || work.anonymous?) && is_author_of?(work) %>
        <span class="status">
          <% if work.unrevealed? %>
            <%= ts("Unrevealed:") %>
          <% elsif work.anonymous? %>
            <%= ts("Anonymous:") %>
          <% end %>
        </span>
      <% end %>
      <%= link_to work.title, @collection ? collection_work_path(@collection, work) : work %>
      <%= ts('by') %>

      <!-- do not cache -->
      <%= byline(work, visibility: "public") %>

<% #### CACHE show/hide ####, if you update the key edit lib/tasks/memcached.rake %>
<% cache("#{work.cache_key}-#{Work.work_blurb_version(work.id)}-#{hide_warnings?(work) ? 'nowarn' : 'showwarn'}-#{hide_freeform?(work)  ? 'nofreeform' : 'showfreeform'}-v11", skip_digest: true) do %>

      <% tag_groups = work.tag_groups %>

      <% if work.gifts.not_rejected.exists? %>
        <%= ts("for") %> <%= recipients_link(work) %>
      <% end %>
      <% if work.restricted %><%= image_tag("lockblue.png", :size => "15x15", :alt => "(Restricted)", :title => "Restricted", skip_pipeline: true) %><% end %>
      <% if work.hidden_by_admin %><%= image_tag("lockred.png", :size => "15x15", :alt => "(Hidden by Admin)", :title => "Hidden by Administrator", skip_pipeline: true) %><% end %>
    </h4>

    <h5 class="fandoms heading">
      <span class="landmark"><%= ts("Fandoms") %>:</span>
      <% fandoms = tag_groups['Fandom'] %>
      <%= fandoms.collect{|tag| link_to_tag_works(tag) }.join(', ').html_safe if fandoms %>
      &nbsp;
    </h5>

    <!--required tags-->
    <%= get_symbols_for(work, tag_groups) %>
    <p class="datetime"><%= set_format_for_date(work.revised_at) %></p>
  </div>

  <% if !work.posted? %>
   <p class="caution notice"><%= t('.draft_deletion_notice_html', deletion_date: date_in_zone(work.created_at + 29.days)) %></p>
  <% end %>
  <!--warnings again, cast, freeform tags-->
  <h6 class="landmark heading"><%= ts("Tags") %></h6>
  <ul class="tags commas">
    <%= blurb_tag_block(work, tag_groups) %>
  </ul>

  <!--summary-->
  <% unless work.summary.blank? %>
    <h6 class="landmark heading"><%= ts("Summary") %></h6>
    <blockquote class="userstuff summary">
      <%=raw strip_images(sanitize_field(work, :summary)) %>
    </blockquote>
  <% end %>

  <% unless work.series.empty? %>
    <h6 class="landmark heading"><%= ts("Series") %></h6>
    <ul class="series">
      <% work.series.each do |series| %>
        <li>
          <%= work_series_description(work, series) %>
        </li>
      <% end %>
    </ul>
  <% end %>

  <!--stats-->

  <dl class="stats">
    <% if work.language.present? %>
      <dt class="language"><%= ts("Language") %>:</dt>
      <dd class="language" lang="<%= work.language.short %>"><%= work.language.name %></dd>
    <% end %>
    <dt class="words"><%= ts('Words') %>:</dt>
    <dd class="words"><%= number_with_delimiter(work.word_count) %></dd>
    <dt class="chapters"><%= ts('Chapters') %>:</dt>
    <dd class="chapters"><%= chapter_total_display_with_link(work) %></dd>

<% end %>
<% #### END CACHE show/hide %>

<% #### CACHE stats #### %>
<% cache("#{work.cache_key}/stats-v4", expires_in: 1.hour, skip_digest: true) do %>
  <% unless work.approved_collections.empty? %>
    <dt class="collections"><%= ts('Collections') %>:</dt>
    <dd class="collections"><%= link_to number_with_delimiter(work.approved_collections.length), work_collections_path(work) %></dd>
  <% end %>

  <% if work.count_visible_comments > 0 %>
    <dt class="comments"><%= ts('Comments') %>:</dt>
    <dd class="comments"><%= link_to number_with_delimiter(work.count_visible_comments), work.number_of_posted_chapters > 1 ? work_path(work, anchor: "comments", show_comments: true, view_full_work: "true") : work_path(work, anchor: "comments", show_comments: true) %></dd>
  <% end %>

  <% if work.all_kudos_count > 0 %>
    <dt class="kudos"><%= ts('Kudos') %>:</dt>
    <dd class="kudos"><%= link_to number_with_delimiter(work.all_kudos_count), work.number_of_posted_chapters > 1 ? work_path(work, anchor: "kudos", view_full_work: "true") : work_path(work, anchor: "kudos") %></dd>

  <% end %>
  <% if (bookmark_count = work.public_bookmarks_count) > 0 %>
    <dt class="bookmarks"><%= ts('Bookmarks') %>:</dt>
    <dd class="bookmarks"><%= link_to_bookmarkable_bookmarks(work, number_with_delimiter(bookmark_count)) %></dd>
  <% end %>

  <dt class="hits"><%= ts("Hits") %>:</dt>
  <dd class="hits"><%= number_with_delimiter(work.hits) %></dd>
<% end %>
<% #### END CACHE stats #### %>

  </dl>

<% end %>
