<div id="filePreviewModal"
     class="modal modal-file-preview"
     role="dialog"
     tabindex="-1"
     aria-labelledby="filePreviewModal"
     data-backdrop="static"
     data-object-id="<%= asset.id %>">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <span class="file-name"><%= asset.file.metadata[:name] || asset.file_name %></span>
        <div class="sci-btn-group">
          <%= link_to shared_asset_download_path(@shareable_link.uuid, asset), class: 'btn btn-light file-download-link', data: { turbolinks: false } do %>
            <span class="sn-icon sn-icon-export"></span>
            <%= t('Download') %>
          <% end %>
          <button type="button" class="btn icon-btn btn-light" data-dismiss="modal"><span class="sn-icon sn-icon-close"></span></button>
        </div>
      </div>
      <div class="modal-body">
        <div class="file-preview-container">
          <% if asset.pdf_previewable? %>
            <%= render partial: 'shared/pdf_viewer', locals: { asset: asset, report_document: false, shareable_document: true } %>
          <% elsif asset.previewable? && asset.large_preview&.image&.attached? %>
            <%= image_tag asset.large_preview.url(expires_in: Constants::URL_SHORT_EXPIRE_TIME.minutes),
                class: 'asset-image',
                style: 'opacity: 1' %>
          <% else %>
            <%= render partial: 'shared/file_preview/file_icon', locals: { asset: asset } %>
          <% end %>
        </div>
      </div>
      <div class="modal-footer">
        <div class="gallery">
          <% previous_asset = Asset.find_by(id: gallery.split(asset.id)[0]&.last) %>
          <% next_asset = Asset.find_by(id: gallery.split(asset.id)[1]&.first) %>
          <% if previous_asset %>
            <%= link_to '#',
              class: "previous-asset shareable-gallery-switcher",
              data: { id: previous_asset.id } do %>
              <i class="sn-icon sn-icon-arrow-left"></i>
              <% if previous_asset.previewable? && previous_asset.medium_preview&.image&.attached? %>
                <%= image_tag previous_asset.medium_preview.url(expires_in: Constants::URL_SHORT_EXPIRE_TIME.minutes),
                    class: 'asset-image',
                    style: 'opacity: 1' %>
              <% else %>
                <i class="fas <%= file_fa_icon_class(previous_asset) if previous_asset.file_name %>"></i>
              <% end %>
              <span class="file-name"><%= previous_asset.file_name %></span>
            <% end %>
          <% end %>
          <span class="file-counter">
            <%= gallery.split(asset.id)[0].length + 1 %> of <%= gallery.length %> attachments
          </span>
          <% if next_asset %>
            <%= link_to '#',
              class: "next-asset shareable-gallery-switcher",
              data: { id: next_asset.id } do %>
              <% if next_asset.previewable? && next_asset.medium_preview&.image&.attached? %>
                <%= image_tag next_asset.medium_preview.url(expires_in: Constants::URL_SHORT_EXPIRE_TIME.minutes),
                    class: 'asset-image',
                    style: 'opacity: 1' %>
              <% else %>
                <i class="fas <%= file_fa_icon_class(next_asset) if next_asset.file_name %>"></i>
              <% end %>
              <span class="file-name"><%= next_asset.file_name %></span>
              <i class="sn-icon sn-icon-arrow-right"></i>
            <% end %>
          <% end %>
        </div>
      </div>
    </div>
  </div>
</div>
