<!--page description, messages-->
<% if @work.unrevealed? %>
  <%= render "works/work_unrevealed_notice" %>
<% end %>
<% if @work.user_has_creator_invite?(current_user) %>
  <p class="notice">
    <%= ts("You've been invited to become a co-creator of this work. To accept or reject the request, visit your %{creator_requests_page}.",
           creator_requests_page: link_to(ts("Co-Creator Requests page"), user_creatorships_path(current_user))).html_safe %>
  </p>
<% end %>
<!--/descriptions-->

<!--subnav-->
<% if policy(@work).show_admin_options? %>
  <%= render "admin/admin_options", item: @work %>
<% end %>
<!--/subnav-->

<% if !@work.unrevealed? || logged_in_as_admin? || can_access_unrevealed_work(@work, current_user) %>
  <!-- BEGIN work -->
  <div class="work"><p class="landmark"><a name="top">&nbsp;</a></p>
    <%= render :partial => 'works/work_header' %>

    <div id="chapters">
      <%= render :partial => 'chapters/chapter', :locals => { :chapter => @chapter } %>
    </div>

    <% inspired_by = get_inspired_by(@work) %>
    <% last_chapter = @work.posted? ? @work.last_posted_chapter : @work.last_chapter %>
    <% if @chapter == last_chapter && (@work.endnotes.present? || @work.series.present? || inspired_by.present?) %>
      <!--afterword-->
      <div class="afterword preface group">
        <% if !@work.endnotes.blank? %>
          <%= render :partial => 'works/work_endnotes' %>
        <% end %>
        <% unless @preview_mode || @work.series.blank? %>
          <%= render :partial => 'works/work_series_links' %>
        <% end %>
        <% unless inspired_by.empty? %>
          <%= render :partial => 'works/work_approved_children', :locals => {:inspired_by => inspired_by} %>
        <% end %>
      </div>
      <!--/afterword-->
    <% end %>

    </div>
    <!-- END work skin -->
  </div>
  <!-- END work -->

  <!-- BEGIN comment section -->
  <%= render :partial => 'comments/commentable', :locals => {:commentable => @chapter} %>
  <!-- END comment section -->

  <% if @next_chapter %>
    <script type="speculationrules">
      {
        "prerender": [
          {
            "source": "list",
            "urls": ["<%= work_chapter_path(@work, @next_chapter, anchor: "workskin") %>"]
          }
        ]
      }
    </script>
  <% end %>
<% end %>

<%= render "hit_count/include" %>
