<% if user_signed_in? %>
  <% if current_user != @page_collection.user %>
    <% if @page_collection.followed_by?(current_user) %>
      <%= link_to unfollow_page_collection_path(@page_collection), class: "hoverable btn #{PageCollection.color}", style: 'width: 100%' do %>
        <i class="material-icons"><%= PageCollection.icon %></i>
        &nbsp;
        Unfollow
      <% end %>

    <% else %>
      <%= link_to follow_page_collection_path(@page_collection), class: "hoverable btn #{PageCollection.color}", style: 'width: 100%' do %>
        <i class="material-icons"><%= PageCollection.icon %></i>
        &nbsp;
        Follow for updates
      <% end %>
    <% end %>
  <% end %>
<% else %>
  <%= link_to follow_page_collection_path(@page_collection), class: "hoverable btn #{PageCollection.color} disabled", style: 'width: 100%' do %>
    Sign in to follow this Collection
  <% end %>
<% end %>

<%= render partial: 'page_collections/quick_add' %>

<% if user_signed_in? && @page_collection.user == current_user %>
  <div class="card-panel">
    <%= form_for @page_collection do |f| %>
      <div class="input-field">
        <%= f.text_area :description, class: 'materialize-textarea' %>
        <%= f.label :description, 'Collection Description' %>
        <div class="help-text">You can add details for this collection to explain what kinds of pages you'd like it to contain.</div>
      </div>
      <%= f.submit 'Save changes', class: 'btn right blue white-text' %>
      <div class="clearfix"></div>

    <% end %>
  </div>
<% else %>
  <% if @page_collection.description? %>
    <div class="card-panel">
      <%= simple_format @page_collection.description %>
    </div>
  <% end %>
<% end %>

<div class="grey-text uppercase">In this collection</div>
<div class="collection">
  <%= link_to @page_collection, class: "collection-item #{PageCollection.text_color}" do %>
    <i class="material-icons left"><%= PageCollection.icon %></i>
    All Pages
    <span class="badge brown-text"><%= @page_collection.accepted_submissions.count %></span>
  <% end %>
  <% @page_collection.page_types.each do |pt| %>
    <% klass = content_class_from_name(pt) %>
    <%= link_to(send(pt.downcase.pluralize + '_page_collection_path', @page_collection), class: "collection-item #{klass.color} white-text") do %>
      <i class="material-icons left"><%= klass.icon %></i>
      <%= pt.pluralize %>
      <span class="badge white-text"><%= @page_collection.accepted_submissions.where(content_type: pt).count %></span>
    <% end %>
  <% end %>
</div>

<div class="grey-text uppercase">Curator</div>
<div>
  <%= link_to @page_collection.user, class: "#{User.text_color}" do %>
    <%= image_tag @page_collection.user.image_url(size=20), class: 'left circle', style: 'margin-right: 8px;' %>
    <%= @page_collection.user.display_name %>
  <% end %>
</div>
<br />

<% if @page_collection.contributors.any? %>
  <div class="grey-text uppercase">Contributors</div>
  <% @page_collection.contributors.each do |user| %>
    <div>
      <%= link_to user, class: "#{User.text_color}" do %>
        <%= image_tag user.image_url(size=20), class: 'left circle', style: 'margin-right: 8px;' %>
        <%= user.display_name %>
      <% end %>
    </div>
  <% end %>
  <br />
<% end %>

<% if user_signed_in? && current_user == @page_collection.user %>
  <ul>
    <li><%= link_to pluralize(@page_collection.pending_submissions.count, 'pending submission'), page_collection_pending_submissions_path(page_collection_id: @page_collection.id) %></li>
    <li><%= link_to 'Edit this collection', edit_page_collection_path(@page_collection) %></li>
  </ul>
<% end %>

<ul>
  <li class="grey-text uppercase">
    Share collection to...
  </li>
  <li>
    <%= link_to [
      'http://twitter.com/share?',
      'url=' + URI::escape(page_collection_url(@page_collection)),
      '&text=' + URI::escape("I'm building a collection of fictional " + @page_collection.page_types.map(&:pluralize).map(&:downcase).to_sentence + " on Notebook.ai. Check it out!")
    ].join, class: 'blue-text', target: '_blank' do %>
      <i class="material-icons tiny left" style="margin-top: 4px;">share</i>
      Twitter
    <% end %>
  </li>
  <li>
    <%= 
      link_to "https://www.facebook.com/sharer/sharer.php?app_id=1523926344336934&u=#{URI::escape(page_collection_url(@page_collection))}&display=popup&ref=plugin&src=share_button", 
        class: 'blue-text',
        onclick: "return !window.open(this.href, 'Facebook', 'width=640,height=580')" do
    %>
      <i class="material-icons tiny left" style="margin-top: 4px">share</i>
      Facebook
    <% end %>
  </li>

</ul>