<div class="datatable">
  <rd-widget>
    <rd-widget-body classes="no-padding">
      <div class="toolBar">
        <div class="toolBarTitle vertical-center">
          <div class="widget-icon space-right">
            <pr-icon icon="$ctrl.titleIcon" feather="true"></pr-icon>
          </div>
          {{ $ctrl.titleText }}
        </div>
        <div class="searchBar vertical-center">
          <pr-icon icon="'search'" feather="true" class-name="'searchIcon'"></pr-icon>
          <input
            type="text"
            class="searchInput"
            ng-model="$ctrl.state.textFilter"
            ng-model-options="{ debounce: 300 }"
            ng-change="$ctrl.onTextFilterChange()"
            placeholder="Search..."
            auto-focus
          />
        </div>
        <file-uploader authorization="DockerAgentBrowsePut" ng-if="$ctrl.isUploadAllowed" on-file-selected="($ctrl.onFileSelectedForUpload)"> </file-uploader>
      </div>
      <div class="table-responsive">
        <table class="table">
          <thead>
            <tr>
              <th>
                <table-column-header
                  col-title="'Name'"
                  can-sort="true"
                  is-sorted="$ctrl.state.orderBy === 'Name'"
                  is-sorted-desc="$ctrl.state.orderBy === 'Name' && $ctrl.state.reverseOrder"
                  ng-click="$ctrl.changeOrderBy('Name')"
                ></table-column-header>
              </th>
              <th>
                <table-column-header
                  col-title="'Size'"
                  can-sort="true"
                  is-sorted="$ctrl.state.orderBy === 'Size'"
                  is-sorted-desc="$ctrl.state.orderBy === 'Size' && $ctrl.state.reverseOrder"
                  ng-click="$ctrl.changeOrderBy('Size')"
                ></table-column-header>
              </th>
              <th>
                <table-column-header
                  col-title="'Last modification'"
                  can-sort="true"
                  is-sorted="$ctrl.state.orderBy === 'ModTime'"
                  is-sorted-desc="$ctrl.state.orderBy === 'ModTime' && $ctrl.state.reverseOrder"
                  ng-click="$ctrl.changeOrderBy('ModTime')"
                ></table-column-header>
              </th>
              <th> Actions </th>
            </tr>
          </thead>
          <tbody>
            <tr ng-if="!$ctrl.isRoot">
              <td colspan="4">
                <a ng-click="$ctrl.goToParent()"><pr-icon icon="'corner-left-up'" feather="true"></pr-icon>Go to parent</a>
              </td>
            </tr>
            <tr ng-repeat="item in ($ctrl.state.filteredDataSet = ($ctrl.dataset | filter:$ctrl.state.textFilter | orderBy:$ctrl.state.orderBy:$ctrl.state.reverseOrder))">
              <td>
                <span ng-if="item.edit" class="vertical-center">
                  <input
                    class="input-sm"
                    type="text"
                    ng-model="item.newName"
                    on-enter-key="$ctrl.rename({ name: item.Name, newName: item.newName }); item.edit = false"
                    auto-focus
                  />
                  <a class="interactive" ng-click="item.edit = false;"><pr-icon icon="'x'" feather="true"></pr-icon></a>
                  <a class="interactive" ng-click="$ctrl.rename({name: item.Name, newName: item.newName}); item.edit = false;"><pr-icon icon="'check'" feather="true"></pr-icon></a>
                </span>
                <span ng-if="!item.edit && item.Dir">
                  <a ng-click="$ctrl.browse({name: item.Name})" class="vertical-center"><pr-icon icon="'folder'" feather="true"></pr-icon>{{ item.Name }}</a>
                </span>
                <span ng-if="!item.edit && !item.Dir" class="vertical-center"><pr-icon icon="'file'" feather="true"></pr-icon>{{ item.Name }}</span>
              </td>
              <td>{{ item.Size | humansize }}</td>
              <td>
                {{ item.ModTime | getisodatefromtimestamp }}
              </td>
              <td>
                <btn authorization="DockerAgentBrowseGet" class="btn btn-xs btn-secondary space-right" ng-click="$ctrl.download({ name: item.Name })" ng-if="!item.Dir">
                  <pr-icon icon="'download'" feather="true"></pr-icon> Download
                </btn>
                <btn authorization="DockerAgentBrowseRename" class="btn btn-xs btn-secondary space-right" ng-click="item.newName = item.Name; item.edit = true">
                  <pr-icon icon="'edit'" feather="true"></pr-icon> Rename
                </btn>
                <btn authorization="DockerAgentBrowseDelete" class="btn btn-xs btn-dangerlight" ng-click="$ctrl.delete({ name: item.Name })">
                  <pr-icon icon="'trash-2'" feather="true"></pr-icon> Delete
                </btn>
              </td>
            </tr>
            <tr ng-if="!$ctrl.dataset">
              <td colspan="5" class="text-center text-muted">Loading...</td>
            </tr>
            <tr ng-if="$ctrl.state.filteredDataSet.length === 0">
              <td colspan="5" class="text-center text-muted">No files found.</td>
            </tr>
          </tbody>
        </table>
      </div>
    </rd-widget-body>
  </rd-widget>
</div>
