<% @chapter = chapter if defined?(chapter) %>

<div class="meta group">
  <h2 class="heading"><%= @chapter.chapter_title.html_safe %></h2>
  <% if (!@chapter.pseuds.blank? && (@chapter.pseuds != @work.pseuds) && (!@work.anonymous?)) %>
    <%# only display byline if different from the main byline %>
    <p class="byline"><%= t(".chapter_byline_html", byline_names_link: byline(@chapter, only_path: false)) %></p>
  <% end %>

  <% unless @chapter.summary.blank? %>
    <p><%= t(".chapter_summary") %></p>
    <blockquote class="userstuff"><%= raw sanitize_field(@chapter, :summary) %></blockquote>
  <% end %>

  <% unless @chapter.notes.blank? && @chapter.endnotes.blank? %>
    <p><%= t(".chapter_notes") %></p>
    <% unless @chapter.notes.blank? %>
      <blockquote class="userstuff"><%= raw sanitize_field(@chapter, :notes) %></blockquote>
    <% end %>
    <% unless @chapter.endnotes.blank? %>
      <div class="endnote-link">
        <%= t(".see_chapter_end_notes_html", chapter_end_notes_link: link_to(@chapter.notes.present? ? t(".chapter_end_notes_with_chapter_notes") : t(".chapter_end_notes_without_chapter_notes"), "#endnotes#{@chapter.position}")) %>
      </div>
    <% end %>
  <% end %>
</div>

<!--chapter content-->
<div class="userstuff">
  <%= raw defined?(@content) ? @content : sanitize_field(@chapter, :content) %>
</div>
<!--/chapter content-->

<% unless @chapter.endnotes.blank? %>
  <div class="meta" id="endnotes<%= @chapter.position %>">
    <p><%= t(".section_chapter_end_notes") %></p>
    <blockquote class="userstuff"><%= raw sanitize_field(@chapter, :endnotes) %></blockquote>
  </div>
<% end %>
