<% document ||= @document %>
<% if document_downloadable? %>
  <div class='panel-body'>
    <div class='btn-group' itemprop='distribution' itemscope='itemscope' itemtype='http://schema.org/DataDownload'>
      <% if document.direct_download.present? %>
      <%= link_to(download_text(@document[:dc_format_s]), document.direct_download[:download], class: 'btn btn-default', 'contentUrl' => document.direct_download[:download], data: { download: 'trigger', download_type: 'direct', download_id: document[:layer_slug_s] }) %>
      <% elsif document.hgl_download.present? %>
      <%= link_to(download_text(document.download_types.first[0]),
      download_hgl_path(id: document), data: {ajax_modal: 'trigger', download: 'trigger', download_type: 'harvard-hgl', download_id: document[:layer_slug_s] },
      class: 'btn btn-default') %>
      <% else %>
      <%= link_to(download_text(document.download_types.first[0]), '', data: { download_path: "#{download_path(document[:layer_slug_s], type: document.download_types.first[0])}", download: 'trigger', download_type: document.download_types.first[0], download_id: document[:layer_slug_s] }, class: 'btn btn-default') %>
      <% end %>
      <button type='button' class='btn btn-default dropdown-toggle download-dropdown-toggle' data-toggle='dropdown' aria-expanded='false'>
        <span class='caret'></span>
        <span class='sr-only'>Toggle Download Dropdown</span>
      </button>
      <ul class='dropdown-menu' role='menu'>
        <% if document.hgl_download.present? %>
        <li role="presentation" class="dropdown-header">Original</li>
        <li>
          <%= link_to(download_text(document.download_types.first[0]),
          download_hgl_path(id: document), data: {ajax_modal: 'trigger', download: 'trigger', download_type: 'harvard-hgl', download_id: document[:layer_slug_s] }) %>
        </li>
        <% else %>
        <% if document.direct_download.present? %>
        <li role="presentation" class="dropdown-header">Original</li>
        <li>
          <%= link_to(download_text(@document[:dc_format_s]), document.direct_download[:download], 'contentUrl' => document.direct_download[:download], data: { download: 'trigger', download_type: 'direct', download_id: document[:layer_slug_s] }) %>
        </li>
        <% end %>
        <% if document.download_types.present? %>
        <li role="presentation" class="dropdown-header">Generated</li>
        <% document.download_types.each do |type| %>
        <%= content_tag(:li) do %>
        <% link_to(download_text(type[0]), '', data: { download_path: "#{download_path(document[:layer_slug_s], type: type[0])}", download: 'trigger', download_type: type[0], download_id: document[:layer_slug_s] }) %>
        <% end %>
        <% end %>
        <% end %>
        <% end %>
      </ul>
    </div>
  </div>
  <% elsif document.restricted? && document.same_institution? %>
    <div class='panel-body'>
      <%= link_to t('geoblacklight.tools.login_to_view'), new_user_session_path(referrer: request.original_url) %>
    </div>
<% end %>