<% title "Dashboard - DEV" %>

<div class="dashboard-container" id="user-dashboard">
  <div class="actions">
    <a class="action <%= 'active' if params[:which] == "organization" || params[:which].blank? %>" href="/dashboard">
      <span>POSTS</span>
      <span>(<%= @user.articles_count %>)</span>
    </a>
    <a class="action <%= 'active' if params[:which] == "user_followers" || params[:which] == "organization_user_followers" %>" href="/dashboard/user_followers">
      <span>FOLLOWERS</span>
      <span>(<%= @user.followers_count %>)</span>
    </a>
    <a class="action <%= 'active' if params[:which].to_s.include?("following") %>" href="/dashboard/following">
      <span>FOLLOWING</span>
      <span>(<%= @user.following_users_count + @user.following_tags_count %>)</span>
    </a>
  </div>
<% if @user.org_admin && @user.organization &&  (params[:which].blank? || params[:which] == "organization") %>
  <h1>
    <a href="/dashboard" class=<%= "active" if params[:which].blank? %>>Personal</a>
    <a href="/dashboard/organization" class=<%= "active" if params[:which] == "organization" %>><%= @user.organization.name %> (<%= @user.organization.articles.size %>)</a>
  </h1>
<% elsif @user.org_admin && @user.organization &&  (params[:which] == "organization_user_followers" || params[:which] == "user_followers")%>
  <h1>
    <a href="/dashboard/user_followers" class=<%= "active" if params[:which] == "user_followers" %>>Personal</a>
    <a href="/dashboard/organization_user_followers" class=<%= "active" if params[:which] == "organization_user_followers" %>><%= @user.organization.name %> (<%= @user.organization.followers_count %>)</a>
  </h1>
<% end %>
  <% if @user.org_admin && @user.organization && params[:which] == "organization" %>
      <%= render "analytics" %>
      <% @articles.each do |article| %>
        <%= render "dashboard_article", article: article, org_admin: true %>
      <% end %>
    </div>
  <% elsif params[:which] == "user_followers" || params[:which] == "following_users" || params[:which] == "following"  || params[:which] == "organization_user_followers" %>
      <% if @followed_tags %>
        <h2>Followed tags (<%= @user.following_tags_count %>)</h2>
        <p><em>Adjust <strong>Follow Weight</strong> to make a tag show up less or more in your feed (default 1.0)</em></p>
        <% negative_follow_shown_once = false %>
        <% @followed_tags.each do |follow| %>
          <% tag = follow.followable %>
          <% if tag %>
            <% if follow.points < 0 && !negative_follow_shown_once %>
              <h2>Negative Tags (anti-follows)</h2>
              <% negative_follow_shown_once = true %>
            <% end %>
            <% color = HexComparer.new([tag.bg_color_hex || "#0000000",tag.text_color_hex || "#ffffff"]).brightness(0.8) %>
            <div class="single-article" style="border-color:<%= color %>;box-shadow: 3px 3px 0px <%= color %>">
                <h2>
                  <a href="/t/<%= tag.name %>">
                    <%= tag.name %>
                  </a>
                  <%= form_for(follow) do |f| %>
                    <%= f.label(:points, "Follow Weight:") %>
                    <%= f.text_field(:points) %>
                    <%= f.submit "Submit" %>
                  <% end %>
                </h2>
              </a>
            </div>
          <% end %>
        <% end %>
        <h2>Followed users (<%= @user.following_users_count %>)</h2>
      <% end %>
      <% @follows.each do |follow| %>
        <% user = params[:which].include?("followers") ? follow.follower : follow.followable %>
        <% if user %>
          <div class="single-article">
            <a href="<%= user.path %>" class="block-link">
              <h2>
                <img alt="<%= user.username %> profile image" src="<%= ProfileImage.new(user).get(60)%>" />
                <%= user.name %>
                <span class="dashboard-username">@<%= user.username %></a>
              </h2>
            </a>
          </div>
        <% end %>
    <% end %>
  <% elsif @articles.any? %>
    <%= render "analytics" %>
    <% if current_user.has_role?(:video_permission) %>
      <a class="video-upload-cta" href="/videos/new" data-no-instant>
        Upload a Video 🎥
      </a>
    <% end %>
    <% @articles.each do |article| %>
        <%= render "dashboard_article", article: article, org_admin: false %>
    <% end %>
  <% else %>
    <div class="no-articles">
      <h3>This is where you can manage your posts, but you haven't written anything yet.</h3>
      <a href="/new" class="cta big">
        Write your first post now
      </a>
      <%=image_tag(cl_image_path(asset_path("/assets/sloan.png"),
       :type=>"fetch",
       :width => 300,
       :crop => "imagga_scale",
       :quality => "auto",
       :flags => "progressive",
       :fetch_format => "auto",
       :sign_url => true), class:"sloan", alt:"sloth-mascot") %>
       <br/>
      <h3>Also check out the <a href="/welcome" data-no-instant>Welcome Thread</a> to introduce yourself!</h3>
    </div>
  <% end %>
</div>
