<div id="preface">
  <h2 class="toc-heading"><%= t(".preface") %></h2>

  <p class="message">
    <b><%= @work.title %></b><br />
    <%= t(".originally_posted_html",
          archive_link: link_to(ArchiveConfig.APP_NAME, root_url),
          work_url: link_to(work_url(@work), work_url(@work))) %>
  </p>

  <div class="meta">
    <dl class="tags">
      <% Tag::VISIBLE.each do |type| %>
        <% tags = @work.tag_groups[type] %>
        <% unless tags.blank? %>
          <dt><%= t(".tag_type", tag_type: tags.size == 1 ? type.constantize::NAME : type.constantize::NAME.pluralize) %></dt>
          <dd><%= safe_join(tags.map { |t| link_to(t.display_name, tag_url(t)) }, t("support.array.words_connector")) %></dd>
        <% end %>
      <% end %>

      <% unless @work.language.blank? %>
        <dt><%= t(".language") %></dt>
        <dd><%= @work.language.name %></dd>
      <% end %>

      <% series_list = @work.serial_works.reject { |sw| sw.series.nil? } %>
      <% unless series_list.blank? %>
        <dt><%= t(".series") %></dt>
        <dd><%= safe_join(series_list.map { |s| t(".series_list_html", position: s.position, series_link: link_to(s.series.title, series_url(s.series))) }, t("support.array.words_connector")) %></dd>
      <% end %>
      <% unless @work.approved_collections.empty? %>
        <dt><%= t(".collections") %></dt>
        <dd><%= safe_join(@work.approved_collections.map { |c| link_to(c.title, collection_url(c)) }, t("support.array.words_connector")) %></dd>
      <% end %>
      <dt><%= t(".stats") %></dt>
      <dd>
        <%= t(".published", date: l(@work.first_chapter.published_at)) %>
        <% if @work.first_chapter.published_at < @work.revised_at.to_date %>
          <%= @work.is_wip ? t(".updated", date: l(@work.revised_at.to_date)) : t(".completed", date: l(@work.revised_at.to_date)) %>
        <% end %>
        <%= t(".words", count_with_delimiters: number_with_delimiter(@work.word_count)) %>
        <%= t(".chapters", chapter_total_display: chapter_total_display(@work)) %>
      </dd>
    </dl>
    <h1><%= @work.title %></h1>
    <div class="byline"><%= t(".byline_html", byline_names_link: byline(@work, visibility: "public", only_path: false)) %></div>
    <% unless @work.summary.blank? %>
      <p><%= t(".summary") %></p>
      <blockquote class="userstuff"><%= raw sanitize_field(@work, :summary) %></blockquote>
    <% end %>

    <% unless @work.notes.blank? && @work.endnotes.blank? %>
      <p><%= t(".notes") %></p>
      <% unless @work.notes.blank? %>
        <blockquote class="userstuff"><%= raw sanitize_field(@work, :notes) %></blockquote>
      <% end %>
      <% unless @work.endnotes.blank? %>
        <div class="endnote-link">
          <%= t(".see_end_notes_html", end_notes_link: link_to(@work.notes.present? ? t(".end_notes_with_work_notes") : t(".end_notes_without_work_notes"), "#endnotes")) %>
        </div>
      <% end %>
    <% end %>

    <%# i18n-tasks-use t("downloads.download_preface.translated_to.restricted_html") %>
    <%# i18n-tasks-use t("downloads.download_preface.translated_to.revealed_html") %>
    <%# i18n-tasks-use t("downloads.download_preface.translated_to.unrevealed_html") %>
    <%# i18n-tasks-use t("downloads.download_preface.inspired_by.restricted_html") %>
    <%# i18n-tasks-use t("downloads.download_preface.inspired_by.revealed_html") %>
    <%# i18n-tasks-use t("downloads.download_preface.inspired_by.unrevealed") %>
    <%# i18n-tasks-use t("downloads.download_preface.translation_of.restricted_html") %>
    <%# i18n-tasks-use t("downloads.download_preface.translation_of.revealed_html") %>
    <%# i18n-tasks-use t("downloads.download_preface.translation_of.unrevealed") %>
    <% translations = @work.approved_related_works.where(translation: true) %>
    <% related_works = @work.parent_work_relationships.reject { |wr| !wr.parent } %>
    <% if translations.any? || related_works.any? %>
      <ul>
        <% translations.each do |related_work| %>
          <li>
            <%= related_work_note(related_work.work, "translated_to", download: true) %>
          </li>
        <% end %>
        <% related_works.each do |work| %>
          <li>
            <% relation = work.translation ? "translation_of" : "inspired_by" %>
            <%= related_work_note(work.parent, relation, download: true) %>
          </li>
        <% end %>
      </ul>
    <% end %>

  </div>
</div>
