<p class="well-sm" ng-bind-html="document.description"></p>
<dl class="dl-horizontal">
  <dt ng-if="document.subject">{{ 'document.subject' | translate }}</dt>
  <dd ng-if="document.subject">{{ document.subject }}</dd>
  <dt ng-if="document.identifier">{{ 'document.identifier' | translate }}</dt>
  <dd ng-if="document.identifier">{{ document.identifier }}</dd>
  <dt ng-if="document.publisher">{{ 'document.publisher' | translate }}</dt>
  <dd ng-if="document.publisher">{{ document.publisher }}</dd>
  <dt ng-if="document.format">{{ 'document.format' | translate }}</dt>
  <dd ng-if="document.format">{{ document.format }}</dd>
  <dt ng-if="document.source">{{ 'document.source' | translate }}</dt>
  <dd ng-if="document.source">{{ document.source }}</dd>
  <dt ng-if="document.type">{{ 'document.type' | translate }}</dt>
  <dd ng-if="document.type">{{ document.type }}</dd>
  <dt ng-if="document.coverage">{{ 'document.coverage' | translate }}</dt>
  <dd ng-if="document.coverage">{{ document.coverage }}</dd>
  <dt ng-if="document.rights">{{ 'document.rights' | translate }}</dt>
  <dd ng-if="document.rights">{{ document.rights }}</dd>
  <dt>{{ 'document.contributors' | translate }}</dt>
  <dd>
    <span ng-repeat="contributor in document.contributors">
      <a class="btn btn-xs" href="#/user/{{ contributor.username }}">
        <span class="fas fa-user"></span>
        {{ contributor.username }}
      </a>
    </span>
  </dd>
  <dt ng-if="document.relations.length > 0">{{ 'document.relations' | translate }}</dt>
  <dd ng-if="document.relations.length > 0">
    <span ng-repeat="relation in document.relations">
      <span class="btn btn-link btn-xs">
        <a href="#/document/view/{{ relation.id }}">
          {{ relation.title }}
        </a>
      </span>
    </span>
  </dd>

  <dt ng-if="false" ng-repeat-start="meta in document.metadata"></dt>
  <dt ng-if="meta.value != null">{{ meta.name }}</dt>
  <dd ng-if="meta.value != null && (meta.type == 'STRING' || meta.type == 'INTEGER' || meta.type == 'FLOAT')">{{ meta.value }}</dd>
  <dd ng-if="meta.value != null && meta.type == 'DATE'">{{ meta.value | date: dateFormat }}</dd>
  <dd ng-if="meta.value != null && meta.type == 'BOOLEAN'">{{ meta.value ? 'yes' : 'no' | translate }}</dd>
  <dd ng-if="false" ng-repeat-end></dd>
</dl>

<!-- Display mode (list or grid) -->
<div class="btn-group mt-10 mb-10 pull-right">
          <span class="btn btn-default" ng-class="{ active: displayMode == 'list' }"
                uib-tooltip="{{ 'document.view.content.display_mode_list' | translate }}"
                tooltip-append-to-body="true"
                ng-click="displayMode = 'list'">
            <span class="fas fa-list"></span>
          </span>
  <span class="btn btn-default" ng-class="{ active: displayMode == 'grid' }"
        uib-tooltip="{{ 'document.view.content.display_mode_grid' | translate }}"
        tooltip-append-to-body="true"
        ng-click="displayMode = 'grid'">
            <span class="fas fa-th"></span>
          </span>
</div>

<div class="clearfix"></div>

