<ion-header>
    <ion-toolbar>
        <ion-buttons slot="start">
            <ion-back-button [text]="'core.back' | translate"></ion-back-button>
        </ion-buttons>
        <ion-title>
            <h1>{{ user?.fullname }}</h1>
        </ion-title>
    </ion-toolbar>
</ion-header>
<ion-content [core-swipe-navigation]="users" class="limited-width">
    <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 ion-text-wrap">
                <core-user-avatar [user]="user" [userId]="user.id" [linkProfile]="false" [checkOnline]="true">
                </core-user-avatar>
                <ion-label>
                    <h2>{{ user.fullname }}</h2>
                    <p *ngIf="user.address">
                        <ion-icon name="fas-location-dot" [attr.aria-hidden]="true"></ion-icon> {{ user.address }}
                    </p>
                    <p *ngIf="rolesFormatted">
                        <strong>{{ 'core.user.roles' | translate}}</strong>{{'core.labelsep' | translate}}
                        {{ rolesFormatted }}
                    </p>
                    <p *ngIf="user.lastaccess !== undefined">
                        <strong>{{ 'core.lastaccess' | translate }}: </strong>
                        <span *ngIf="user.lastaccess">{{ user.lastaccess | coreTimeAgo }}</span>
                        <ng-container *ngIf="!user.lastaccess">{{ 'core.never' | translate }}</ng-container>
                    </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 [attr.aria-label]="'core.loading' | translate"></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="fas-user" slot="start" aria-hidden="true"></ion-icon>
                <ion-label>
                    <p class="item-heading">{{ 'core.user.details' | translate }}</p>
                </ion-label>
            </ion-item>
            <ion-item class="ion-text-center core-loading-handlers" *ngIf="isLoadingHandlers">
                <ion-label>
                    <ion-spinner [attr.aria-label]="'core.loading' | translate"></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>
                    <p class="item-heading">{{ handler.title | translate }}</p>
                </ion-label>
                <ion-badge slot="end" *ngIf="handler.showBadge" [hidden]="handler.loading || !handler.badge" aria-hidden="true">
                    {{handler.badge}}
                </ion-badge>
                <span *ngIf="handler.showBadge && handler.badge && handler.badgeA11yText" class="sr-only">
                    {{ handler.badgeA11yText | translate: {$a : handler.badge } }}
                </span>
                <ion-spinner slot="end" *ngIf="handler.showBadge && handler.loading" [attr.aria-label]="'core.loading' | translate">
                </ion-spinner>
            </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" [attr.aria-label]="'core.loading' | translate"></ion-spinner>
                    </ion-button>
                </ion-label>
            </ion-item>
        </ion-list>
        <core-empty-box *ngIf="!user && !isDeleted && isEnrolled" icon="far-user" [message]=" 'core.user.detailsnotavailable' | translate">
        </core-empty-box>
        <core-empty-box *ngIf="isDeleted" icon="far-user" [message]="'core.userdeleted' | translate"></core-empty-box>
        <core-empty-box *ngIf="isSuspended" icon="far-user" [message]="'core.usersuspended' | translate"></core-empty-box>
        <core-empty-box *ngIf="!isEnrolled" icon="far-user" [message]="'core.notenrolledprofile' | translate"></core-empty-box>
    </core-loading>
</ion-content>
