<% if @user_buffer_updates.any? %>
  <div class="alert alert-primary">
    You have sent <strong><%= @user_buffer_updates.size %></strong> buffers so far in the past 24 hours. Keep it up!
  </div>
<% else %>
  <div class="alert alert-warning" role="alert">
    You haven't sent any buffers in the past 24 hours, let's get to work!
  </div>
<% end %>

<div class="row">
  <div class="col-12">
    <ul class="nav nav-tabs nav-fill">
      <li class="nav-item">
        <a href="/internal/articles" class="nav-link <%= "active" if params[:state].blank? %>">Hot</a>
      </li>
      <li class="nav-item">
        <a href="/internal/articles?state=chronological" class="nav-link <%= "active" if params[:state] == "chronological" %>">Chronological</a>
      </li>
      <li class="nav-item">
        <a href="/internal/articles?state=satellite" class="nav-link <%= "active" if params[:state] == "satellite" %>">Satellite</a>
      </li>
      <li class="nav-item">
        <span class="nav-link disabled">Not Buffered:</span>
      </li>
      <li class="nav-item">
        <a href="/internal/articles?state=not-buffered-0.25" class="nav-link <%= "active" if params[:state] == "not-buffered-0.25" %>">6hr</a>
      </li>
      <li class="nav-item">
        <a href="/internal/articles?state=not-buffered-1" class="nav-link <%= "active" if params[:state] == "not-buffered-1" %>">1d</a>
      </li>
      <li class="nav-item">
        <a href="/internal/articles?state=not-buffered-7" class="nav-link <%= "active" if params[:state] == "not-buffered-7" %>">7d</a>
      </li>
      <li class="nav-item">
        <a href="/internal/articles?state=satellite-not-buffered" class="nav-link <%= "active" if params[:state] == "satellite-not-buffered" %>">Satellite</a>
      </li>
      
    </ul>
    <% if params[:state] && params[:state].include?("top-") && params[:state] != "top-3" && params[:state] != "top-6" %>
      <h1 style="color:red">
        <%= params[:state] %>-months
      </h1>
    <% end %>
  </div>
  <% if @pending_buffer_updates.any? %>
    <div class="col-12 mb-2">
      <details>
        <summary style="font-size: 1.3em; cursor: pointer;">Suggested Tweets (<%= @pending_buffer_updates.size %>)</summary>
        <% @pending_buffer_updates.each do |buffer_update| %>
          <% next unless buffer_update.article %>
          <div class="card my-3" id="suggested-tweet-<%= buffer_update.id %>" data-controller="buffer" data-action="load@window->buffer#autosizeBodyText">
            <div class="card-header">
              <h2 class="my-0" data-target="buffer.header"><%= buffer_update.article.title %></h2>
            </div>
            <div class="card-body">
              <h4>Score: <%= buffer_update.article.score %></h4>
              <div class="blockquote">
                <%= HTML_Truncator.truncate(buffer_update.article.processed_html, 50, ellipsis: '<a class="comment-read-more" href="' + buffer_update.article.path + '">... Read Entire Post</a>').html_safe %>
              </div>
              <hr />

              <code><b><%= Tag.find_by(id: buffer_update.tag_id)&.name || buffer_update.social_service_name %>:</b></code>

              <%= form_with url: internal_buffer_update_path(buffer_update.id), class: "buffer-form buffer-confirm", html: { data: { action: "submit->buffer#highlightElement" } } do |f| %>
                <div class="form-group">
                  <input name="utf8" type="hidden" value="✓">
                  <input type="hidden" name="authenticity_token" value="<%= form_authenticity_token %>" />
                  <input type="hidden" name="_method" value="patch" />
                  <input type="hidden" name="status" value="confirmed" />
                  <textarea class="w-100 suggested-tweet-body-text" name="body_text" class="form-control" data-target="buffer.bodyText"><%= buffer_update.body_text %></textarea>
                </div>
                <button value="confirmed" name="status" class="btn btn-success" data-action="buffer#tagBufferUpdateConfirmed">Confirm</button>
              <% end %>

              <%= form_with url: internal_buffer_update_path(buffer_update.id), class: "buffer-form buffer-dismiss", html: { data: { action: "submit->buffer#highlightElement" } } do |f| %>
                <div class="form-group">
                  <input name="utf8" type="hidden" value="✓">
                  <input type="hidden" name="authenticity_token" value="<%= form_authenticity_token %>" />
                  <input type="hidden" name="_method" value="patch" />
                  <input type="hidden" name="status" value="dismissed" />
                </div>
                <button value="dismissed" name="status" class="btn btn-danger" data-action="buffer#tagBufferUpdateDismissed">Dismiss</button>
              <% end %>
            </div>
          </div>
        <% end %>
      </details>
    </div>
  <% end %>
  <div class="col-12">
    <% if @featured_articles.present? %>
      <h2>Manually Featured Articles</h2>
      <% @featured_articles.each do |article| %>
        <%= render "individual_article", article: article %>
      <% end %>
    <% end %>
  </div>
  <div class="col-12">
    <%= paginate @articles %>

    <% @articles.each do |article| %>
      <%= render "individual_article", article: article %>
    <% end %>

    <%= paginate @articles %>
  </div>
</div>

<%= render "image_upload_script" %>