<!-- List of files -->
<div class="row upload-zone"
     ngf-drop="fileDropped($files)"
     ngf-drag-over-class="'bg-success'"
     ngf-multiple="true"
     ngf-allow-dir="false">
  <!-- Grid view -->
  <div ng-show="displayMode == 'grid'" ui-sortable="fileSortableOptions" ng-model="files">
    <div class="col-xs-6 col-sm-4 col-md-4 col-lg-3 text-center" ng-repeat="file in files">
      <div class="thumbnail" ng-if="file.id">
        <div class="file-processing-indicator" ng-show="file.processing"
             uib-tooltip="{{ 'document.view.content.file_processing_indicator' | translate }}">
          <span class="fas fa-spin fa-circle-notch"></span>
        </div>

        <a class="file-thumbnail" ng-click="openFile(file, $event)">
          <img ng-src="../api/file/{{ file.id }}/data?size=thumb" uib-tooltip="{{ file.mimetype }} | {{ file.size | filesize }}" tooltip-placement="top" />
        </a>

        <div class="file-info">
          <div></div><!-- Actually useful -->
          <div class="v-align file-name" ng-if="file.name" title="{{ file.name }} (v{{ file.version + 1 }}.0)">{{ file.name }}</div>
          <div class="v-align" ng-show="document.writable">
            <div uib-dropdown>
              <button class="btn btn-default" uib-dropdown-toggle>
                <span class="fas fa-ellipsis-v"></span>
              </button>
              <ul class="dropdown-menu" uib-dropdown-menu>
                <li>
                  <a ng-href="../api/file/{{ file.id }}/data" target="_blank">
                    <span class="fas fa-download"></span>
                    {{ 'download' | translate }}
                  </a>
                </li>
                <li role="separator" class="divider"></li>
                <li>
                  <a href ng-click="renameFile(file)">
                    <span class="fas fa-pencil-alt"></span>
                    {{ 'rename' | translate }}
                  </a>
                </li>
                <li>
                  <a href ng-click="processFile(file)">
                    <span class="fas fa-eye"></span>
                    {{ 'document.view.content.reprocess_file' | translate }}
                  </a>
                </li>
                <li role="separator" class="divider"></li>
                <li>
                  <a href ngf-select
                     ngf-change="uploadNewVersion($files, file)"
                     ngf-multiple="false">
                    <span class="fas fa-plus"></span>
                    {{ 'document.view.content.upload_new_version' | translate }}
                  </a>
                </li>
                <li>
                  <a href ng-click="openVersions(file)">
                    <span class="fas fa-angle-double-left"></span>
                    {{ 'document.view.content.open_versions' | translate }}
                  </a>
                </li>
                <li role="separator" class="divider"></li>
                <li>
                  <a href ng-click="deleteFile(file)">
                    <span class="fas fa-trash text-danger"></span>
                    {{ 'delete' | translate }}
                  </a>
                </li>
              </ul>
            </div>
          </div>
        </div>
      </div>

      <div class="thumbnail" ng-if="!file.id">
        <p class="text-center lead">
          {{ file.status }}
        </p>
        <div class="caption">
          <uib-progressbar value="file.progress" class="progress-info active"></uib-progressbar>
        </div>
      </div>
    </div>
  </div>

  <!-- List view -->
  <table ng-show="displayMode == 'list'" class="table table-hover table-files">
    <thead>
    <tr>
      <th width="3%"></th>
      <th>Filename</th>
      <th>Type</th>
      <th>Size</th>
      <th width="10%">Version</th>
      <th></th>
    </tr>
    </thead>
    <tbody ui-sortable="fileSortableOptions" ng-model="files">
    <tr ng-repeat="file in files" ng-class="{ 'active': openedFile.id == file.id }">
      <td class="pointer" ng-click="openFile(file, $event)">
        <div class="thumbnail-list">
          <img ng-src="../api/file/{{ file.id }}/data?size=thumb" />
        </div>
      </td>
      <td class="pointer" ng-click="openFile(file, $event)">
        {{ file.name }}
        <span class="fas fa-spin fa-circle-notch"
              ng-show="file.processing"
              uib-tooltip="{{ 'document.view.content.file_processing_indicator' | translate }}"></span>
      </td>
      <td>{{ file.mimetype }}</td>
      <td>{{ file.size | filesize }}</td>
      <td>v{{ file.version + 1 }}.0</td>
      <td ng-show="document.writable">
        <div uib-dropdown>
          <button class="btn btn-default" uib-dropdown-toggle>
            <span class="fas fa-ellipsis-v"></span>
          </button>
          <ul class="dropdown-menu" uib-dropdown-menu>
            <li>
              <a ng-href="../api/file/{{ file.id }}/data" target="_blank">
                <span class="fas fa-download"></span>
                {{ 'download' | translate }}
              </a>
            </li>
            <li role="separator" class="divider"></li>
            <li>
              <a href ng-click="renameFile(file)">
                <span class="fas fa-pencil-alt"></span>
                {{ 'rename' | translate }}
              </a>
            </li>
            <li>
              <a href ng-click="processFile(file)">
                <span class="fas fa-eye"></span>
                {{ 'document.view.content.reprocess_file' | translate }}
              </a>
            </li>
            <li role="separator" class="divider"></li>
            <li>
              <a href ngf-select
                 ngf-change="uploadNewVersion($files, file)"
                 ngf-multiple="false">
                <span class="fas fa-plus"></span>
                {{ 'document.view.content.upload_new_version' | translate }}
              </a>
            </li>
            <li>
              <a href ng-click="openVersions(file)">
                <span class="fas fa-angle-double-left"></span>
                {{ 'document.view.content.open_versions' | translate }}
              </a>
            </li>
            <li role="separator" class="divider"></li>
            <li>
              <a href ng-click="deleteFile(file)">
                <span class="fas fa-trash text-danger"></span>
                {{ 'delete' | translate }}
              </a>
            </li>
          </ul>
        </div>
      </td>
    </tr>
    </tbody>
  </table>

  <p class="text-center well-lg" ng-if="files.length == 0">
    <span class="fas fa-arrows-alt"></span>
    {{ 'document.view.content.drop_zone' | translate }}
  </p>
</div>

<p class="text-center">
  <button class="btn btn-primary" ngf-select
    ngf-change="fileDropped($files, $event)"
    input-file-multiple="multiple"
    ngf-multiple="true">
    {{ 'document.view.content.add_files' | translate }}
  </button>
</p>

<div ui-view="file"></div>