<div class="stream-item row">
  <div class="col s12 m12 l4">
    <div class="grey-text uppercase">
      <br />
      Shared page
    </div>
    <% if @share.content_page %>
      <div class="hoverable card">
        <div class="card-image">
          <%= link_to @share.content_page do %>
            <%= image_tag @share.content_page.first_public_image %>
            <span class="card-title bordered-text">
              <i class="material-icons <%= @share.content_page.class.text_color %> left small"><%= @share.content_page.class.icon %></i>
              <%= @share.content_page.name %>
            </span>
          <% end %>
        </div>
      </div>
    <% else %>
      <div class="hoverable card">
        The shared page has been removed.
      </div>
    <% end %>
    <div class="grey-text uppercase">
      <br />
      Created by
    </div>
    <%= link_to @share.user do %>
      <div class="hoverable card <%= User.color %>">
        <!-- todo vertical card stack user avatar -->
        <div class="card-content">
          <div class="card-title white-text">
            <%= image_tag @share.user.image_url(size=34), class: 'left circle avatar' %>
            <%= @share.user.display_name %>
          </div>
          <%= render partial: 'thredded/users/badge', locals: { user: @share.user } %>
        </div>
      </div>
    <% end %>
    <br />
    <div>
      <ul>
        <li class="uppercase grey-text">
          Share Actions
        </li>
        <li>
          <% if @share.followed_by?(current_user) %>
            <%= link_to 'Unfollow this share', unfollow_user_content_page_share_path(user_id: @share.user.id, id: @share.id) %>
          <% else %>
            <%= link_to 'Follow this share', follow_user_content_page_share_path(user_id: @share.user.id, id: @share.id) %>
          <% end %>
        </li>
        <% if @share.user == current_user %>
          <li>
            <%= 
              link_to user_content_page_share_path(user_id: @share.user.id, id: @share.id),
                method: :DELETE,
                data: { confirm: "Are you sure? This will delete this share and any comments that have been posted to it!" } do
            %>
              Delete this share
            <% end %>
          </li>
        <% else %>
          <li>
            <%= link_to report_user_content_page_share_path(user_id: @share.user.id, id: @share.id) do %>
              Report this share
            <% end %>
          </li>
        <% end %>
        <li>
          <%= link_to 'Back to your stream', main_app.stream_path %>
        </li>
      </ul>
    </div>
    <div>
      <ul>
        <li class="grey-text uppercase">
          Reshare to...
        </li>
        <li>
          <%= link_to [
            'http://twitter.com/share?',
            'url=' + URI::escape(user_content_page_share_url(user_id: @share.user.id, id: @share.id)),
            '&text=' + URI::escape(@share.message)
          ].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(user_content_page_share_url(user_id: @share.user.id, id: @share.id))}&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>
    </div>
  </div>
  <div class="col s12 m12 l7">
    <br /><br />
    <div class="card">
      <div class="card-content">
        <p>
          <%= link_to @share.user, class: "#{User.text_color}" do %>
            <%= image_tag @share.user.image_url(size=20), class: 'left circle avatar' %>
            <%= @share.user.name %>
          <% end %>
          said:
          <span class="grey-text right">
            <%= time_ago_in_words @share.shared_at %> ago
          </span>
        </p>
        <% if @share.message.present? %>
          <blockquote class="original-comment black-text">
            <%=
              simple_format ContentFormatterService.show(
                text:         @share.message,
                viewing_user: current_user
              )
            %>
          </blockquote>
        <% end %>
      </div>
    </div>
    <div class="card <%= user_signed_in? && @share.user == current_user ? 'purple' : 'blue' %> lighten-5 black-text hoverable">
      <div class="card-content">
        <% if user_signed_in? %>
          <%= render partial: 'share_comments/form', locals: { share: @share } %>
        <% else %>
          <div class='center'>
            <%= link_to new_user_registration_path do %>
              To leave a comment, sign up for a free Notebook.ai account.
            <% end %>
          </div>
        <% end %>
        <div class="clearfix"></div>
      </div>
    </div>

    <div class="uppercase grey-text center">
      <%= pluralize @share.share_comments.count, 'comment' %>
    </div>
    <% @share.share_comments.each do |comment| %>
      <%= 
        render partial: 'share_comments/show', 
              locals: { comment: comment, share: @share }
      %>
    <% end %>

    <% if @share.share_comments.count > 10 && user_signed_in? %>
      <div class="clearfix"></div>
      <div class="card <%= user_signed_in? && @share.user == current_user ? 'purple' : 'blue' %> lighten-3 black-text hoverable">
        <div class="card-content">  
          <%= render partial: 'share_comments/form', locals: { share: @share } %>
        </div>
      </div>
    <% end %>
    <br /><br />
  </div>
</div>
