<% title "Credits" %>

<div class="credits-container">
  <% if flash[:notice].present? %>
    <div class="notice" id="notice">
      <%= flash[:notice] %>
    </div>
  <% end %>

  <div class="existing-credits">
    <div class="existing-credits-status">You have <%= @user_unspent_credits_count %> personal credits to spend</div>
    <a href="<%= purchase_credits_path %>" data-no-instant>Purchase additional credits</a>

    <%= render "ledger", items: @ledger[["User", current_user.id]] %>
  </div>

  <% if @organizations.present? %>
    <% @organizations.find_each do |org| %>
      <div class="existing-credits">
        <div class="existing-credits-status">
          <%= org.name %> has <span id="org-credits-number"><%= org.unspent_credits_count %></span> credits to spend
        </div>
        <a id="org-credits-purchase-link" href="<%= purchase_credits_path(organization_id: org.id) %>" data-no-instant>
          Purchase additional credits
        </a>

        <%= render "ledger", items: @ledger[["Organization", org.id]] %>
      </div>
    <% end %>
  <% end %>

  <% if @user_unspent_credits_count.positive? %>
    <center>
      <p>
        <a href="<%= new_classified_listing_path %>">Create a Listing</a>
      </p>
      <p>
        <a href="/listings/dashboard">Go to Listings Dashboard</a>
      </p>

      <% if @organizations.present? %>
        <p>
          <a href="<%= partnerships_path %>">View Partnership Opportunities</a>
        </p>
      <% end %>
    </center>
  <% end %>
</div>
