<%
# BigBlueButton open source conferencing system - http://www.bigbluebutton.org/.
# Copyright (c) 2018 BigBlueButton Inc. and by respective authors (see below).
# This program is free software; you can redistribute it and/or modify it under the
# terms of the GNU Lesser General Public License as published by the Free Software
# Foundation; either version 3.0 of the License, or (at your option) any later
# version.
#
# BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
# You should have received a copy of the GNU Lesser General Public License along
# with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
%>

<div class="sessions pb-5">
  <div class="container pt-6">

    <%= render "shared/components/subtitle", subtitle: (only_public ? t("recording.visibility.public") + " " : "") + title, search: true %>
    <div class="row">
      <div class="col-12">
        <div class="card">
          <div class="table-responsive">
            <table id="recordings-table" class="table table-hover table-outline table-vcenter text-nowrap card-table">
              <thead>
                <tr>
                  <th data-header="name" data-order="<%= @order_column == "name" ? @order_direction : "none" %>">
                    <%= t("recording.table.name") %>
                    <% if @order_column == "name" && @order_direction == "desc" %>
                      ↓
                    <% elsif @order_column == "name" && @order_direction == "asc" %>
                      ↑
                    <% end %>
                  </th>
                  <% if recording_thumbnails? %>
                    <th>
                      <%= t("recording.table.thumbnails") %>
                    </th>
                  <% end %>
                  <th class="text-left" data-header="length" data-order="<%= @order_column == "length" ? @order_direction : "none" %>">
                    <%= t("recording.table.length") %>
                    <% if @order_column == "length" && @order_direction == "desc" %>
                      ↓
                    <% elsif @order_column == "length" && @order_direction == "asc" %>
                      ↑
                    <% end %>
                  </th>
                  <th class="text-left" data-header="users" data-order="<%= @order_column == "users" ? @order_direction : "none" %>">
                    <%= t("recording.table.users") %>
                    <% if @order_column == "users" && @order_direction == "desc" %>
                      ↓
                    <% elsif @order_column == "users" && @order_direction == "asc" %>
                      ↑
                    <% end %>
                  </th>
                  <th class="text-left" data-header="visibility" data-order="<%= @order_column == "visibility" ? @order_direction : "none" %>">
                    <%= t("recording.table.visibility") %>
                    <% if @order_column == "visibility" && @order_direction == "desc" %>
                      ↓
                    <% elsif @order_column == "visibility" && @order_direction == "asc" %>
                      ↑
                    <% end %>
                  </th>
                  <th data-header="formats" data-order="<%= @order_column == "formats" ? @order_direction : "none" %>">
                    <%= t("recording.table.formats") %>
                    <% if @order_column == "formats" && @order_direction == "desc" %>
                      ↓
                    <% elsif @order_column == "formats" && @order_direction == "asc" %>
                      ↑
                    <% end %>
                  </th>
                  <% unless only_public %>
                    <th class="text-center"><i class="icon-settings"></i></th>
                  <% end %>
                </tr>
              </thead>
              <tbody id="recording-table">
                <tr id="no_recordings_found" style="display: none;">
                  <td colspan="7" class="text-center h4 p-6 font-weight-normal" >
                    <%= t("recording.no_matched_recordings", inject: only_public ? t("recording.visibility.public").downcase + " "  : "") %>
                  </td>
                </tr>
                <% if recordings.empty? %>
                  <tr>
                    <td colspan="7" class="text-center h4 p-6 font-weight-normal">
                      <% if user_recordings %>
                        <%= t("recording.no_user_recordings") %>
                      <% else %>
                        <%= t("recording.no_recordings", inject: only_public ? t("recording.visibility.public").downcase + " "  : "") %>
                      <% end %>
                    </td>
                  </tr>
                <% else %>
                  <% failed_recordings = 0 %>
                  <% recordings.each do |recording| %>
                    <% begin %>
                      <% if only_public || (defined?(shared_room) && shared_room) %>
                        <%= render "shared/components/public_recording_row", recording: recording %>
                      <% else %>
                        <%= render "shared/components/recording_row", recording: recording %>
                      <% end %>
                    <% rescue => e %>
                      <% logger.error "Error retrieving recording #{recording[:meetingID]}: #{e} -> #{e.backtrace[0]}" %>
                      <% failed_recordings += 1 %>
                    <% end %>
                  <% end %>

                  <% if failed_recordings > 0 %>
                    <div class="alert alert-danger alert-dismissible text-center mb-0">
                      <%= t("recording.error", count: failed_recordings) %>
                    </div>
                  <% end %>
                <% end %>
              </tbody>
            </table>
            <% if !recordings.empty?%>
              <div class="float-right mr-4 mt-4">
                <%== pagy_bootstrap_nav(pagy) %>
              </div>
            <% end %>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>
