<section class="content">
  <div class="content-block">
    <div class="block-header">
      <div class="breadcrumb-main">
        <div class="row">
          <div class="col-6">
            <div class="mb-2">
              <span class="page-title">{{ "ALL_DOCUMENTS" | translate }}
                <app-page-help-text code="ALL_DOCUMENTS"></app-page-help-text>
              </span>
            </div>
          </div>
          <div class="col-6">
            <ul class="breadcrumb-list">
              <li class="breadcrumb-item bcrumb-1">
                <a *hasClaim="'ALL_DOCUMENTS_CREATE_DOCUMENT'" [routerLink]="['/documents/add']"
                  class="btn btn-outline-success btn-sm">
                  <i-feather name="Plus" class="btn-success"></i-feather>
                  <span class="d-none d-sm-inline"> {{'ADD_DOCUMENT' | translate}}</span>
                </a>
              </li>
            </ul>
          </div>
        </div>
      </div>
    </div>
    <div class="row">
      <div class="col-xl-12 col-lg-12 col-md-12 col-sm-12">
        <div class="card">
          <div class="body">
            <div class="row margin-2">
              <div class="col-md-3">
                <input class="form-control" placeholder="{{'SEARCH_DOCUMENT_BY_NAME_OR_DESCRIPTION' | translate}}"
                  type="text" #input>
              </div>
              <div class="col-md-3">
                <input class="form-control" placeholder="{{'SEARCH_DOCUMENT_BY_META_TAGS' | translate}}" #metatag>
              </div>
              <div class="col-md-2">
                <ng-select placeholder="{{'SELECT_CATEGORY' | translate}}" (change)="onCategoryChange($event)">
                  <ng-option *ngFor="let category of allCategories" [value]="category.id">
                    <div class="country-item"
                      [ngStyle]="this.direction === 'rtl'? {'margin-right.px': category.deafLevel* 20} : {'margin-left.px': category.deafLevel* 20}">
                      <div *ngIf="!category.parentId">
                        <b> {{category.name}}</b>
                      </div>
                      <div *ngIf="category.parentId">
                        {{category.name}}
                      </div>
                    </div>
                  </ng-option>
                </ng-select>
              </div>
              <div class="col-md-2">
                <ng-select (change)="onStorageChange($event)" placeholder="{{'STORAGE' | translate}}">
                  <ng-option [value]="'local'">{{'LOCAL' | translate}}</ng-option>
                  <ng-option [value]="'s3'">{{'S3' | translate}}</ng-option>
                </ng-select>
              </div>
              <div class="col-md-2">
                <input [max]="max" class="form-control" placeholder="{{'CREATED_DATE' | translate}}"
                  [formControl]="createdDate" [owlDateTimeTrigger]="date1" [owlDateTime]="date1">
                <owl-date-time #date1 [pickerType]="'calendar'"></owl-date-time>
              </div>
            </div>
            <div class="row">
              <div class="col">
                <div class="table-responsive">
                  <div class="grid-height-small">
                    <table mat-table [dataSource]="dataSource" class="w-100" matSort matSortActive="createdDate"
                      matSortDirection="desc" matSortDisableClear>
                      <ng-container matColumnDef="select">
                        <th class="table-column-fix-30" mat-header-cell *matHeaderCellDef>
                          <ng-container *ngIf="selection.isEmpty()">
                            <mat-checkbox (change)="$event ? masterToggle() : null" color="primary"
                              [checked]="selection.hasValue() && isAllSelected()"
                              [indeterminate]="selection.hasValue() && !isAllSelected()">
                            </mat-checkbox>
                          </ng-container>
                          <ng-container *ngIf="!selection.isEmpty()">
                            <button mat-mini-fab class="btn btn-primary btn-sm" matTooltipPosition="above"
                              (click)="onSharedSelectDocument()" *hasClaim="'ALL_DOCUMENTS_SHARE_DOCUMENT'">
                              <mat-icon>share</mat-icon>
                            </button>
                          </ng-container>
                        </th>
                        <td mat-cell *matCellDef="let row">
                          <mat-checkbox (click)="$event.stopPropagation()" color="primary"
                            (change)="$event ? selection.toggle(row) : null" [checked]="selection.isSelected(row)">
                          </mat-checkbox>
                        </td>
                      </ng-container>
                      <ng-container matColumnDef="action">
                        <th mat-header-cell *matHeaderCellDef>{{'ACTION' | translate}} </th>
                        <td mat-cell *matCellDef="let document">
                          <button mat-icon-button [matMenuTriggerFor]="menu" aria-label="Action">
                            <mat-icon>more_vert</mat-icon>
                          </button>
                          <mat-menu #menu="matMenu">
                            <button class="btn btn-light btn-sm" mat-menu-item (click)="onDocumentView(document)"
                              type="button">
                              <mat-icon>visibility</mat-icon>
                              {{'VIEW' | translate}}
                            </button>
                            <button *hasClaim="'ALL_DOCUMENTS_EDIT_DOCUMENT'" mat-menu-item class="btn btn-light btn-sm"
                              (click)="editDocument(document)">
                              <mat-icon>edit</mat-icon>
                              {{'EDIT' | translate}}
                            </button>
                            <button *hasClaim="'ALL_DOCUMENTS_SHARE_DOCUMENT'" mat-menu-item
                              class="btn btn-light btn-sm" (click)="manageDocumentPermission(document)" type="button">
                              <mat-icon>share</mat-icon>
                              {{'SHARE'| translate}}
                            </button>
                            <button *hasClaim="'ALL_DOCUMENTS_MANAGE_SHARABLE_LINK'" mat-menu-item
                              (click)="onCreateShareableLink(document)">
                              <mat-icon> link</mat-icon>
                              {{'GET_SHAREABLE_LINK' | translate}}
                            </button>
                            <button class="btn btn-light btn-sm" *hasClaim="'ALL_DOCUMENTS_DOWNLOAD_DOCUMENT'"
                              mat-menu-item (click)="downloadDocument(document)" type="button">
                              <mat-icon>download</mat-icon>
                              {{'DOWNLOAD' | translate}}
                            </button>
                            <button mat-menu-item class="btn btn-light btn-sm" (click)="uploadNewVersion(document)"
                              type="button">
                              <mat-icon>upload</mat-icon>
                              {{'UPLOAD_NEW_VERSION_FILE' | translate}}
                            </button>
                            <button mat-menu-item (click)="onVersionHistoryClick(document)">
                              <mat-icon> history</mat-icon>
                              {{'VERSION_HISTORY' | translate}}
                            </button>
                            <button class="btn btn-light btn-sm" mat-menu-item (click)="addComment(document)"
                              type="button">
                              <mat-icon> chat</mat-icon>
                              {{'COMMENT' | translate}}
                            </button>
                            <button class="btn btn-light btn-sm" mat-menu-item (click)="addReminder(document)"
                              type="button">
                              <mat-icon>notifications</mat-icon>
                              {{'ADD_REMINDER' | translate}}
                            </button>
                            <button class="btn btn-light btn-sm" mat-menu-item (click)="sendEmail(document)"
                              type="button">
                              <mat-icon>forward_to_inbox</mat-icon>
                              {{'SEND_EMAIL' | translate}}
                            </button>
                            <ng-container *ngIf="document.isIndexable && !document.isIndexed">
                              <button *hasClaim="'DEEP_SEARCH_ADD_INDEXING'" mat-menu-item class="btn btn-light btn-sm"
                                (click)="addIndexing(document)" type="button">
                                <mat-icon>find_in_page</mat-icon>
                                {{'ADD_INDEXING' | translate}}
                              </button>
                            </ng-container>
                            <ng-container *ngIf="document.isIndexable && document.isIndexed">
                              <button *hasClaim="'DEEP_SEARCH_REMOVE_INDEXING'" mat-menu-item
                                class="btn btn-light btn-sm" (click)="removeIndexing(document)" type="button">
                                <mat-icon>zoom_out</mat-icon>
                                {{'REMOVE_INDEXING' | translate}}
                              </button>
                            </ng-container>
                            <button *hasClaim="'ALL_DOCUMENTS_ARCHIVE_DOCUMENT'" mat-menu-item
                              class="btn btn-light btn-sm" (click)="archiveDocument(document)" type="button">
                              <mat-icon>archive</mat-icon>
                              {{'ARCHIVE' | translate}}
                            </button>
                            <button *hasClaim="'ALL_DOCUMENTS_DELETE_DOCUMENT'" mat-menu-item
                              class="btn btn-light btn-sm" (click)="deleteDocument(document)" type="button">
                              <mat-icon>delete</mat-icon>
                              {{'DELETE' | translate}}
                            </button>
                          </mat-menu>
                        </td>
                      </ng-container>
                      <ng-container matColumnDef="name">
                        <th mat-header-cell *matHeaderCellDef mat-sort-header> {{'NAME' | translate}} </th>
                        <td mat-cell *matCellDef="let document">
                          <a class="doc-link" (click)="onDocumentView(document)">{{document.name}}</a>
                        </td>
                      </ng-container>
                      <ng-container matColumnDef="categoryName">
                        <th mat-header-cell *matHeaderCellDef mat-sort-header>{{'DOCUMENT_CATEGORY' | translate}}</th>
                        <td mat-cell *matCellDef="let document"> {{document.categoryName}} </td>
                      </ng-container>
                      <ng-container matColumnDef="location">
                        <th mat-header-cell *matHeaderCellDef mat-sort-header>{{'STORAGE' | translate}}</th>
                        <td mat-cell *matCellDef="let document"> {{document.location.toUpperCase() | translate}} </td>
                      </ng-container>
                      <ng-container matColumnDef="createdDate">
                        <th mat-header-cell *matHeaderCellDef mat-sort-header> {{'CREATED_DATE' | translate}} </th>
                        <td mat-cell *matCellDef="let document"> {{document?.createdDate | utcToLocalTime:'shortDate' }}
                        </td>
                      </ng-container>
                      <ng-container matColumnDef="createdBy">
                        <th mat-header-cell *matHeaderCellDef mat-sort-header> {{'CREATED_BY' | translate}} </th>
                        <td mat-cell *matCellDef="let document"> {{document.createdByName}} </td>
                      </ng-container>
                      <ng-container matColumnDef="footer">
                        <td mat-footer-cell colspan="8" *matFooterCellDef>
                          <mat-paginator [length]="documentResource.totalCount" [pageSize]="documentResource.pageSize"
                            [pageSizeOptions]="[10, 20, 30]">
                          </mat-paginator>
                        </td>
                      </ng-container>
                      <tr *matNoDataRow>
                        <td colspan="8">
                          <div class="m-2">
                            <b> {{'NO_DATA_FOUND' | translate}}</b>
                          </div>
                        </td>
                      </tr>
                      <tr mat-header-row *matHeaderRowDef="displayedColumns;sticky: true"></tr>
                      <tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
                      <tr mat-footer-row *matFooterRowDef="footerToDisplayed;sticky: true"></tr>
                    </table>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</section>
<div class="loading-shade" *ngIf="dataSource.loading$ | async">
  <mat-spinner></mat-spinner>
</div>