<%- @title = "All Pages" -%>

<%= categories_menu unless @categories.empty? %>

<div id="allPages">
<%- unless @pages_that_are_orphaned.empty? && @page_names_that_are_wanted.empty? -%>
  <h2>
    All Pages
    <br/><span class="pageType">All pages in <%= raw @set_name %> listed alphabetically</span>
  </h2>
<%- end -%>

<% if [:markdownMML, :markdownPNG, :markdown].include?(@web.markup) -%>
<% form_tag({ :controller => 'wiki', :action => 'tex_list', :web => @web.address },
             {'method' => 'post', 'accept-charset' => 'utf-8' }) do
%>
<div>
<% if params['category'] -%>
<input type="hidden" name="category" value="<%= params['category'] %>"/>
<%- end -%>
<ul id="sortable_pages">
  <% @pages_in_category.each do |page| %>
    <% content_tag_for :li, page do %>
    
      <input type="checkbox" name="<%= page.name %>" value="tex"/>       
      <%= link_to_existing_page page, truncate(page.plain_name, :length => 35) %>
    <% end %>

  <% end %>
</ul>
<%= sortable_element('sortable_pages', {:onUpdate => 'function(){}'}) %>
<label for="commit"> Export selected pages (drag to re-order them) to a LaTeX file.</label>
<%= submit_tag("Export") %>
</div>
<%- end -%>
<%- else -%>
<ul>
  <%- @pages_in_category.each do |page| -%>
    <li>
      <%= link_to_existing_page page, truncate(page.plain_name, :length => 35) %>
    </li>
  <%- end -%>
</ul>
<%- end -%>

<%- if @web.count_pages? -%>
  <% total_chars = @pages_in_category.characters %>
  <p class="pageStats">All content: <%= total_chars %> chars / approx. <%= sprintf("%-.1f", (total_chars / 2275 )) %> printed pages</p>
<%- end -%>
</div>

<div id="wantedPages">
<%- unless @page_names_that_are_wanted.empty? -%>
  <h2>
    Wanted Pages
    <br/>
    <span class="pageType">
      Nonexistent pages that other pages in <%= raw @set_name %> reference
    </span>
  </h2>

  <ul style="margin-bottom: 10px">
  <%- @page_names_that_are_wanted.each do |wanted_page_name| -%>
    <li>
      <%= link_to_page(wanted_page_name, @web, truncate(WikiWords.separate(wanted_page_name), :length => 35)) %>
      wanted by
      <%= @web.select.pages_that_reference(wanted_page_name).collect { |referring_page|            
            link_to_existing_page referring_page
          }.join(", ").html_safe 
      %>
    </li>
  <%- end -%>
  </ul>
<%- end -%>

<%- unless @pages_that_are_orphaned.empty? -%>
  <h2>
    Orphaned Pages
    <br/><span class="pageType">Pages in <%= raw @set_name %> that no other page reference</span>
  </h2>

  <ul style="margin-bottom: 35px">
    <%- @pages_that_are_orphaned.each do |orphan_page| -%>
      <li>
        <%= link_to_existing_page orphan_page, truncate(orphan_page.plain_name, :length => 35) %>
      </li>
    <%- end -%>
  </ul>
<%- end -%>
</div>
