<ion-header>
    <ion-toolbar>
        <ion-buttons slot="start">
            <ion-back-button [text]="'core.back' | translate"></ion-back-button>
        </ion-buttons>
        <ion-title>
            <h1>{{ 'core.user.profile' | translate }}</h1>
        </ion-title>
    </ion-toolbar>
</ion-header>
<ion-content 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">
            <ion-item class="ion-text-center core-user-profile-maininfo ion-text-wrap" lines="full">
                <core-user-avatar [user]="user" [userId]="user.id" [linkProfile]="false" [checkOnline]="!canChangeProfilePicture">
                    <ion-button class="edit-avatar" *ngIf="canChangeProfilePicture" (click)="changeProfilePicture()"
                        [attr.aria-label]="'core.user.newpicture' | translate" fill="clear">
                        <ion-icon slot="icon-only" name="fas-pen" aria-hidden="true"></ion-icon>
                    </ion-button>
                </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>
                </ion-label>
            </ion-item>

            <ion-item-group *ngIf="hasContact">
                <ion-item-divider>
                    <ion-label>
                        <p class="item-heading">{{ 'core.user.contact' | translate}}</p>
                    </ion-label>
                </ion-item-divider>
                <ion-item class="ion-text-wrap" *ngIf="user.email">
                    <ion-label>
                        <p class="item-heading">{{ 'core.user.email' | translate }}</p>
                        <p><a class="core-anchor" href="mailto:{{user.email}}" core-link auto-login="no" [showBrowserWarning]="false">
                                {{ user.email }}
                            </a></p>
                    </ion-label>
                </ion-item>
                <ion-item class="ion-text-wrap" *ngIf="user.phone1">
                    <ion-label>
                        <p class="item-heading">{{ 'core.user.phone1' | translate}}</p>
                        <p><a class="core-anchor" href="tel:{{user.phone1}}" core-link auto-login="no" [showBrowserWarning]="false">
                                {{ user.phone1 }}
                            </a></p>
                    </ion-label>
                </ion-item>
                <ion-item class="ion-text-wrap" *ngIf="user.phone2">
                    <ion-label>
                        <p class="item-heading">{{ 'core.user.phone2' | translate}}</p>
                        <p><a class="core-anchor" href="tel:{{user.phone2}}" core-link auto-login="no" [showBrowserWarning]="false">
                                {{ user.phone2 }}
                            </a></p>
                    </ion-label>
                </ion-item>
                <ion-item class="ion-text-wrap" *ngIf="formattedAddress">
                    <ion-label>
                        <p class="item-heading">{{ 'core.user.address' | translate}}</p>
                        <p><a class="core-anchor" [href]="encodedAddress" core-link auto-login="no" [showBrowserWarning]="false">
                                {{ formattedAddress }}
                            </a></p>
                    </ion-label>
                </ion-item>
                <ion-item class="ion-text-wrap" *ngIf="user.city && !formattedAddress">
                    <ion-label>
                        <p class="item-heading">{{ 'core.user.city' | translate}}</p>
                        <p>{{ user.city }}</p>
                    </ion-label>
                </ion-item>
                <ion-item class="ion-text-wrap" *ngIf="user.country && !formattedAddress">
                    <ion-label>
                        <p class="item-heading">{{ 'core.user.country' | translate}}</p>
                        <p>{{ user.country }}</p>
                    </ion-label>
                </ion-item>
                <ion-item class="ion-text-wrap" *ngIf="displayTimezone && user.timezone">
                    <ion-label>
                        <p class="item-heading">{{ 'core.timezone' | translate}}</p>
                        <p>{{ user.timezone }}</p>
                    </ion-label>
                </ion-item>
            </ion-item-group>
            <ion-item-group *ngIf="hasDetails">
                <ion-item-divider>
                    <ion-label>
                        <p class="item-heading">{{ 'core.userdetails' | translate}}</p>
                    </ion-label>
                </ion-item-divider>
                <ion-item class="ion-text-wrap" *ngIf="user.url">
                    <ion-label>
                        <p class="item-heading">{{ 'core.user.webpage' | translate}}</p>
                        <p><a class="core-anchor" href="{{user.url}}" core-link>
                                {{ user.url }}
                            </a></p>
                    </ion-label>
                </ion-item>
                <ion-item class="ion-text-wrap core-user-profile-interests" *ngIf="interests">
                    <ion-label>
                        <p class="item-heading">{{ 'core.user.interests' | translate}}</p>
                        <ion-badge *ngFor="let interest of interests" role="link" (click)="openInterest(interest)">
                            {{ interest }}
                        </ion-badge>
                    </ion-label>
                </ion-item>
                <core-user-profile-field *ngFor="let field of user.customfields" [field]="field" contextLevel="course"
                    [contextInstanceId]="courseId" [courseId]="courseId">
                </core-user-profile-field>
            </ion-item-group>
            <ion-item-group *ngIf="user.description">
                <ion-item-divider>
                    <ion-label>
                        <p class="item-heading">{{ 'core.user.description' | translate}}</p>
                    </ion-label>
                </ion-item-divider>
                <ion-item class="ion-text-wrap">
                    <ion-label>
                        <p>
                            <core-format-text [text]="user.description" contextLevel="user" [contextInstanceId]="user.id">
                            </core-format-text>
                        </p>
                    </ion-label>
                </ion-item>
            </ion-item-group>
        </ion-list>

        <core-empty-box *ngIf="!user || (!hasContact && !hasDetails && !user.description)" icon="fas-user"
            [message]=" 'core.user.detailsnotavailable' | translate">
        </core-empty-box>
    </core-loading>
</ion-content>
