<ion-header>
    <ion-toolbar>
        <ion-buttons slot="start">
            <ion-back-button [text]="'core.back' | translate"></ion-back-button>
        </ion-buttons>
        <ion-title *ngIf="title">{{ title }}</ion-title>
    </ion-toolbar>
</ion-header>
<ion-content>
    <ion-refresher slot="fixed" [disabled]="!userLoaded" (ionRefresh)="refreshUser($event.target)">
        <ion-refresher-content pullingText="{{ 'core.pulltorefresh' | translate }}"></ion-refresher-content>
    </ion-refresher>
    <core-loading [hideUntil]="userLoaded">
        <ion-list *ngIf="user && !isDeleted && isEnrolled">
            <ion-item class="ion-text-center core-user-profile-maininfo">
                <core-user-avatar [user]="user" [userId]="user.id" [linkProfile]="false" [checkOnline]="true">
                    <div class="core-icon-foreground" *ngIf="canChangeProfilePicture">
                        <ion-icon name="fa-pen" (click)="changeProfilePicture()"
                            [attr.aria-label]="'core.user.newpicture' | translate">
                        </ion-icon>
                    </div>
                </core-user-avatar>
                <ion-label>
                    <h2>{{ user.fullname }}</h2>
                    <p *ngIf="user.address">{{ user.address }}</p>
                    <p *ngIf="rolesFormatted" class="ion-text-wrap">
                        <strong>{{ 'core.user.roles' | translate}}</strong>{{'core.labelsep' | translate}}
                        {{ rolesFormatted }}
                    </p>
                </ion-label>
            </ion-item>

            <div class="core-user-communication-handlers"
                *ngIf="(communicationHandlers && communicationHandlers.length) || isLoadingHandlers">
                <ion-item *ngIf="communicationHandlers && communicationHandlers.length">
                    <ion-label>
                        <ion-button *ngFor="let handler of communicationHandlers" expand="block" size="default"
                            [ngClass]="['core-user-profile-handler', handler.class || '']" (click)="handlerClicked($event, handler)"
                            [hidden]="handler.hidden" [attr.aria-label]="handler.title | translate" [disabled]="handler.spinner">
                            <ion-icon *ngIf="handler.icon" [name]="handler.icon" slot="start" aria-hidden="true"></ion-icon>
                            {{ handler.title | translate }}
                        </ion-button>
                    </ion-label>
                </ion-item>
                <div *ngIf="isLoadingHandlers" class="ion-text-center core-loading-handlers">
                    <ion-spinner></ion-spinner>
                </div>
            </div>


            <ion-item button class="ion-text-wrap core-user-profile-handler" (click)="openUserDetails()"
                [attr.aria-label]="'core.user.details' | translate" detail="true">
                <ion-icon name="fa-user" slot="start" aria-hidden="true"></ion-icon>
                <ion-label>
                    <h2>{{ 'core.user.details' | translate }}</h2>
                </ion-label>
            </ion-item>
            <ion-item class="ion-text-center core-loading-handlers" *ngIf="isLoadingHandlers">
                <ion-label><ion-spinner></ion-spinner></ion-label>
            </ion-item>

            <ion-item button *ngFor="let handler of newPageHandlers" class="ion-text-wrap" (click)="handlerClicked($event, handler)"
                [ngClass]="['core-user-profile-handler', handler.class || '']" [hidden]="handler.hidden"
                [attr.aria-label]="handler.title | translate" detail="true">
                <ion-icon *ngIf="handler.icon" [name]="handler.icon" slot="start" aria-hidden="true"></ion-icon>
                <ion-label>
                    <h2>{{ handler.title | translate }}</h2>
                </ion-label>
            </ion-item>

            <ion-item *ngIf="actionHandlers && actionHandlers.length">
                <ion-label>
                    <ion-button *ngFor="let handler of actionHandlers" expand="block" fill="outline" size="default"
                        [ngClass]="['core-user-profile-handler', handler.class || '']" (click)="handlerClicked($event, handler)"
                        [hidden]="handler.hidden" [attr.aria-label]="handler.title | translate" [disabled]="handler.spinner">
                        <ion-icon *ngIf="handler.icon" [name]="handler.icon" slot="start" aria-hidden="true"></ion-icon>
                        {{ handler.title | translate }}
                        <ion-spinner *ngIf="handler.spinner" slot="end"></ion-spinner>
                    </ion-button>
                </ion-label>
            </ion-item>
        </ion-list>

        <core-empty-box *ngIf="!user && !isDeleted && isEnrolled" icon="fa-user"
            [message]=" 'core.user.detailsnotavailable' | translate">
        </core-empty-box>
        <core-empty-box *ngIf="isDeleted" icon="fa-user" [message]="'core.userdeleted' | translate"></core-empty-box>
        <core-empty-box *ngIf="!isEnrolled" icon="fa-user" [message]="'core.notenrolledprofile' | translate"></core-empty-box>
    </core-loading>
</ion-content>
