<core-loading [hideUntil]="loaded" [fullscreen]="false">
    <ion-card>
        <ion-item class="ion-text-wrap">
            <ion-label>
                <p class="item-heading">{{ title }} <span [core-mark-required]="required" class="core-mark-required"></span></p>
                <span *ngIf="maxSubmissionsReadable">
                    {{ 'core.maxsizeandattachments' | translate:{$a: {size: maxSizeReadable, attachments: maxSubmissionsReadable} } }}
                </span>
                <span *ngIf="!maxSubmissionsReadable">{{ 'core.maxfilesize' | translate:{$a: maxSizeReadable} }}</span>
            </ion-label>
            <ion-button slot="end" (click)="add()" [ariaLabel]="'core.fileuploader.addfiletext' | translate"
                *ngIf="unlimitedFiles || (maxSubmissions !== undefined && maxSubmissions >= 0 && files && files.length < maxSubmissions)">
                <ion-icon name="fas-plus" slot="icon-only" aria-hidden="true" />
            </ion-button>
        </ion-item>

        @if (fileTypes && fileTypes.mimetypes && fileTypes.mimetypes.length) {
        <ion-accordion-group>
            <ion-accordion toggleIconSlot="start">
                <ion-item class="core-attachments-header ion-text-wrap" slot="header">
                    <ion-label>
                        <p class="item-heading">{{ 'core.fileuploader.filesofthesetypes' | translate }}</p>
                    </ion-label>
                    <ion-icon name="fas-circle-info" aria-hidden="true" slot="end" color="dark" />
                </ion-item>

                <ul class="core-attachments" slot="content">
                    <li *ngFor="let typeInfo of fileTypes.info">
                        <strong *ngIf="typeInfo.name">{{typeInfo.name}} </strong>{{typeInfo.extlist}}
                    </li>
                </ul>
            </ion-accordion>
        </ion-accordion-group>
        }



        <ng-container *ngFor="let file of files; let index=index">
            <!-- Files already attached to the submission, either in online or in offline. -->
            <core-file *ngIf="!file.name" [file]="file" [component]="component" [componentId]="componentId" [canDelete]="true"
                (onDelete)="delete(index, true)" [canDownload]="!file.offline" />

            <!-- Files added to draft but not attached to submission yet. -->
            <core-local-file *ngIf="file.name" [file]="file" [manage]="true" (onDelete)="delete(index, false)"
                (onRename)="renamed(index, $event)" />
        </ng-container>

        <ion-item class="ion-text-wrap" *ngIf="!files || !files.length">
            <ion-label>
                <p>{{ 'core.fileuploader.nofilesattached' | translate }}</p>
            </ion-label>
        </ion-item>
    </ion-card>
</core-loading>
