<% title "Dashboard" %>

<div class="dashboard-container" id="user-dashboard">
  <%= render "actions" %>
  <% if @organizations && @organizations.size > 0 && (params[:which].blank? || params[:which] == "organization") %>
    <h1>
      <a href="/dashboard" class="rounded-btn <%= "active" if params[:which].blank? %>">Personal</a>
      <% @organizations.each do |org| %>
        <a href="/dashboard/organization/<%= org.id %>" class="rounded-btn <%= "active" if params[:org_id].to_i == org.id %>"><%= org.name %> (<%= org.articles_count %>)</a>
      <% end %>
    </h1>
  <% end %>
  <% if params[:which] == "organization" %>
    <%= render "analytics" %>
    <% @articles.each do |article| %>
      <%= render "dashboard_article", article: article, organization: article.organization, org_admin: true, manage_view: false %>
    <% end %>
  <% elsif @articles.any? %>
    <%= render "analytics" %>
    <div class="actions-secondary">
      <% if current_user.created_at < 2.weeks.ago %>
        <a class="video-upload-cta cta" href="/videos/new" data-no-instant>
          Upload a Video 🎥
        </a>
      <% end %>
        <a class="video-upload-cta cta" href="/listings/dashboard" data-no-instant>
          Create/Manage Listings
        </a>
      <%= select_tag "dashhboard_sort", options_for_select(sort_options, params[:sort]) %>
      <% if @articles.any? {|article| article.archived } %>
        <%= link_to "Show archived", "javascript:;", id: "toggleArchivedLink" %>
      <% end %>
    </div>
    <% @articles.each do |article| %>
      <%= render "dashboard_article", article: article, organization: nil, org_admin: false, manage_view: 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: "Sloan, the sloth mascot") %>
      <br />
      <h3>Also check out the <a href="/welcome" data-no-instant>Welcome Thread</a> to introduce yourself!</h3>
    </div>
  <% end %>
</div>
