<%= render HeaderComponent.new(title: "App Catalog") %>

<%= render MainWithSidenavComponent.new(sidenav_partial: 'shared/admin_sidenav_app_catalog') do %>
  <section>
    <%= render QuickstatsContainerComponent.new do %>
      <%= render QuickstatsItemComponent.new(
          type: :number,
          title: 'Known Web Apps',
          value: @stats[:known_apps],
      ) %>
      <%# <%= render QuickstatsItemComponent.new(
      <%#     type: :number,
      <%#     title: 'Accepted',
      <%#     value: @stats[:accepted],
      <%# ) %>
      <%# <%= render QuickstatsItemComponent.new(
      <%#     type: :number,
      <%#     title: 'Users with referrals',
      <%#     value: @stats[:users_with_referrals],
      <%#     meta: "/ #{User.count}"
      <%# ) %>
    <% end %>
  </section>
  <% if @web_apps.any? %>
    <section>
      <h3>Web Apps</h3>
      <table class="divided mb-8">
        <thead>
          <tr>
            <th>Name</th>
            <th>URL</th>
            <th class="hidden md:table-cell">RS Auths</th>
            <th class="hidden md:table-cell">Created at</th>
          </tr>
        </thead>
        <tbody>
          <% @web_apps.each do |web_app| %>
            <tr>
              <td><%= web_app.name %></td>
              <td><%= link_to web_app.url, web_app.url,
                              target: "_blank", rel: "nofollow noopener",
                              class: "ks-text-link" %></td>
              <td class="hidden md:table-cell"><%= web_app.remote_storage_authorizations.count %></td>
              <td class="hidden md:table-cell">
                <span title="<%= web_app.created_at %>" class="cursor-help">
                  <%= time_ago_in_words web_app.created_at, include_seconds: false %> ago
                </span>
              </td>
            </tr>
          <% end %>
        </tbody>
      </table>
      <%== pagy_nav @pagy %>
    </section>
  <% end %>
<% end %>
