<ion-header>
    <ion-navbar core-back-button>
        <ion-title><core-format-text [text]="title"></core-format-text></ion-title>
    </ion-navbar>
</ion-header>
<ion-content>
    <ion-refresher [enabled]="filesLoaded && (showPrivateFiles || showSiteFiles)" (ionRefresh)="refreshData($event)">
        <ion-refresher-content pullingText="{{ 'core.pulltorefresh' | translate }}"></ion-refresher-content>
    </ion-refresher>

    <core-loading [hideUntil]="filesLoaded" *ngIf="showPrivateFiles || showSiteFiles">
        <!-- Allow selecting the files to see: private or site. -->
        <div padding *ngIf="showPrivateFiles && showSiteFiles && !path">
            <ion-select [(ngModel)]="root" (ngModelChange)="rootChanged()" interface="popover" class="core-button-select">
                <ion-option value="my">{{ 'addon.files.privatefiles' | translate }}</ion-option>
                <ion-option value="site">{{ 'addon.files.sitefiles' | translate }}</ion-option>
            </ion-select>
        </div>

        <!-- Display info about space used and space left. -->
        <p class="core-info-card" *ngIf="userQuota && filesInfo && filesInfo.filecount > 0">{{ 'core.quotausage' | translate:{$a: {used: spaceUsed, total: userQuotaReadable} } }}</p>

        <!-- List of files. -->
        <ion-list *ngIf="files && files.length > 0">
            <ng-container *ngFor="let file of files">
                <a *ngIf="file.isdir" ion-item class="item-media" [navPush]="'AddonFilesListPage'" [navParams]="{path: file.link, title: file.filename}">
                    <img [src]="file.imgPath" alt="" role="presentation" item-start>
                    <p>{{file.filename}}</p>
                </a>
                <core-file *ngIf="!file.isdir" [file]="file" [component]="component" [componentId]="file.contextid"></core-file>
            </ng-container>
        </ion-list>

        <!-- Message telling there are no files. -->
        <core-empty-box *ngIf="!files || !files.length" icon="folder" [message]="'addon.files.emptyfilelist' | translate"></core-empty-box>
    </core-loading>

    <!-- Upload a private file. -->
    <ion-fab core-fab bottom end *ngIf="showUpload && root != 'site' && !path">
        <button ion-fab (click)="uploadFile()" [attr.aria-label]="'core.fileuploader.uploadafile' | translate">
            <ion-icon name="add"></ion-icon>
        </button>
    </ion-fab>
</ion-content>